Re: 12 hackers hacking...
Not long ago, Mark J. Reed proclaimed... > What's the consensus on how to do an idiomatic countdown loop? I used > for [1..$n].reverse... This: will work eventually: for $n..1:by(-1) { ... } This currently works in rakudo: for (1..$n).reverse { ... }
Re: 12 hackers hacking...
On Thu, Dec 25, 2008 at 1:55 AM, Stephen Weeks wrote: > Not long ago, Mark J. Reed proclaimed... >> What's the consensus on how to do an idiomatic countdown loop? I used >> for [1..$n].reverse... > > This: will work eventually: >for $n..1:by(-1) { ... } Cool. > This currently works in rakudo: >for (1..$n).reverse { ... } No, it doesn't (r34384) for (1..10).reverse { say $^i } 01 9 8 7 6 5 4 3 2 1 The list is flattened into a string and then reversed by character; the body of the loop is executed only once. That's why I used the square brackets in my version. - Mark J. Reed
Re: 12 hackers hacking...
Not long ago, Mark J. Reed proclaimed... > On Thu, Dec 25, 2008 at 1:55 AM, Stephen Weeks wrote: > > This currently works in rakudo: > >for (1..$n).reverse { ... } > > No, it doesn't (r34384) > > for (1..10).reverse { say $^i } > 01 9 8 7 6 5 4 3 2 1 > > The list is flattened into a string and then reversed by character; > the body of the loop is executed only once. That's why I used the > square brackets in my version. Looks like you found a regression. This has been fixed since r34393. [swe...@kweh perl6]$ rakudo > for (1..10).reverse { .say } 10 9 8 7 6 5 4 3 2 1
pop'ping from an emty Array
Both pugs and rakudo agree on this one: 21:44 <@moritz_> perl6: my (@a, @b); @a.push(@b.pop); say @a.elems 21:44 < p6eval> ..pugs, rakudo 34399: OUTPUT«1» pop'ping from an empty array returns an undef, which is then pushed onto @a. Wouldn't it be nice of @empty_list.pop (or .unshift) would return a Nil instead, so that in list context this is the empty array, and the operation @a.push(@b.pop) would always preserve (@a.elems + @b.elems)? Cheers, Moritz (and a happy new year to all Perl 6 hackers, designers, fans and followers).