5

When I try to modify matrix in raku. I got the error :

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

Why all of those values are immutable value?

黃家億
  • 355
  • 1
  • 4

1 Answers1

5

Well, lists are always immutable. You can modify their container, but not themselves. rotor creates lists, so once they have been created, you can't modify them. Don't know exactly what you want to do here, but looking at the errors here, I would say you need to turn those immutable lists into mutable Arrays:

my @matrix = ^100 .rotor(10).map: *.Array;
@matrix[1;*] = 1 xx 10;
@matrix[1;1] = 3;
jjmerelo
  • 22,578
  • 8
  • 40
  • 86