Why do + and ~ affect Perl 6 connections differently?

Add one to the Ints connection:

put any( 1, 3, 7 ) + 1; 

Now you have the connection of these Ints increased by one:

 any(2, 4, 8) 

So 2 == any(2, 4, 8) true.

Make a string join and add to these lines:

 put any( <h H> ) ~ 'amadryas'; 

You get another result that is not equal to "hamadryas" or "Hamadryas":

 any("h", "H")amadryas 

I was expecting something like:

 any( 'hamadryas', 'Hamadryas' ); 

What difference in these operations gives them a different behavior, even if they should be similar?

+8
perl6 perl6-junction
source share
2 answers

The result with ~ that you are observing is a strict join added to the second line.

The reason is that ~ has a random candidate that accepts the connection as arg, and + does not have such a candidate, and therefore it combines:

 <Zoffix__> m: sub foo (*@a) { @a.join: '|' }; say foo <h H>.any, 'amadryas' <camelia> rakudo-moar a91ad2: OUTPUT: «any("h", "H")|amadryas␤» <Zoffix__> m: sub foo ($a, $b) { ($a, $b).join: '|' }; say foo <h H>.any, 'amadryas' <camelia> rakudo-moar a91ad2: OUTPUT: «any(h|amadryas, H|amadryas)␤» 

At the very least, this is a contradictory behavior and should be unified. I opened the @LARRY RT ticket for this: https://rt.perl.org/Ticket/Display.html?id=131856

+4
source share

in High Sierra 10.13, crashing:

 put any( 1, 3, 7 ) + 1 

This type cannot unpack the original line: P6opaque, Junction in a block in line 1

 perl6 -v 

This is the version of Rakudo Star 2017.10, built on the version of MoarVM 2017.10 implementation of Perl 6.c.

+1
source share

All Articles