哪个上下文使此Perl 6 zip运算符感到困惑? [英] Which context confuses this Perl 6 zip operator?
本文介绍了哪个上下文使此Perl 6 zip运算符感到困惑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑在我创建哈希的程序.然后,我要更改其中的两个值:
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;
像这样,for
的最后一行不执行任何操作,也没有警告.哈希值保持不变:
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)}
如果我没有Z+=
,应该是同一件事,那么它会起作用:
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;
再次获得正确的输出:
Hash $hash = ${:gave(1), :received(0), :wallet(99)}
推荐答案
这是一个错误一个>.自Rakudo 2018.02.1-45-g8a10fc1
It's a bug. Fixed as of Rakudo 2018.02.1-45-g8a10fc1
这篇关于哪个上下文使此Perl 6 zip运算符感到困惑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文