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; 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: 1) fetch pointer from container 2) bind self to this pointer and call method For object types this is sufficient because the pointer in the container remains valid. A value type on the other hand needs 3) capture new pointer 4) store new pointer in container Note that the return value of the method is independent of this new pointer to the modified value. To unify these two sequences the system either has to know which type of object the pointer in the container belongs to or all four steps are executed for both types where the mutable ones always return the same pointer. The price to pay for the flexibility of the latter approach is with expensive store operations of the container. 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? Regards, TSa. -- "The unavoidable price of reliability is simplicity" -- C.A.R. Hoare "Simplicity does not precede complexity, but follows it." -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan