Today in "use overload", the so-called assignment operator can be defined. If an overloaded operator is called on an object that is not unique but shares a reference, this function is called to duplicate it. That is, it's uses as a lazy copy-on-write mechanism.
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
$a= $b;
++ $a;
can indeed be made to work like built-in numbers, calling
$a= $b;
$a->set_imaginary (5);
cannot, and would set the imaginary part of $b as well.
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.