On Tue, May 26, 2009 at 04:10:45PM -0700, yary wrote: > 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")
Correct, that's a typo. > > 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. In p6, one always uses the sigil to refer to the sub itself; the bare identifier form invokes it. > 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} This is really equivalent to sub odd_a(*...@_, *%_) { $_ % 2 } Every Routine gets its own $_ that isn't inherited from the outer lexical context (and is initialized to undef). Beyond that, what is really happening with say grep &odd_a, 0..6 is that grep is performing a smart-match of each value of 0..6 with &odd_a, and smart-matching a value to a Code object invokes the Code object with the value as an argument. Pm