Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^9: Experimenting with Lvalue Subs

by Juerd (Abbot)
on Jan 25, 2005 at 22:55 UTC ( #425076=note: print w/ replies, xml ) Need Help??


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

I think juerd has posted a number of examples of where such behaviour would be very useful indeed. Hopefully he will reply with a link.

Just think of anything you can do with a variable, but cannot do with a value returned by a sub.

Variables are really powerful in Perl because they are mutable. While other languages disagree that this is a good thing (Python, for example, has immutable variables - only assignment can change a value), we should stick to the Perl idea that this can actually be put to great use.

Variables are variable, and that's where they excel. Some examples of what you can do on lvalues, but not on rvalues:

But really, my favourite:
  • you can take a reference and pass that, re-use that, etcetera!

To extend it to Perl 6, I'll explain how "." and ".=" work in P6: "." is used for method calls and dereferencing, as with "->" in Perl 5. ".=" is like Perl 5's ".=", except "." doesn't concatenate strings. If this is too vague, let one example be sufficient to explain what I mean: @array.=sort; does the same as @array = @array.sort, but possibly more efficient. No more need for LHS detection hacks like with the optimization for @array = sort @array; in Perl 5.

The expressiveness, flexibility and efficiency of lvalue operations must not be undersestimated.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


Comment on Re^9: Experimenting with Lvalue Subs
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-12-25 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (159 votes), past polls