如何在 raku-lang 中修改矩阵

How to modify matrix in raku-lang

当我尝试修改 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 are always immutable. You can modify their container, but not themselves. rotor 创建列表,因此一旦创建,您就无法修改它们。 不知道你到底想在这里做什么,但看看这里的错误,我会说你需要把那些不可变的列表变成可变的 Arrays:

my @matrix = ^100 .rotor(10).map: *.Array;
@matrix[1;*] = 1 xx 10;
@matrix[1;1] = 3;