Lisp-likeness
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Tue Mar 15 18:20:31 EST 2005
Thomas A. Russ wrote:
> Fernando <frr at easyjob.net> writes:
>
>
>>On 15 Mar 2005 00:43:49 -0800, "Kay Schluehr" <kay.schluehr at gmx.net>
>>wrote:
>>
>>
>>>Maybe You can answer my question what this simple LISP function does ?
>>>
>>>(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?
AFAIK, yes. I admit that I know almost nothing about Lisp though. And
I'm not a Python guru either.
> What happens if you call addn more than once with different
> parameters. Will you get different functions that you can
> use simultaneously?
Yes. Using the addn function defined above, you can do for example:
>>> add4 = addn(4)
>>> add10 = addn(10)
>>> add4(5)
9
>>> add10(7)
17
>>> add4(add10(28))
42
And so on. At least, I think that's what you mean.
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
More information about the Python-list
mailing list