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

Binary assignment Z+= fails if it's the last thing in for loop #6642

Closed
p6rt opened this issue Nov 28, 2017 · 6 comments
Closed

Binary assignment Z+= fails if it's the last thing in for loop #6642

p6rt opened this issue Nov 28, 2017 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Nov 28, 2017

Migrated from rt.perl.org#132511 (status was 'resolved')

Searchable as RT132511$

@p6rt
Copy link
Author

p6rt commented Nov 28, 2017

From @briandfoy

I previously asked about this unexpected Z behavior on Stackoverflow
( https://stackoverflow.com/q/45001820/2766176 ).

I expected this to change several hash keys at once. It changes no keys​:

  my $hash = %(
  wallet => 100,
  gave => 0,
  received => 0,
  );

  for ^1 { $hash<wallet gave> Z+= <-1 1> }

  dd $hash;

I get​:

  Hash $hash = ${​:gave(0), :received(0), :wallet(100)}

If I change that to add another statement it works​:

  for ^1 { $hash<wallet gave> Z+= <-1 1>; True }

It also works if I take out the binary assignment​:

  for ^1 { $hash<wallet gave> = $hash<wallet gave> Z+ <-1 1> }

@p6rt
Copy link
Author

p6rt commented Nov 28, 2017

From @timo

Curious sidenote​:

when you use [Z+]= it will complain about "useless use of [Z+]= in sink
context" and the modifications actually go through. With Z[+=] - which
is probably the default parsing of this - it will not complain about
useless use, but it also won't Do The Thing.

@p6rt
Copy link
Author

p6rt commented Nov 28, 2017

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

@p6rt
Copy link
Author

p6rt commented Dec 4, 2017

From @AlexDaniel

FWIW it never worked​: https://gist.github.com/Whateverable/d9dbebb0e985a3964845df2c8652cbdf

On 2017-11-27 17​:36​:22, comdog wrote​:

I previously asked about this unexpected Z behavior on Stackoverflow
( https://stackoverflow.com/q/45001820/2766176 ).

I expected this to change several hash keys at once. It changes no keys​:

my $hash = %(
wallet => 100,
gave => 0,
received => 0,
);

for ^1 { $hash<wallet gave> Z+= <-1 1> }

dd $hash;

I get​:

Hash $hash = ${​:gave(0), :received(0), :wallet(100)}

If I change that to add another statement it works​:

for ^1 { $hash<wallet gave> Z+= <-1 1>; True }

It also works if I take out the binary assignment​:

for ^1 { $hash<wallet gave> = $hash<wallet gave> Z+ <-1 1> }

@p6rt
Copy link
Author

p6rt commented Feb 26, 2018

From @zoffixznet

On Mon, 04 Dec 2017 12​:31​:28 -0800, alex.jakimenko@​gmail.com wrote​:

FWIW it never worked​:
https://gist.github.com/Whateverable/d9dbebb0e985a3964845df2c8652cbdf

On 2017-11-27 17​:36​:22, comdog wrote​:

I previously asked about this unexpected Z behavior on Stackoverflow
( https://stackoverflow.com/q/45001820/2766176 ).

I expected this to change several hash keys at once. It changes no keys​:

my $hash = %(
wallet => 100,
gave => 0,
received => 0,
);

for ^1 { $hash<wallet gave> Z+= <-1 1> }

dd $hash;

I get​:

Hash $hash = ${​:gave(0), :received(0), :wallet(100)}

If I change that to add another statement it works​:

for ^1 { $hash<wallet gave> Z+= <-1 1>; True }

It also works if I take out the binary assignment​:

for ^1 { $hash<wallet gave> = $hash<wallet gave> Z+ <-1 1> }

Thank you for the report. This is now fixed.

Fix​: rakudo/rakudo@8a10fc17a319029
Test​: Raku/roast@01b59fba66bde1e61

@p6rt
Copy link
Author

p6rt commented Feb 26, 2018

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

@p6rt p6rt closed this as completed Feb 26, 2018
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