On Thu, 22 Jul 2004, JOSEPH RYAN wrote:
> When I think about your description of xxx, I
> summarized it in my head as "Call a coderef a certain
> number of times, and then collect the results."
> That's pretty much what map is, except that xxx is
> infix and map is prefix.
>
> @results = { ... } xxx 100;
> @results = map { ... } 1.. 100;
>
> Doesn't seem that special to me.
It isn't: the difference is not practical in nature but
aesthetical/phylosophical. Even if behind the scenes it may not be really
so, the latter conveys the idea of creating a list to actually ignore its
elements. So that while map() would be most always what one really wants,
there may be fewer cases in which an operator like the one suggested by
the OP would be the Right Tool(TM)...
Well, after all one thing that I've definitely understood about Perl6 is
that it will make easy to construct such custom operators on a per-user
basis. But IMHO at least some of them would fit in well as predefined
functions/operator or companions in crime of map() and grep() ;-)
Quite similarly, for example, I'd like to have a fold() function like the
one that is available in many functional programming languages, a la:
my $tot = fold 0, { + }, 1..10; # 55
my $fact = fold 1, { * }, 2..5; # 120
(i.e. please DO NOT point out that there other WTDI: it's obvious that
there are...)
Michele
--
SILVIO CLEPTOMANE
- Scritta su un muro,
Via F. Sforza, Milano