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

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.

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

    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.

        I didn't say that; I said that prototyping allows Iterator to behave like map { ... } and grep { ... }.

        Then you're assuming Iterator(sub {...}) is the starting point, and that's nonsense.

        sub { ... } is the starting point, and it's already syntactically similar to map { ... } and grep { ... }. To say that (&) is needed to create the iterator while using the BLOCK syntax of map and grep is untrue. (&) is therefore irrelevant to the question at hand.

        Using Iterator is the sugar. It conveys information to the user without any effect on the program. (&) is only the means to make it happen.