On Mon, 9 Mar 2009, Larry Wall wrote:
> the only difference between C<for> and C<map> is that you can only use
> C<for> at the start of a statement. But we're more liberal about where
> statements are expected in Perl 6, so you can say things like:
>
> my @results = do for @list -> $x {...};
> my @results = (for @list -> $x {...});
>
> and either of those is equivalent to:
>
> my @results = map -> $x {...}, @list;
>
> I also Officially Don't Care if you use map in a void context. :)
(Good.)
<tongue-in-cheek> Maybe we should just treat "map" as a synonym for "for".
</tongue-in-cheek>
I'd like to be able to use grep, map, etc in a currying fashion. Can I do:
my &square_list := -> $x { $x * $x }.map();
And if so, what is the signature of &square_list ?
Maybe that's why there's a difference between "for" and "map"
@list = @array.map(&code);
&iterator = &code.for($signature);
@list = iterator(@list);
But I suspect they should logically be the other way around:
&iterator = &code.map($signature);
@list = iterator(@list);
@list = @array.for(&code);
-Martin