in reply to Re: Perl6 - value vs. reference issues
in thread Perl6 - value vs. reference issues
This means that Perl must know that the reference is shared, and which functions are indeed "mutators". I can have a complex number class appear to have value semantics when an assignment is followed by an overloaded operator such as "+", but not for a named method call.
So, something like
can indeed be made to work like built-in numbers, calling$a= $b; ++ $a;
cannot, and would set the imaginary part of $b as well.$a= $b; $a->set_imaginary (5);
Perhaps Perl6 simply needs to have the lazy copy function applied uniformly whenever a mutator is called, whether you must identify mutators or it figures it out by itself.
Meanwhile, why write the copy code every time? Simply saying that a class is "by value" should be enough to automatically generate the copy function, which copies all the data members of the object.
—John
|
|---|