in reply to Re^2: Weird syntax. What does this goto statement do? ( 'goto &NAME' use cases)
in thread Weird syntax. What does this goto statement do?

You said "coroutines", but I think you meant "tail call elimination"?

  • Comment on Re^3: Weird syntax. What does this goto statement do? ( 'goto &NAME' use cases)

Replies are listed 'Best First'.
Re^4: Weird syntax. What does this goto statement do? ( 'goto &NAME' use cases)
by LanX (Saint) on Jan 03, 2024 at 18:00 UTC
    I meant Co-routines, I saw someone demoing them in Perl many years ago in tinita's German Perl Board.

    Not very efficient tho.

    And my LISP skills are restricted to dabbling with emacs.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Implementing co-routines (co-operative multitasking) requires

      • The ability to create a context (call stack and execution pointer).
      • The ability to swap the active context with another.
      • The ability to free a context.

      (Example of a C co-routine implementation achieved using makecontext, swapcontext, getcontext and setcontext.)

      goto &foo does not help with any of that.

      On the other hand, it can be used to eliminate tail calls, and tail call elimination is something LISP does.

      The OP uses goto &sub for tail call elimination.

        I disagree, most probably your assumptions are based on some C lang specific conventions including call stack manipulations. (?)

        And I can't deal with your C code either, especially as it's far from short.

        But I looked into the WP page for Coroutines which has an abstract definition and boils it down to two simple criteria which can be very easily mapped to Perl.

        The first yield-to example with routines translates 1to1

        The next example showing a generator is a bit more complex, it requires to store the exit point in a closure-var as lable-name and to goto to that lable after rentry.

        This is essentially the semantic of gather-take in Perl6

        NB: I didn't say using goto &NAME and goto LABEL are efficient.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        Update

        The post I replied to was considerably extended while I wrote this