In the summary of differences between Perl 5 and Perl 6, it is noted that the wantarray
function is gone:
wantarray() is gone
wantarray is gone. In Perl 6, context flows outwards, which means that a routine does not know which context it is in.
Instead you should return objects that do the right thing in every context.
Could someone provide an example of how such an object is created?
I think 2 examples might be:
http://perlcabal.org/syn/S13.html#Type_Casting
A class may define methods that allow it to respond as if it were a routine, array, or hash. The long forms are as follows:
method postcircumfix:<( )> ($capture) {...}
method postcircumfix:<[ ]> (**@slice) {...}
method postcircumfix:<{ }> (**@slice) {...}
Those are a bit unwieldy, so you may also use these short forms:
method &.( $capture ) {...}
method @.[ **@slice ] {...}
method %.{ **@slice } {...}
Also, I think this might be relevant though less so: http://perlcabal.org/syn/S12.html
Search for:
You may write your own accessors to override any or all of the autogenerated ones.
So you return an object which has several context-specific accessors.
Interestingly enough, it started out with Perl6 replacing "wantarray" with a generic "want": RFC 98 (v1) context-based method overloading, circa 2000, also at http://dev.perl.org/perl6/rfc/21.html . I'm not sure why/when the change was made.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With