Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: Experimenting with Lvalue Subs

by BrowserUk (Pope)
on Jan 24, 2005 at 23:59 UTC ( #424747=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Experimenting with Lvalue Subs
in thread Experimenting with Lvalue Subs

I just saw that and read the pertaining bits of apo6. In particular

RFC 107: lvalue subs should receive the rvalue as an argument

This would make it hard to dynamically scope an attribute. You'd have to call the method twice--once to get the old value, and once to set the new value.

The essence of the lvalue problem is that you'd like to separate the identification of the object from its manipulation. Forcing the new value into the same argument list as arguments meant to identify the object is going to mess up all sorts of things like assignment operators and temporization.

Which, without some form of explaination of how it "is going to mess up all sorts of things" and why those things are considered more important than the ability to validate the assigned value, sounds an aweful lot like "because I said so" :(


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.


Comment on Re^5: Experimenting with Lvalue Subs
Re^6: Experimenting with Lvalue Subs
by Aristotle (Chancellor) on Jan 25, 2005 at 00:06 UTC

    He is saying that it would make it impossible to do things like (in spirit)

    local $foo->bar = 'baz';

    ie dynamic scoping. If the sub was responsible for the actual assignment, this would be impossible because it can't know whether the assignment is scoped dynamically and because there is no obvious mechnism for undoing the assignment at the end of the block. If you require validating to go through a tied proxy object, all of this is trivial since all the existing language hooks work as expected.

    Makeshifts last the longest.

      I fully understood that bit.

      I'm saying that I do not see why that ability would take precedence over being able to validate the value assigned without resorting to callback via tieing (even if it is by the streamlined, inline mechanism). It just seems like an optimisation aimed at the rare case.

      I will want to validate every occurance of assignment to an attribute. I (at this stage) cannot see a use for localising it. If it required a callback to achieve localisation for those (I think rare) occasions when I might want to do that but not for the general case , I would see that as a good thing.

      But as I said earlier, it is very possible that I am missing the significance of the implementation. I've been sat here trying to understand the P5 code that does this for the last couple of hours and I am none the wiser as to the technical reasoning behind this.

      As far as I can tell, with the ability of the code in the sub to decide the target of the assignment at invokation time:

      { my( $x, $y ) = ( 0, 0 ); sub t : lvalue { my $ref = (rand >.5) ? \$x : \$y; $$ref } sub showme{ print "x=$x : y=$y" } } t = 5; showme; x=0 : y=5 t = 7; showme; x=0 : y=7 t = 9; showme; x=9 : y=7

      I don't understand the difficulties? The code has to be run to determine the target (and therefore what would need to be localised).

      If, at that point, the code produced a warning or died, or rendered a dummy target that prevented the assignment or whatever other action might be appropriate if the rvalue was deemed invalid because it tested the rvalue supplied to it, I don't understand how that would prevent the correct value being localised if it was valid?


      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.

        I (at this stage) cannot see a use for localising it.

        Let's just say that this is why Larry is designing the language and not you or I… :-)

        I don't understand how that would prevent the correct value being localised if it was valid?

        I suppose it could work if the lvalue sub was given the rvalue solely for the purpose of validation, but was expected not to do the actual assignment itself. I'm not sure if that has ramifications past the obvious though — that's something Larry will have to answer.

        Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://424747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-12-27 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls