Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: sort +*, @array

by raiph (Hermit)
on Dec 10, 2013 at 07:24 UTC ( #1066391=note: print w/ replies, xml ) Need Help??


in reply to Re^3: sort +*, @array
in thread sort +*, @array

I'm not saying that the design of the P6 builtin is ST, just that it is functionally equivalent, and even more concise.

And it's not just about the "decorate" step, which your "key extractor" closure is roughly equivalent of.

One critical point: while a "key extractor" closure is indeed roughly equivalent to the decorate step in terms of the role it's playing, it's multiple key extractor closures that is basically fully equivalent to the before map.

Because the ST has an explicit sort block (normally, unless it's the GRT variant :-)), it allows to execute arbitrarily complex Perl code in the comparison. Where does one do that in this Perl 6 "equivalent"?

You just specify a comparator closure (or multiple, if you want).

(P6 can tell the difference due to a closure's number of args. If it has one, it's a key extractor closure, if it has two it's a comparator closure.)

For lots more examples which are still correct modulo a few minor syntax shifts, see "The Sort Problem: a definitive ruling" from 2004.

Which got me to focus on the Pair variant which maybe helps clarify the connection for you:

sort { #`( key extractor closure) } => { #`( comparator closure) }, { #`( key extractor closure) } => { #`( comparator closure) }, ... @array


Comment on Re^4: sort +*, @array
Download Code
Re^5: sort +*, @array
by Anonymous Monk on Dec 10, 2013 at 21:31 UTC
    I'm not saying your posts are full of blowhard marketing nonsense, but they're functionally equivalent. Do you even program, bro?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066391]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2014-09-16 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (45 votes), past polls