Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pair.WHICH distinguishes pairs with same container value #5579

Open
p6rt opened this issue Aug 15, 2016 · 5 comments
Open

Pair.WHICH distinguishes pairs with same container value #5579

p6rt opened this issue Aug 15, 2016 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 15, 2016

Migrated from rt.perl.org#128948 (status was 'open')

Searchable as RT128948$

@p6rt
Copy link
Author

p6rt commented Aug 15, 2016

From zefram@fysh.org

Pair.WHICH has special behaviour if the pair's value is a container​:

my $a; my $b = :a($a); my $c = :a($a); $a = 3; for $b, $c { say (.WHICH, .perl) }
(Pair|47082244733376 :a(3))
(Pair|47082244733472 :a(3))

As you can see, both pairs are behaviourally equivalent, in that they
have the same key and refer to the same value container, thus both seeing
the change in the value contained in it. But they get different .WHICH
values, falsely suggesting that they're distinct. (=== follows .WHICH
in falsely indicating that they're distinct.)

The container case of .WHICH is using the default .WHICH that reflects the
physical identity of the Pair objects. To get the intended equivalence,
Pair.WHICH needs to reflect the key and the identity of the container held
in the value slot. I think that just removing the branch of Pair.WHICH
for the container case would be correct.

-zefram

@p6rt
Copy link
Author

p6rt commented Aug 15, 2016

From @lizmat

A Pair in which the value is a container, is mutable. And therefore cannot be a value type​:

$ 6 'my $p = a => my $ = 42; say $p.WHICH; $p.value = 666; say $p.WHICH'
Pair|140196969054016
Pair|140196969054016

Note if the value is *not* a container​:

$ 6 'my $p = a => 42; say $p.WHICH; $p.value = 666; say $p.WHICH'
Pair|Str|a|Int|42
Cannot modify an immutable Int
  in block <unit> at -e line 1

I think this is ENOTABUG

On 15 Aug 2016, at 15​:56, Zefram (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Zefram
# Please include the string​: [perl #​128948]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128948 >

Pair.WHICH has special behaviour if the pair's value is a container​:

my $a; my $b = :a($a); my $c = :a($a); $a = 3; for $b, $c { say (.WHICH, .perl) }
(Pair|47082244733376 :a(3))
(Pair|47082244733472 :a(3))

As you can see, both pairs are behaviourally equivalent, in that they
have the same key and refer to the same value container, thus both seeing
the change in the value contained in it. But they get different .WHICH
values, falsely suggesting that they're distinct. (=== follows .WHICH
in falsely indicating that they're distinct.)

The container case of .WHICH is using the default .WHICH that reflects the
physical identity of the Pair objects. To get the intended equivalence,
Pair.WHICH needs to reflect the key and the identity of the container held
in the value slot. I think that just removing the branch of Pair.WHICH
for the container case would be correct.

-zefram

@p6rt
Copy link
Author

p6rt commented Aug 15, 2016

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

@p6rt
Copy link
Author

p6rt commented Aug 15, 2016

From zefram@fysh.org

Elizabeth Mattijsen via RT wrote​:

A Pair in which the value is a container, is mutable.

Not really. The *container* is mutable. The Pair can't be changed to
refer to any other container, as far as I can see​:

my $a; my $b = :a($a); my $c = :a($a); $b.value = 3; $b.perl, $c.perl
(​:a(3) :a(3))

I've mutated something there, but it's not one of the pairs to
the exclusion of the other. It's the thing they share, the value
container. These pairs should therefore show the same identity
under .WHICH. I'd expect the .WHICH string to be something like
"Pair|Str|a|Scalar|47608575457088".

-zefram

@p6rt
Copy link
Author

p6rt commented Aug 16, 2016

From zefram@fysh.org

I wrote​:

          I'd expect the \.WHICH string to be something like

"Pair|Str|a|Scalar|47608575457088".

Upon further investigation, I think this requires

  multi method WHICH(Pair​:D​:) {
  "Pair|" ~ $!key.WHICH ~ "|" ~ $!value.VAR.WHICH
  }

That is, .VAR needs to be applied to $!value, which isn't currently in
the WHICH method. My original suggestion of merely using the existing
non-container branch of the WHICH method, without this fix, would
cause the WHICH to reflect the identity of the value in the container.
That outcome is what Liz then pointed out would be incorrect, though it
was never what I intended.

-zefram

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant