Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify matrix in raku-lang

Tags:

raku

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?

like image 792
黃家億 Avatar asked Jan 12 '20 07:01

黃家億


1 Answers

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;
like image 124
jjmerelo Avatar answered Oct 23 '22 18:10

jjmerelo