I was looking at the silly/cute/brilliant "sleep sort" that seems to have originated over at 4chan. To sort an array of ints, the idea is roughly
foreach elt in @array
spawn thread(elt)
where thread(n) does
sleep n
print n
so the smaller values get printed earlier.
There's a Perl6 implementation
@foo = @foo>>.&sleep;
I get that >> 'hypers' the operator, and that this assumes hypering is automatically parallelized. But the .& confuses me.
Can anyone explain this?
thanks
If you have a function yourfunc, then you can grab a reference to it with the ampersand, &yourfunc. The syntax $obj.$function just invokes $function with one argument, $obj. So one could just as well write $function($obj) - except that this syntax doesn't allow the use of a hyper.
But whoever came up with this "implementation" was wrong on three accounts:
@foo will not be sorted at all, even if the first point didn't apply.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