Perl6 Operator Questions

I was looking at a stupid / cute / brilliant dream that seems to have originated in 4chan . To sort an ints array, the idea is roughly equal

    
     foreach elt in @array
         spawn thread (elt)

where thread (n) does

  sleep n
     print n

so that smaller values ​​are printed earlier.

Perl6 implementation is implemented there

  @foo = @foo >>. & sleep;

I get that >> "hyper" operator, and this assumes that hyperpolation is automatically parallelized. But .& Bothers me.

Can anyone explain this?

thanks

+6
source share
1 answer

If you have yourfunc function, you can get a link to it using the ampersand, &yourfunc . The syntax of $obj.$function simply calls $function with one argument, $obj . So you can simply write $function($obj) - except that this syntax does not allow hyper.

But the one who came up with this “implementation” was mistaken in three accounts:

  • The hyper-operator allows the compiler to spawn multiple threads for each method to execute, it should not spawn a thread for all of them at once, so "random sorting" cannot work
  • A hyper operator can randomize the execution order of methods, but it must preserve the order or returned elements, so @foo will not be sorted at all, even if the first point is not applicable.
  • sleep () should return the number of seconds, but not an argument. If someone makes the computer sleep during the calculation, the result can be much larger.
+8
source

Source: https://habr.com/ru/post/891154/


All Articles