TSa Thomas.Sandlass-at-vts-systems.de |Perl 6| wrote:

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;

where the reverse method returns a new string that somehow has to
find its way into $s. That is, the method call sequence has to be
different for object types and value types. The start is identical:


Don't do that. Changing the identity of the object will mean that other containers pointing to the same copy will change, but other containers pointing to another physical copy (but the same id) will not.

Well, or the language is explicit about the capture of the new
value. Is this meant with

   $s.=reverse; # means $s = $s.reverse



Yes. Define .reverse to return a new object, and use .= if you want it to go back into the same container. I suppose that seeing .= will make it easy for the compiler to optimize, if the object is not shared it can reuse the structure.

--John

Reply via email to