Skip Menu |
Report information
Id: 132511
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: comdog <brian.d.foy [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: rakudobug [...] perl.org
Date: Mon, 27 Nov 2017 17:35:13 -0800
From: brian d foy <brian.d.foy [...] gmail.com>
Subject: Binary assignment Z+= fails if it's the last thing in for loop
Download (untitled) / with headers
text/plain 648b
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> }
Date: Tue, 28 Nov 2017 03:21:48 +0100
To: perl6-compiler [...] perl.org
Subject: Re: [perl #132511] Binary assignment Z+= fails if it's the last thing in for loop
From: Timo Paulssen <timo [...] wakelift.de>
Download (untitled) / with headers
text/plain 276b
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.
FWIW it never worked: https://gist.github.com/Whateverable/d9dbebb0e985a3964845df2c8652cbdf

On 2017-11-27 17:36:22, comdog wrote:
Show quoted text
> 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> }




This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org