Lisp-likeness

Valentino Volonghi aka Dialtone dial#####$$NOSPAM##$#$## at gmail.com
Tue Mar 15 17:50:24 EST 2005


Thomas A. Russ <tar at sevak.isi.edu> wrote:

> > >(defun addn (n)
> > >     #'(lambda (x)
> > >         (+ x n)))
> > 
> > The same as 
> > def addn(n):
> >     def fn(x):
> >             return n + x
> >     return fn
> 
> Is this really equivalent?

yes

> What happens if you call addn more than once with different
> parameters.  Will you get different functions that you can
> use simultaneously?

yes

> The lisp snippet creates new functions each time the addn function is
> called, so one can interleave calls to the individual functions.

In [21]: a = addn(4)

In [22]: b = addn(5)

In [23]: c = addn(25)

In [24]: a(1)
Out[24]: 5

In [25]: b(1)
Out[25]: 6

In [26]: c(1)
Out[26]: 26

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.3.8
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de



More information about the Python-list mailing list