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

Re^5: Local for lexicals

by BrowserUk (Patriarch)
on Aug 11, 2009 at 04:39 UTC ( [id://787480]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Local for lexicals
in thread Local for lexicals

Maybe this is a repetition of a question already asked--possibly even asked and answered--but having re-read the thread, I cannot see it. So here goes:

{ #outer scope $lamb = lambda ( $x, $y, $z ) => sub { $x + $y } }

This is, in a sense, the crux of my problem—I don't want the values of $x, $y, and $z to leak from the inside out, or vice versa,

What are you trying to achieve that this doesn't?

my( $x, $y, $z ) = ( 1,2,3 ); my $lamb = do{ my( $x, $y, $z ) = ( $x, $y, $z ); lambda ( $x, $y, $z ) => sub { $x + $y } }

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".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^6: Local for lexicals
by JadeNB (Chaplain) on Aug 12, 2009 at 19:17 UTC
    What are you trying to achieve that this doesn't?
    my( $x, $y, $z ) = ( 1,2,3 ); my $lamb = do{ my( $x, $y, $z ) = ( $x, $y, $z ); lambda ( $x, $y, $z ) => sub { $x + $y } }
    Unfortunately, I don't know quite what this does, so I can't answer! My question (at least, the part of my question that seems to have attracted the most attention) is how to write lambda in such a way that lambda( $x, $y, $z ) => sub { $x + $y } is the same as sub { $_[0] + $_[1] }. As far as I can tell, the code that you've written would be the same as
    my ( $x, $y, $z ) = ( 1, 2, 3 ); lambda ( 1, 2, 3 ) => sub { 1 + 2 }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-26 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found