Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: sort +*, @array

by raiph (Chaplain)
on Dec 09, 2013 at 12:32 UTC ( #1066280=note: print w/replies, xml ) Need Help??

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

Sorts numerically. (The default is to sort stringwise).

Replies are listed 'Best First'.
Re^3: sort +*, @array
by hdb (Prior) on Dec 09, 2013 at 12:39 UTC

    Thanks for your reply.

    So it is the Perl 6 equivalent to say sort {$a <=> $b} @array;?

    But how is that statement related to the Schwartzian transformation?

      The +* is a "key extractor" closure. This closure corresponds to the before map of the ST. Of course, in the specific case of +*, it's trivial to instead just specify a "comparator" closure using <=>, but what if one instead writes:

      say sort +*.value, 1=>4, 11=>5, 2=>99, 22=>22, 3=>339 # prints 1=>4 11=>5 22=>22 2=>99 3=>339 say sort ~*.value, 1=>4, 11=>5, 2=>99, 22=>22, 3=>339 # prints 22=>22 3=>339 1=>4 11=>5 2=>99

      (And of course the results of the closure call on a given item is memoized.)

        Thanks for the explanation. So the link to the Schwartzian really is the fact that the items are automatically memoized.

Re^3: sort +*, @array
by moritz (Cardinal) on Dec 11, 2013 at 12:27 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066280]
[stevieb]: I don't know what you mean. I write the code in C/C++ that accesses the ICs per the datasheet, wrap it for Perl, then use them. My code ensures that the functions/methods from Perl do the right thing for the chips/sensors etc
[stevieb]: At least that's what I'm working on right now. I've also been updating my automated test software Test::BrewBuild so it handles this work properly. It's not really easy meshing high level languages with low-level hardware :)
[stevieb]: this link is probably better for an overview of my test software

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-06-25 23:12 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.