in reply to Re^3: "a bit of sugar "(HOP)
in thread "a bit of sugar "(HOP)

Yes, (&) is syntactic sugar, but that doesn't explain Iterator.

I see is as return Iterator {...} being semantic sugar for return sub {...}. It signals to the reader that the closure is an iterator.

Replies are listed 'Best First'.
Re^5: "a bit of sugar "(HOP)
by hbm (Hermit) on Mar 13, 2009 at 18:41 UTC

    Quoting HOP, [prototyping means that]:

    when we write this:
      Iterator { ... }
    Perl behaves as though we had written:
      Iterator(sub { ... })

    It allows the passing of a code reference to the Iterator subroutine, and is elsewhere compared to map { ... } @array and grep { ... } @array.

      That explains absolutely nothing. You don't need sub Iterator(&) to make sub {...} have the same form as map {...} and grep {...}. It already has that form.

      goto 750492;
      
        make sub {...} have the same form as map {...} and grep {...}.

        I didn't say that; I said that prototyping allows Iterator to behave like map { ... } and grep { ... }. And I agree, it also allows Iterator to behave like sub { ... }.

        Meanwhile, curious about the origination of "syntactic sugar", I found this quote:

        Syntactic sugar causes cancer of the semicolon;
        And a hundred other goodies at http://www.cs.yale.edu/quotes.html.