Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: Closures clarification

by lodin (Hermit)
on Dec 04, 2007 at 14:52 UTC ( #654804=note: print w/replies, xml ) Need Help??

in reply to Re: Closures clarification
in thread Closures clarification

If I'm not mistaken, neither of your examples are closures. According to Intermediate Perl, a closure is "just a subroutine that references a lexical variable that has gone out of scope".

The anonymous subroutine passed by reference to find does bind a lexical variable ($total_size). By most definitions (e.g wikipedia's), that subroutine is then a closure. The variable doesn't have to have gone out of lexical scope. The important part is that the subroutine deeply binds the variable, and the variable may go out of scope.


PS. The code should read sub { instead of { sub, but that's not important for the question at hand.

Replies are listed 'Best First'.
Re^3: Closures clarification
by memnoch (Scribe) on Dec 04, 2007 at 15:52 UTC
    Thanks lodin...I missed that other typo! I have addressed it in my previous posting. But as far as whether it was a closure or not, according to Intermediate Perl, the lexical variable needs to have gone out of scope for the subroutine to be a closure....that's what I was going off of.


    Gloria in Excelsis Deo!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2021-03-05 11:09 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (109 votes). Check out past polls.