Richard Hainsworth wrote:
The following (the n:> is to mark the lines) are legal:

1:> my @x = 1,2,3,4; ([+] @x).say; # output 10
2:> my @x = 1|11,2,3,4; ([+] @a).perl.say; # output any(10,20)
3:> my @x = 1|11,2,3,4; ([+] @a).eigenstates.min.say; # output 10

However, the next line isnt
4:> my @x = 1,2,3,4; ([+] @a).eigenstates.min.say; # Method 'eigenstates' not found for invocant of class 'Integer'

But suppose I dont know until runtime whether @x contains a junction or not, eg.,

my @s = 1|11,2,3,4,5,6,7; # as in the value of an ace in 21
my @x;
loop {
   @x = @s.pick(3);
   ([+] @x).eigenstates.min.say;
};

Eg.
$ perl6
> my @s=1|11,2,3,4,5,6;my @x; loop {...@x=@s.pick(3);([+] @x).eigenstates.min.say}
8
6
Method 'eigenstates' not found for invocant of class 'Integer'
>

I suggested to Masak on irc that an integer is a singleton, hence a degenerate Junction. He said not.

So, how to determine whether a junction is being used or not?

You can detect junctions by smart-matching against the Junction type (e.g. $sum ~~ Junction).

my @s=1|11,2,3,4,5,6;
loop {
   my $sum = [+] @s.pick(3);
   say $sum ~~ Junction ?? $sum.eigenstates.min !! $sum;
}

Jonathan

Reply via email to