# Should junctions collapse unique values?#6180

Closed
opened this issue Apr 7, 2017 · 9 comments
Closed

# Should junctions collapse unique values? #6180

opened this issue Apr 7, 2017 · 9 comments

### p6rt commented Apr 7, 2017

 Migrated from rt.perl.org#131114 (status was 'rejected') Searchable as RT131114\$ The text was updated successfully, but these errors were encountered:

### From @briandfoy

# using Rakudo 2017.01

Should junctions only care about unique values?

For example, does 3 need to be in the junction twice?

> my \$j = any( 1, 2, 3, 3 )
any(1, 2, 3, 3)

I ran into this when I was playing around with something like
this where I ended up with a junction has the same value repeated​:

> \$j > 5
any(False, False, False, False)

Curiously, I expected the result would be either True or False
rather than another junction.

Consider how this propagates​:

> \$j > any( 5, 2 )
any(any(False, False), any(False, False), any(False, True),
any(False, True))

As a boolean value, this is merely a baroque True. Since junctions
are not introspective, it doesn't need to remember how it got there.

### From @AlexDaniel

Something to note​:

Code​:
sub foo(\$x) {
say ‘foo’;
rand
}
say foo (1 | 1 | 1)

Result​:
foo
foo
foo
any(0.142758876399169, 0.287238600458814, 0.123654645170192)

Also, trying to filter out unique values in a junction is probably more costly than just doing whatever operation you've got with each element (in most cases at least).

On 2017-04-07 04​:49​:58, comdog wrote​:

# using Rakudo 2017.01

Should junctions only care about unique values?

For example, does 3 need to be in the junction twice?

my \$j = any( 1, 2, 3, 3 )
any(1, 2, 3, 3)

I ran into this when I was playing around with something like
this where I ended up with a junction has the same value repeated​:

\$j > 5
any(False, False, False, False)

Curiously, I expected the result would be either True or False
rather than another junction.

Consider how this propagates​:

\$j > any( 5, 2 )
any(any(False, False), any(False, False), any(False, True),
any(False, True))

As a boolean value, this is merely a baroque True. Since junctions
are not introspective, it doesn't need to remember how it got there.

### p6rt commented Apr 7, 2017

 The RT System itself - Status changed from 'new' to 'open'

### From @zoffixznet

Hi,

Should junctions only care about unique values?

No, Junctions aren't about unique values. They're a superposition of values that threads through routines without them even knowing they're working with a Junction​:

m​: my \$a = 3|3; my \$x++ for ^\$a; say \$x
rakudo-moar 49c0ab​: OUTPUT​: «6␤»

In the future, when seeking support, would it be possible for you to use proper support channels, instead of the bug reporting system, as a means to ask questions?

There are plenty of venues available to cater to all tastes​:

IRC​: https://webchat.freenode.net/?channels=#perl6
Email​: perl6-users@​perl.org http://www.nntp.perl.org/group/perl.perl6.users/
SO​: http://stackoverflow.com/questions/tagged/perl6
Reddit​: https://www.reddit.com/r/perl6/
Slack​: https://perl6.slack.com/

There are plenty of helping hands to go around.

### p6rt commented Apr 7, 2017

 @zoffixznet - Status changed from 'open' to 'rejected'

closed this as completed Apr 7, 2017

### From @briandfoy

I consider it a bug that a Junction does what its doing, and reported
it as such. The combinatorial explosion is something I think should
not happen.

For questions, I use Stackoverflow. However, other people keep telling
me to file bugs. Lots of mixed messages there. Either way, the real
time and social media channels aren't searchable and of little value
to those googling to find answers to similar questions.

### From @lizmat

On 7 Apr 2017, at 14​:19, Zoffix Znet via RT <perl6-bugs-followup@​perl.org> wrote​:
In the future, when seeking support, would it be possible for you to use proper support channels, instead of the bug reporting system, as a means to ask questions?

I think this is uncalled for. brian is using StackOverflow for questions. And one *could* think this is a bug.

And I don’t see this kind of reaction when other people post RT tickets with similar issues that may or may not be bugs.

So please, treat everybody the same! :-)

There are plenty of venues available to cater to all tastes​:

IRC​: https://webchat.freenode.net/?channels=#perl6
Email​: perl6-users@​perl.org http://www.nntp.perl.org/group/perl.perl6.users/
SO​: http://stackoverflow.com/questions/tagged/perl6
Reddit​: https://www.reddit.com/r/perl6/
Slack​: https://perl6.slack.com/

There are plenty of helping hands to go around.

Indeed. A good list. Is this published anywhere?

Liz

### From @lizmat

On 7 Apr 2017, at 13​:49, brian d foy (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by "brian d foy"
# Please include the string​: [perl #​131114]
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=131114 >

# using Rakudo 2017.01

Should junctions only care about unique values?

For example, does 3 need to be in the junction twice?

my \$j = any( 1, 2, 3, 3 )
any(1, 2, 3, 3)

I would argue yes for two reasons​:

1. What determines when something is unique?
This is typically done by using the .WHICH method on the object and using the resulting string as a key in a hash. But that *can* be very expensive for some types of objects, like sets, bags, buffers, etc. Imposing a uniqueness check on junctions would cause a severe degradation in performance of junctions. Even if it can be done at compile time.
2. Junctions *can* have side effects, if they contain Callables and you call the junction. Having identical Callables in there may produce different side-effects.

I ran into this when I was playing around with something like
this where I ended up with a junction has the same value repeated​:

\$j > 5
any(False, False, False, False)

Curiously, I expected the result would be either True or False
rather than another junction.

Now, Booleanising a junction *does* collapse​:

\$ 6 'my \$j = any(1,2,3); say (\$j > 5).Bool'
False

The REPL doesn’t booleanize, and thus you see the whole junction​:

\$ 6 'my \$j = any(1,2,3); say \$j > 5'
any(False, False, False)

Consider how this propagates​:

\$j > any( 5, 2 )
any(any(False, False), any(False, False), any(False, True),
any(False, True))

As a boolean value, this is merely a baroque True. Since junctions
are not introspective, it doesn't need to remember how it got there.

Again, the REPL is not booleanizing​:

\$ 6 'my \$j = any(1,2,3); say \$j > any( 5, 2 )'
any(any(False, False), any(False, False), any(False, True))

If you do, it does *exactly* what you expect​:

\$ 6 'my \$j = any(1,2,3); say (\$j > any( 5, 2 )).Bool’
True

or​:

\$ 6 'my \$j = any(1,2,3); say ?(\$j > any( 5, 2 ))’
True

I think this ticket can be closed.

### From @briandfoy

I figured the comparison operator would Booleanize, because that's how
it's (halfway) documented (Raku/doc#1269).

If it's something else, the Operators docs should explain it in another way.