This program
my @bitfields;
for ^3 -> $i {
@bitfields[$i] = Bool.pick xx 3;
}
my @total = 0 xx 3;
for @bitfields -> @row {
@total Z+= @row;
}
say @total;
says [0 0 0]
. If we add something to the loop, whatever:
my @bitfields;
for ^3 -> $i {
@bitfields[$i] = Bool.pick xx 3;
}
my @total = 0 xx 3;
for @bitfields -> @row {
@total Z+= @row;
say "foo";
}
say @total;
It will work correctly. Apparently, the last element of the block is thrown into sink context which in this case means it's simply ignored; this trap is related to that. However, that code above looks perfectly fine; and this
{@total Z+= @^t} for @bitfields;
apparently works, although I don't see the real difference. Any other idea?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…