Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: Local for lexicals

by JadeNB (Chaplain)
on Aug 12, 2009 at 19:26 UTC ( [id://788015]=note: print w/replies, xml ) Need Help??


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

Seems you just want a complicated way of not writing $_[0] in the sub. That can be done of course. But why would you? And what has this to do with localizing a lexical, which you were asking about in your earlier posts? If you're passing in the parameter to the sub, there's no need to localize anything, is there?
In order:
  1. Yes, that's right (for the lambda example).
  2. Skipped.
  3. Why not?
  4. Only that localising a lexical was my first thought for how to implement it. (Example code is at Local for lexicals.) Once I thought of the problem in that context, it immediately seemed to crop up many other places.
  5. You are certainly right that there are ways to do it without localisation. If I write out the sub—as you've done here:
    my $f = sub {my $x = shift; sub {$x ** 2}->()};
    (formatted, I think, specifically to be faithful to my original attempt), or even more briefly as just:
    my $f = sub { my $x = shift; $x**2 }
    then it certainly works. I would just like to avoid the slight extra verbiage and write instead
    my $f = lambda $x => sub { $x**2 }
    as syntactic sugar (well, for some definition of ‘sugar’) for the same thing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found