On 3/15/09 11:19 AM, 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'

[...]
I've been pondering and experimenting with this.

Now that the Object.eigenstates patch is in, all of the above cases do it indeed work. But what if you have more than one ace in your hand?

5:> my @x = 1|11, 1|11, 10; ([+] @x).eigenstates.min.say
Junction<0x7f89311bca30>

Not so useful.

6:> my @x = 1|11, 1|11, 10; ([+] @x).perl.say
any(any(12, 22), any(22, 32))

A junction of junctions.  And three aces?

7:> my @x = 1|11, 1|11, 1|11, 10; ([+] @x).perl.say
any(any(any(13, 23), any(23, 33)), any(any(23, 33), any(33, 43)))

Yikes! Is there a way of flattening such a beast into any(13, 23, 33, 43) ? Does a deeply nested Junction have any practical value that the flattened one does not?

At any rate, it behaves much the same as a flattened version would when matched against:

8:> my @x = 1|11, 1|11, 1|11, 10; ([+] @x) == 23 && say "Match!"
Match!

And so, the solution almost presents itself:

9:> my @x = 1|11, 1|11, 1|11, 10; say ([+] @x) ~~ 1..21 ?? "OK" !! "Bust!"
OK
10:> my @x = 1|11, 1|11, 1|11, 10, 9; say ([+] @x) ~~ 1..21 ?? "OK" !! "Bust!"
Bust!

And of course, that would have worked before the patch.

Oh, and ++ for coming up with such a cool use for junctions in the first place!

Bruce

Reply via email to