query on closure...

Discussion of Common Lisp

query on closure...

Postby megera » Fri Nov 09, 2012 5:56 am

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
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

Re: query on closure...

Postby Goheeca » Fri Nov 09, 2012 6:35 am

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).
User avatar
Goheeca
 
Posts: 197
Joined: Thu May 10, 2012 12:54 pm

Re: query on closure...

Postby megera » Fri Nov 09, 2012 8:31 am

ohh good ;)
thanks for explanation ;)
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 1 guest

cron