On Friday, January 17, 2003, at 09:57  AM, Mr. Nobody wrote:
And map/grep aren't "specialized syntax", you could do the same thing with a sub with a prototype of (&block, *@list).
The specialized part is that, in perl5, it's:

@out = grep { ... } map { ... } @in;
instead of:
@out = grep { ... }, map { ... }, @in;

...the absence of the commas is what's special. If they were normal functions/subroutines/methods/whatever, you would need a comma after the first argument, or we need a generic rule saying that a comma is optional after any closure.


The other, bigger issue is whether map, grep, etc. are methods of arrays/lists, or as special (universal) functions. Using a pipe-like syntax allows the following things to happen:

- C<map>, C<grep>, etc., all become methods, not universal functions. That means you can override them for subclasses of Arrays just like you would any other method, and you can make new methods that act like them and have the same syntax.

- If you want a customized C<map> or C<grep> method for a subclass of Array, you don't need to worry about _also_ overriding the universal C<map> and C<grep> functions to recognize each of your subclasses using multimethod variants.

- We don't need special comma-dropping rules for the grep and map syntax.

- You can use the same piping syntax for indirect-object-style calls on any methods:

$b = <~ fooify <~ mooify <~ gooify <~ $a;
same as:
$b = $a.gooify.mooify.fooify;


So short answer is, putting an operator in there like <~ and ~> is a more generic syntax, and especially works better if arrays and lists are objects. That's why it's being discussed.

MikeL



Reply via email to