Larry --

So, will "mutatingness" be a context we'll be able to inquire on
in the implementation of a called routine? Or, could we provide
a specialized distinct implementation for mutating that would get
called if .=X() is used? If we are performing some operation on
large data, and we know the end result is going to clobber the
current object, we could avoid making an extra copy.

I suppose there is some danger here. What if I write a class
that I intend to have value semantics. That is, once an instance's
value is set at construction time,  it never changes, although you
can get new instances by invoking its methods. BigInt would
work this way. I can imagine a Point class working this way - you
don't (necessarily) want two objects hanging on to a point, and one
of them to mutate it into a different value out from under the other
one. You wouldn't expect that behavior from other value objects such
as built-in strings.

This points at mutatingness being aimed at the reference (variable)
not the referrent (value), unless it can be different in the case
of value-objects and container-objects...

So, if we had a BigDataContainer class for which it *was* reasonable
to mutate it in place, and we wanted that behavior to trigger on .=
to do an in-place modification:

  $bigData .=applyBlockCipher($cipher, $key);

would there be a way to do that without the extra copy implied in:

  $bigData = $bigData.applyBlockCipher($cipher, $key);

while leaving

  $foo .=someOtherMethod();

equivalent to

  $foo = $foo.someOtherMethod();

when $foo's class or someOtherMethod() implementation doesn't do
anything special?


Regards,

-- Gregor

On Wed, 2004-03-10 at 21:29, Larry Wall wrote:
> On Wed, Mar 10, 2004 at 10:46:05PM -0500, matt wrote:
> : I was thinking along the lines of...
> : 
> : String $foo = "hello";
> : $foo.scramble!
> 
> That would be $foo.=scramble in the current scheme of things.
> 
> : print "$foo\n";
> : $foo = "hello"
> : print $foo.scramble ~ "\n";
> : print $foo;
> : 
> : OUTPUT (or close):
> : elhlo
> : hloel
> : hello
> : 
> : Also, along these same things.. is there a way to apply a method to all
> : variables/objects of a certain type (e.g. String, Num, etc)?  Taking the
> : above example.. being able to write a method called "Scramble" that can be
> : called as a method from any String type.
> 
> Two ways, actually.  You can 'reopen" the String class and add the method:
> 
>     class String is extended {
>       method scramble () returns String {...}
>     }
> 
> or if you consider that underhanded, you can define a multi-sub:
> 
>     multi sub *scramble (String $s) returns String {...}
> 
> If you call that as a method, and there is no ordinary scramble method,
> it will "fail soft" to looking for a scramble multimethod, and end up
> calling your definition.  Or you can just call it directly as a function:
> 
>     scramble("hello")
> 
> Larry
-- 
Gregor Purdy                            [EMAIL PROTECTED]
Focus Research, Inc.               http://www.focusresearch.com/

Reply via email to