September 2017
Beginner
402 pages
9h 52m
English
Now try passing a junction to a function that takes a scalar:
sub f($x) { say $x; return $x;}say 'OK' if f(1 | 3 | 5) == 3;say 'Not OK' if f(1 | 3 | 5) != 2;
The behavior is intuitively understandable—the function is executed for each of the values of the junction separately. The values that the function returns are then used as the values of a junction.
The preceding code works the same as the following code, where the function receives a single scalar value:
say 'OK' if f(1) | f(3) | f(5) == 3;say 'Not OK' if f(1) | f(3) | f(5) != 2;
Moving the junction operation outside the function argument is called autothreading. In theory, the code from the last example may be executed in parallel.
Now, let us move to the next topic and ...
Read now
Unlock full access