In Routine§
See primary documentation in context for trait is rw
multi trait_mod:<is>(Routine , :!)
When a routine is modified with this trait, its return value will be writable. This is useful when returning variables or writable elements of hashes or arrays, for example:
sub walk(\thing, *) is rwmy ;walk(, 'some', 'key', 1, 2) = 'autovivified';say .raku;
produces
("some" => ).hash
Note that return
marks return values as read only; if you need an early exit from an is rw
routine, you have to use return-rw
instead.
In Type system§
See primary documentation in context for trait is rw
sub trait_mod:<is>(Mu , :!)
The trait is rw
on a class will create writable accessor methods on all public attributes of that class.
is rw;my = C.new.a = 42;say ; # OUTPUT: «42»