Raku has both mutable and immutable containers of various sorts. Here are some of the most common ones:
Mutable
# Arraymy @array = 1,2,3;@array.push: 4,5,6;# Hashmy %hash = 'a'=> 1, 'b'=> 2;%hash<c d> = 3,4;%hash.push: 'e'=> 5, 'f'=> 6;# SetHashmy $s = SetHash.new: <a b c>;$s ∪= <d e f>;# BagHashmy $b = BagHash.new: <b a k l a v a>;$b ⊎= <a b c>;
Immutable
# Listmy @list := 1,2,3;my @newlist := |@list, 4,5,6; # |@list will slip @list into the surrounding list instead of creating a list of lists# Setmy $set = set <a b c>;my $newset = $set ∪ <d e f>;# Bagmy $bag = bag <b a k l a v a>;my $newbag = $bag ⊎ <b e e f>;
Pair list (cons list)
my $tail = d => e => f => Nil;my $new = a => b => c => $tail;
P6opaque object (immutable in structure)
class Something { has $.foo; has $.bar };my $obj = Something.new: foo => 1, bar => 2;my $newobj = $obj but role { has $.baz = 3 } # anonymous mixin