Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^6: Experimenting with Lvalue Subs

by Aristotle (Chancellor)
on Jan 25, 2005 at 00:06 UTC ( #424749=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re^6: Experimenting with Lvalue Subs
Download Code
Re^7: Experimenting with Lvalue Subs
by BrowserUk (Pope) on Jan 25, 2005 at 00:31 UTC

    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.

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

        Understood. But I've never needed to do this in the past, (and I assume that were it a common occurance in your programming you would have produced an example), so as hard as I might try, I cannot think of a pressing use for it.

        That is, any use beyond the one that is (very breifly) alluded too at the very end of Apo6:

        But let and friends need to be blazing fast if we're ever going to use Perl for logic programming, or even recursive descent parsing.

        Grammers are the foundation of not just p6 regexes, but at the very core of P6 itself, and (I assume) that grammers (and therefore P6) will require a RDP.

        So, reading between the line, I assume that the emphasis on the speed of "hypotheticals" and with them, "temporisable" lvalue subs, is a requirement to ensure that P6 regexes and P6 compilation is fast. If this is the case, it would be nice if that was stated a little more clearly somewhere--even if just in response to questions like this.

        That said--and it is only my leap of intuition at this stage--the only way I see of avoiding invoking an lvalue sub twice, whilst retaining the ability to undo lexically localised changes to it, is to actually not assign at the notional point of assignment, but rather defer the actual assignment until the end of the local scope, by proxying the value for the duration of that scope and only making the assignment at the end of the localised scope, if hypothetical is--for want of a better term--realised.

        If that is how it will be done, then could not that final rvalue, be provided to the sub at that point for verification? It still comes down to understanding what action might be taken by the sub suthor in the event that rvalue fails verification. And of those actions possible, which would be the cause of an undesirable slowdown in the processing of an lvalue sub?

        Like you said, it will probably need LW or TheDamian to resolve that question.


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2014-07-10 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (213 votes), past polls