Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can gather be used to unroll Junctions?

In this program:

use v6;
my $j = +any "33", "42", "2.1";
gather for $j -> $e {
    say $e;
} # prints 33␤42␤2.1␤

for $j -> $e {
    say $e; # prints any(33, 42, 2.1)
}

How does gather in front of forchange the behavior of the Junction, allowing to create a loop over it? The documentation does not seem to reflect that behavior. Is that spec?

like image 396
jjmerelo Avatar asked Sep 26 '19 17:09

jjmerelo


1 Answers

Fixed by jnthn in code and test commits.


Issue filed.

Golfed:

    do put .^name for any 1 ; # Int
       put .^name for any 1 ; # Mu

Any of ten of the thirteen statement prefixes listed in the doc can be used instead of do or gather with the same result. (supply unsurprisingly produces no output and hyper and race are red herrings because they try and fail to apply methods to the junction values.)

Any type of junction produces the same results.

Any number of elements of the junction produces the same result for the for loop without a statement prefix, namely a single Mu. With a statement prefix the for loop repeats the primary statement (the put ...) the appropriate number of times.

I've searched both rt and gh issues and failed to find a related bug report.

like image 56
raiph Avatar answered Nov 13 '22 03:11

raiph