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 construction peculiarity in: my $x = 42; $x = :$x; #4649

Closed
p6rt opened this issue Oct 15, 2015 · 7 comments
Closed

pair construction peculiarity in: my $x = 42; $x = :$x; #4649

p6rt opened this issue Oct 15, 2015 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Oct 15, 2015

Migrated from rt.perl.org#126369 (status was 'rejected')

Searchable as RT126369$

@p6rt
Copy link
Author

p6rt commented Oct 15, 2015

From @dwarring

From RT​:

[10​:17] <dwarring> r​: my $x = 42; $x = :$x; say $x.perl
[10​:17] <+camelia> rakudo-jvm 271e84​: ( no output )
[10​:17] <+camelia> ..rakudo-moar 271e84​: OUTPUT«(my \Pair_140034859548832 = :x(Pair_140034859548832))␤»
[10​:18] * dwarring weird
...
[10​:21] <dwarring> r​: my $x = 42; $x = (​:$x); say $x.perl
[10​:22] <+camelia> rakudo-jvm 271e84​: OUTPUT«(my \Pair_1677829811 = :x(Pair_1677829811))␤»
[10​:22] <+camelia> ..rakudo-moar 271e84​: OUTPUT«(my \Pair_139757510868552 = :x(Pair_139757510868552))␤»
...
[10​:22] <dwarring> r​: my $x = 42; my $y = (​:$x); say $y.perl
[10​:22] <+camelia> rakudo-{moar,jvm} 271e84​: OUTPUT«​:x(42)␤»

@p6rt
Copy link
Author

p6rt commented Oct 15, 2015

From @dwarring

On Thu Oct 15 14​:29​:37 2015, david.warring wrote​:

From RT​:

[10​:17] <dwarring> r​: my $x = 42; $x = :$x; say $x.perl
[10​:17] <+camelia> rakudo-jvm 271e84​: ( no output )
[10​:17] <+camelia> ..rakudo-moar 271e84​: OUTPUT«(my
\Pair_140034859548832 = :x(Pair_140034859548832))␤»
[10​:18] * dwarring weird
...
[10​:21] <dwarring> r​: my $x = 42; $x = (​:$x); say $x.perl
[10​:22] <+camelia> rakudo-jvm 271e84​: OUTPUT«(my \Pair_1677829811 =
:x(Pair_1677829811))␤»
[10​:22] <+camelia> ..rakudo-moar 271e84​: OUTPUT«(my
\Pair_139757510868552 = :x(Pair_139757510868552))␤»
...
[10​:22] <dwarring> r​: my $x = 42; my $y = (​:$x); say $y.perl
[10​:22] <+camelia> rakudo-{moar,jvm} 271e84​: OUTPUT«​:x(42)␤»

A fudged test has been added to S02-types/pair.t

@p6rt
Copy link
Author

p6rt commented May 7, 2016

From @smls

Not a bug.

Unlike a Hash, a Pair doesn't force a fresh item containers on its value.
It takes each value as it is.
This means that normally a Pair is immutable, but if you construct it from a Scalar container (like $x is here), then the pair takes that mutable Scalar container as its value.

`List`s (but not `Array`s) work the same way​:

  ➜ my $x = 42; $x = (1, 2, $x); say $x.perl;
  (my \List_80395672 = $(1, 2, List_80395672))

A side-effect of this is that you can define recursive lists and pairs, which is what you inadvertently did in the given example.
To avoid that, you could use the <> postfix operator to explicitly decontainerize the value of $x before passing it to the Pair constructor​:

  ➜ $x = :x($x<>);

TL;DR​:
The fudged test that has been added to roast should be removed again, and then this ticket should be closed.

@p6rt
Copy link
Author

p6rt commented May 7, 2016

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

@p6rt
Copy link
Author

p6rt commented Jun 11, 2016

From @dwarring

Sam,
thanks for the explanation. I've changed my code which triggered the error to​: my $x = 42; $x := :$x;

So that $x rebinds to thye outer pair container.

I will withdraw or modify the test case as above.

On Sat May 07 14​:07​:55 2016, smls75@​gmail.com wrote​:

Not a bug.

Unlike a Hash, a Pair doesn't force a fresh item containers on its
value.
It takes each value as it is.
This means that normally a Pair is immutable, but if you construct it
from a Scalar container (like $x is here), then the pair takes that
mutable Scalar container as its value.

`List`s (but not `Array`s) work the same way​:

➜ my $x = 42; $x = (1, 2, $x); say $x.perl;
(my \List_80395672 = $(1, 2, List_80395672))

A side-effect of this is that you can define recursive lists and
pairs, which is what you inadvertently did in the given example.
To avoid that, you could use the <> postfix operator to explicitly
decontainerize the value of $x before passing it to the Pair
constructor​:

➜ $x = :x($x<>);

TL;DR​:
The fudged test that has been added to roast should be removed again,
and then this ticket should be closed.

@p6rt
Copy link
Author

p6rt commented Jun 12, 2016

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

@p6rt p6rt closed this as completed Jun 12, 2016
@p6rt
Copy link
Author

p6rt commented Jun 14, 2016

From @dwarring

Note. I've kept the test, but changed the assignment to a bind.
On Sat Jun 11 15​:22​:26 2016, david.warring wrote​:

Sam,
thanks for the explanation. I've changed my code which triggered the
error to​: my $x = 42; $x := :$x;

So that $x rebinds to thye outer pair container.

I will withdraw or modify the test case as above.

On Sat May 07 14​:07​:55 2016, smls75@​gmail.com wrote​:

Not a bug.

Unlike a Hash, a Pair doesn't force a fresh item containers on its
value.
It takes each value as it is.
This means that normally a Pair is immutable, but if you construct it
from a Scalar container (like $x is here), then the pair takes that
mutable Scalar container as its value.

`List`s (but not `Array`s) work the same way​:

➜ my $x = 42; $x = (1, 2, $x); say $x.perl;
(my \List_80395672 = $(1, 2, List_80395672))

A side-effect of this is that you can define recursive lists and
pairs, which is what you inadvertently did in the given example.
To avoid that, you could use the <> postfix operator to explicitly
decontainerize the value of $x before passing it to the Pair
constructor​:

➜ $x = :x($x<>);

TL;DR​:
The fudged test that has been added to roast should be removed again,
and then this ticket should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant