TSa wrote:
> The 'is rw' is on the method but I guess it is foreseen that the
> result is stored in $string without preserving the identity of the
> string?

No. It means that the Str object has to get hold of the container in
which it is stored, and store a modified copy in it. If that fails (for
example in "abc".substr(0, 1) = "foo", where "abc" isn't in a container
at all) the write operation will fail.

>     my $a = "His name is barney";
>     my $b = $a;
> 
>     $a ~~ /(barney)/;
>     substr($a, $0.from, $0.to) = "fred";
> 
>     say $b; # prints fred?

No, the match object needs to be bound to the value (which is immutable)
unless the :rw modifier is present.

> If substr should get access to the container passed as argument then
> the signature should read
> 
>     our Str multi method substr (Str $string is rw: StrPos $start,
>                                  Int $length) is rw is export
> 
> and the docu should say that the result is written into the container
> passed in the invocant slot. But the 'is rw' on the invocant has the
> drawback that calling with a string literal is precluded.

Makes sense to me. (The Int should really be StrLen, but that's only a
minor glitch).

That said, much of S29 needs some loving care...

Moritz

-- 
Moritz Lenz
http://moritz.faui2k3.org/ |  http://perl-6.de/

Reply via email to