Nominal type check failed for parameter '@a'; expected Positional but got GatherIterator instead
issue. Errr, sort of. Here's my sum sub:
sub sum(@a) {
+@a ?? @a.reduce({ $^a + $^b }) !! 0;
}
Now it does get called properly if you say
sum(@costs.grep({$_ >= 1000}))
. But even though it appears to be a very simple function, it doesn't work when called this way! The problem, as far as I can tell, is that @a
may look like a Seq or an Array, it's still actually an iterator. That means the first time you use it for something like, say, +@a
, it is completely consumed! Then the next time you access it, there's nothing left. This is definitely not what is expected...Update: Just realized that without "Perl 6", Ironman didn't pick up the previous post or this one. Time to edit...
No, that's not what's expected at all... :-/ Don't know the fix off hand; on the other hand, it's rather late in the...er...morning now. :-)
ReplyDelete/jnthn