Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^12: can sub check context for lvalue vs rvalue context?

by perl-diddler (Chaplain)
on May 14, 2018 at 03:59 UTC ( [id://1214435]=note: print w/replies, xml ) Need Help??


in reply to Re^11: can sub check context for lvalue vs rvalue context?
in thread can sub check context for lvalue vs rvalue context?

In non-lvalue context, you can return the direct variable. It doesn't matter if the lvalue is "ever" modified -- only at that point when it is dereferenced. It isn't returned if you are taking a reference to it.

Only in every instance where you dereference it, does it THEN determine context. But passing around a reference is a null-op as far as the object goes. The code in it won't get called as long as one is only taking references to it and passing them around as references or aliases.

  • Comment on Re^12: can sub check context for lvalue vs rvalue context?

Replies are listed 'Best First'.
Re^13: can sub check context for lvalue vs rvalue context?
by BrowserUk (Patriarch) on May 14, 2018 at 14:16 UTC
    In non-lvalue context, you can return the direct variable. It doesn't matter if the lvalue is "ever" modified -- only at that point when it is dereferenced. It isn't returned if you are taking a reference to it.

    Sorry, but I think I've been more than patient. That's BS!

    Its BS, because you cannot ever know if it is called "In non-lvalue context". Perl provides no mechanism to give you that information.

    Wishing it were so does not make it so. Stridently concluded that "you can"; on the basis of your fantasy that you could if perl gave you the information; is stupid.

    Stupid, because Perl cannot give you that information!.

    Another attempt. This time, try reading the code and understanding it -- not your fantasy vision of it:

    sub x :lvalue{ ...; $something } ... someFunc( x() );

    The value returned from x() is passed to somefunc() as $_[0]; if somefunc() modifies $_[0], it also modifies $something within x(). Perl cannot know if it does!

    And someFunc() might do someOtherFunc( $_[0] ); And if someOtherFunc() modifies it's version of $_[0], it will also modify $something in x().

    And if someOtherFunc() calls someOtherOtherFunc( $_[0] ); And if someOtherOtherFunc() modifies it's version of $_[0], then it will also modify $something.

    And if someOtherOtherFunc()....

    It is not possible for Perl to delve into all the calling code; and all the code it calls, and all the code that code calls through to the end of the program run to determine if anything will/could/might modify the lvalue x() returns.

    And wish and prevaricate as much as you like; it ain't never gonna happen.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-18 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found