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

The syntactic sugar is in the fact that the & prototype allows you to write return Iterator {...} instead of return Iterator sub {...}

Replies are listed 'Best First'.
Re^4: "a bit of sugar "(HOP)
by ikegami (Patriarch) on Mar 13, 2009 at 18:33 UTC

    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.

      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;