On Fri, Aug 15, 2008 at 11:15:46PM -0700, Carl Mäsak wrote: > r30258: > $ ./perl6 -e '.say for [1,2,3]' # as expected > 1 > 2 > 3
This one is actually incorrect in Rakudo -- at least according to Pugs (and I agree with Pugs here). The correct output is "1 2 3\n". Rakudo's output is likely incorrect for one or two reasons: (1) Rakudo doesn't yet properly parse statement modifiers after listops (RT #57352), and (2) I think that the C<for> statement modifier in Rakudo is not properly placing its argument into list context. Until #57352 is resolved, the better test (which Rakudo also fails at the moment, because of (2) above) is: $ ./perl6 -e '.say() for [1,2,3]' > $ ./perl6 -e 'for [1,2,3] { .say }' # shouldn't that be the same? > 1 2 3 This one is correct (both Rakudo and Pugs). > $ ./perl6 -e 'for [1,2,3] -> $a { say $a }' # or this? > 1 2 3 This one is also correct (Rakudo and Pugs). > $ ./perl6 -e 'for [1,2,3].list { .say }' # how do I make it... > 1 2 3 > $ ./perl6 -e 'for @([1,2,3]) { .say }' # ...loop over the elements? > 1 2 3 The reason that the output is "1 2 3\n" and not "1\n2\n3\n" is that an array in list context remains a (scalar) array. Thus the for loop is still iterating over a list of one element. To loop over the elements it ought to be for [1,2,3].values { .say } Rakudo currently has this wrong also -- I suspect that it's having trouble with the .values method on arrays. > All in all, it's difficult to actually loop on the contents of an > array at present. The semantics are not very consistent. I'm hoping > this is a bug. Yes, there are some bugs here -- several of the List methods (.values, .keys, etc.) need some refactoring in Rakudo since it's been decided that they're available for Any objects as well. Pm