当我尝试修改 raku 中的矩阵时。 我收到错误:
my @matrix = ^100 .rotor(10);
@matrix[1;*] = 1 xx 10
Cannot modify an immutable Int (10)
in block <unit> at <unknown file> line 1
@matrix[1;1] = 3
Cannot modify an immutable List ((10 11 12 13 14 15 1...)
in block <unit> at <unknown file> line 1
为什么所有这些值都是不可变的值?
最佳答案
嗯,lists总是不可变的。您可以修改它们的容器,但不能修改它们本身。 rotor
创建列表,因此一旦创建列表,您就无法修改它们。
不知道你到底想在这里做什么,但是看看这里的错误,我想说你需要将这些不可变列表转换为可变 Array
s:
my @matrix = ^100 .rotor(10).map: *.Array;
@matrix[1;*] = 1 xx 10;
@matrix[1;1] = 3;
关于raku - 如何修改raku-lang中的矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59701812/