Idea: "Frozen" inner function

Steve Horne stephenwantshornenospam100 at aol.com
Sat Nov 25 18:34:48 PST 2006


On Sat, 25 Nov 2006 14:41:49 +0100, Michael Butscher
<mbutscher at gmx.de> wrote:

>Especially a closure would have direct access to the current value of 
>local variables of the outer function (if it exists yet) which is not 
>the case for frozen functions.

That's not the definition of closures I was taught. A closure would
behave exactly as your frozen function does - it does not have direct
access to the current value since it keeps a copy of the value at the
time when the definition was 'executed'.

So for instance, in Python (which does use closures)...

a = 5
fn = lambda : a
a = 6
print fn()

The output should be 5, not 6 - the value when the lambda expression
was evaluated.

Is it possible that you're being misled by the style of closures used
for generics? They tend to mostly hold function pointers (pointers to
the methods for the type that the generic is specialised for), but
could possibly hold pointers to global variables too.

-- 
Remove 'wants' and 'nospam' from e-mail.



More information about the Digitalmars-d mailing list