Which context confuses this Perl 6 zip operator?

假装没事ソ 提交于 2019-12-13 12:26:51

问题


Consider this program where I create a hash. I want to then change two values in it:

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

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

dd $hash;

Like this, the last line of for doesn't do anything and there is no warning. The hash is unchanged:

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

Adding another statement changes the behavior:

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

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

dd $hash;

Now the inplace edit does its thing, but there's a warning (although I dispute "useless" when I've found a use for it):

Useless use of constant value True in sink context
Hash $hash = ${:gave(1), :received(0), :wallet(99)}

If I do without the Z+=, which should be the same thing, it works:

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

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

dd $hash;

Again the right output:

Hash $hash = ${:gave(1), :received(0), :wallet(99)}

回答1:


It's a bug. Fixed as of Rakudo 2018.02.1-45-g8a10fc1



来源:https://stackoverflow.com/questions/45001820/which-context-confuses-this-perl-6-zip-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!