Page 1 of 1

query on closure...

Posted: Fri Nov 09, 2012 5:56 am
by megera
HI
in the book Graham says about closure :
"""When a function refers to a variable defined outside it, it's called a free variable. A function that refers to a free lexical variable is called a closure The variable must persist as long as the function does."""
and after says also that """Closures are one of the uniquely wonderful things about Lisp"""...but isn't it?
for example in python we can follow this behavior for example with 'nonlocal' variabile declaration:

Code: Select all

def closurep():
    n = 3
    def closurep_help(m):
        nonlocal n  # now we can set a new value for 'n
        n += 1
        return (n * m)
    return closurep_help

x = closurep()
print(x(3)) --> 12

but also decorators may be considered in "closure way"...if we want..
then I understood the true meaning of CLisp closure? are they only a CL 's prerogative?.. :| thanks in advance

Re: query on closure...

Posted: Fri Nov 09, 2012 6:35 am
by Goheeca
I would say it's unique from the historical point of view. And Python and such languages follow this up.

Re: query on closure...

Posted: Fri Nov 09, 2012 8:31 am
by megera
ohh good ;)
thanks for explanation ;)