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

Iterator appears twice. The first where you found it. The second is 6 lines below, in a "return Iterator { ..... } line that is the actual code reference of the iterator. This is the confusing part...

It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Replies are listed 'Best First'.
Re^3: "a bit of sugar "(HOP)
by tilly (Archbishop) on Mar 13, 2009 at 18:22 UTC
    The syntactic sugar is in the fact that the & prototype allows you to write return Iterator {...} instead of return Iterator sub {...}

      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.

Re^3: "a bit of sugar "(HOP)
by JavaFan (Canon) on Mar 13, 2009 at 19:11 UTC
    The string Iterator indeed appears twice. But an appearance isn't a definition. There's only one definition of Iterator in the code - and that's outcommented.