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.

lodin

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.

    memnoch

    Gloria in Excelsis Deo!