develooper Front page | perl.perl6.language | Postings from March 2009

.map/.reduce with larger arity

Thread Next
From:
Moritz Lenz
Date:
March 8, 2009 13:36
Subject:
.map/.reduce with larger arity
Message ID:
49B42C41.8050908@faui2k3.org
Currently the spec says:

 C<map> returns a lazily evaluated list which is comprised of
 the return value of the expression, evaluated once for every
 one of the C<@values> that are passed in.

But both pugs and rakudo respect the arity of the code ref passed to it,
so that (1..6).map({$^a + $^b + $^c}) returns the list (6, 15), which is
very nice and very DWIM'my.

But it opens the question what should happen if there is a number of
items in the list that's not easily divisible by the arity - should the
rest just be padded with undef's? or just ignored? Or fail() with a
friendly error message?

I don't really mind either way, just want to test and implement it
correctly.

The same question also arises for "magical" List.reduce and similar methods.

Cheers,
Moritz

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About