You know, when I first read that section of A6, I thought "that's as ugly as anything I've ever seen... eh, I'm sure it'll get changed". Now, around 3 years later, I re-read it, and I think "that's as ugly as anything I've ever seen -- it's gotta get fixed, or we'll be stuck with it". This doesn't match how I think about lvalue subs. It doesn't match how I think of lvalue subs. I think of lvalue subs as a different calling convention from a normal sub -- a view reinforced by that being the way most languages that have them seem to think of them. The way you're doing it seems to match the way perl5 does it. Lvalue subs aren't much used in perl5, and them being annoying to use is one reason for that.
Why not make $foo->bar('baz')='quux'; with a declared method multimethod bar($this: *@lvalues, @rvales :rvalues); does... well, the obvious: makes $this be $foo, @rvalues be ('bar') and @lvalues be ('quux'). IOW, make the lvalues be a special zone (in A6 terms), with no presigil signifier, but only a long name. (I suppose you haven't yet used > (points to the left) for anything in this context, but it'd be confusing, because it comes up rarely, and could be difficult to find in the docs, whereas "rvalue" is somewhat obvious, or at least easier to look up.)
As is normal for multimethods, that body is only called if the call matches it -- that is, it's done in an lvalue context.
One difficulty is in determining the context of the RHS of the assignment. Normally, the context of an assignment is determined by what is being assigned to. This is one of the major reasons in both p5 and p6, the lvalue is evaluated before the rvalue, which is why the lvalue sub can't tell what rvalue is being assigned. This needs an aditional rule, I think, instead of a workaround that keeps information from the programmer when they want it. If the lvalue sub has only a single scalar paramter in the :rvalues zone, then it's in scalar context. Otherwise, it's in list context. (If there are two multimethods that have equally compatable signatures, and one of them would be list context by this rule, and the other scalar, then warn, and do it in list.)
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||