> On 7 Apr 2017, at 13:49, brian d foy (via RT) <perl6-bugs-follo...@perl.org> 
> wrote:
> 
> # New Ticket Created by  "brian d foy" 
> # Please include the string:  [perl #131114]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/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.

Reply via email to