On Tue, May 26, 2009 at 1:57 PM, Patrick R. Michaud <pmich...@pobox.com> wrote:
> On Mon, May 25, 2009 at 12:37:34PM -0700, yary wrote:
> How about...?
>
>    sub odd { ^$a % 2 }
typo. "sub odd {$^a % 2}" works (caret goes between "$" and "a")

>    say grep &odd, 0..6;
nice. I need to learn the differences between calling a sub as "odd"
vs "&odd" in p6. Haven't gotten that far in the synopses yet.

> This gets us to within one character of the p5 version.  I think
> we also have the possibility of
>
>    subset odd where { $_ % 2 }
>    say grep odd, 0..6;
>
> which is the same length as the p5 version, but afaict this
> last one doesn't seem to be working in Rakudo yet.

Nope, doesn't seem to.

I was wondering why the perl5 example didn't work in p6- $_ is a
contextual variable, so why doesn't the body of "odd" get its $_ value
from grep in something like this:
sub odd_a { $_ % 2}
sub odd_b { $*_ % 2}
sub odd_c { $CONTEXT::_ % 2 }

say grep &odd_a, 0..6
(calls "say" 7 times with an uninitialized value. Same with &odd_b, &odd_c)

Reply via email to