On Mon, Mar 09, 2009 at 11:38:29AM -0500, Patrick R. Michaud wrote: : On Sun, Mar 08, 2009 at 09:31:19PM -0700, Larry Wall wrote: : > On Sun, Mar 08, 2009 at 09:36:17PM +0100, Moritz Lenz wrote: : > : 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 think the basic rule has to be simply can the signature bind to : > the remaining arguments. If not, we get a warning on unused arguments. : > We can mark arguments as optional if that's what we mean. : > [...] : > My gut feeling is that : > placeholder variables probably should not be considered optional; in : > most cases a non-divisible number of arguments indicates a logic error : > in the program, and an earlier message is better, even at the expense : > of thowing away some (possibly valid) partial data. Especially since : > we do have a way to indicate that partial data is acceptable: : > : > -> $a, $b?, $c? { $a + ($b//0) + ($c//0) } : : Presumably whatever we decide for C<map()> also applies to C<for>, yes? : : for 1..4 -> $a, $b, $c { ... } # error : for 1..4 -> $a, $b, $c? { ... } # error : for 1..4 -> $a, $b?, $c? { ... } # ok
Yes, 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. :) Larry