TSa wrote: > HaloO, > > Darren Duncan wrote: >> If you are wanting to actually mutate a Dog in a user-visible way rather >> than deriving another Dog, then I don't think that calling Dog a value >> type is appropriate. > > I think that mutating methods of immutable value types just have > to modify the identity. The problem is how that relates to references. > Take e.g. the Str type > > my $s = 'abc'; # $s points to 'abc' > $s.reverse;
[...] > Well, or the language is explicit about the capture of the new > value. Is this meant with > > $s.=reverse; # means $s = $s.reverse > > or is this an error that 'abc' is readonly? $s.reverse returns a reversed copy of $s, and $s.=reverse does the "in place" reverse, ie it directly modifies $s (but not the string stored in $s. At least conceptually. But you can't observe the differences, afaict) When you read carefully through S29 you'll notice that most methods in immutable classes (like Str, List, Int) only return modified copies, even if they mutate the string in Perl 5. (There are some exceptions like Str.substr, which explicitly 'is rw', and which implies that the object somehow has to gain access to its container). Moritz -- Moritz Lenz http://moritz.faui2k3.org/ | http://perl-6.de/