Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^4: closure clarity, please

by ikegami (Pope)
on Nov 24, 2009 at 20:52 UTC ( #809205=note: print w/ replies, xml ) Need Help??

in reply to Re^3: closure clarity, please
in thread closure clarity, please

Ok, I can understand that confusion. Lexicals are actually allocated very early on (compile-time?) and on scope exit. This allows for the creation of private variables:

package Foo; my $x; sub set_x { validate($_[0]); $x = $_[0]; } sub get_x { die("uninitialized") if !defined($x); $x } 1;
{ my $x; sub set_x { validate($_[0]); $x = $_[0]; } sub get_x { die("uninitialized") if !defined($x); $x } }

Comment on Re^4: closure clarity, please
Select or Download Code
Replies are listed 'Best First'.
Re^5: closure clarity, please
by JadeNB (Chaplain) on Nov 25, 2009 at 07:05 UTC
    Lexicals are actually allocated very early on (compile-time?)
    I think that it must be true that lexicals are allocated at compile time—at least, if my timeline in Re^4: closure clarity, please is anything near the correct one. I can't see any other reason why the call to f on line 27 of Re^3: closure clarity, please (which I called step 9) would be affected by the call to g on line 23 (which I called step 7). (In fact, I thought that I stole this observation from a post of yours that I read long ago ….)
      The alternative is that they could be vivified by the capture.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2016-02-08 19:17 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (283 votes), past polls