If I understand the Raku docs correctly, the elements of Arrays are always containerized, i.e. Scalars. However, the deepmap method seems to create (inner) Arrays with uncontainerized elements:
my @a = [1, [2, 3]];
my @b = @a.deepmap: *.clone;
say @b[0].VAR.^name; # Scalar, this is OK
say @b[1].^name; # Array, as expected
say @b[1][0].VAR.^name; # Int, why?
@b[0] = 4; # this works
@b[1][0] = 5; # error: Cannot assign to an immutable value
Why does this happen?
For context, I originally wanted to use .deepmap: *.clone
to create a deep copy, but I needed the copy to be mutable. I solved the problem by using @a.deepmap: { my $ = .clone }
, but I am still curious why this happens.