This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

query on closure...

3 posts · 2775 views

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:
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...

I would say it's unique from the historical point of view. And Python and such languages follow this up.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Re: query on closure...

ohh good ;)
thanks for explanation ;)