Dave Whipp wondered:
>> @sorted = sort {-M} @unsorted;
>
> One thing I've been trying to figure out reading this: what is the signature
> of prefix:-M ? i.e. how does it tell the outer block that it (the
> outer-block) needs a parameter?
It doesn't. As A6 explained:
http://dev.perl.org/perl6/apocalypse/A06.html#Bare_subs
any block that doesn't have placeholder-specified parameters but which refers
(even implicitly) to $_ will automatically have the signature of ($_).
That's why:
@odd = grep { $_ % 2 } @nums;
will still work in Perl 6.
Since a bare C<-M> implicitly refers to $_, the surrounding block
automagically gets a one-parameter signature and hence is (correctly!)
interpreted as a key extractor.
Don't you just love it when a plan^H^H^H^Hdesign comes together? ;-)
> There seems to be some transitive magic going on here.
There is. Kinda. Just not the type of magic you thought.
> Could similar magic be used to have infix:<=> require two
> higher-order variables (e.g. could "sort { <=> } @unsorted" be made to
> work?)
No. But this will work:
sort &infix:<=> @unsorted
Damian
Thread Previous
|
Thread Next