Page 1 of 1
How to translate this Common LISP code in newLisp?
Posted: Mon Oct 26, 2009 1:27 pm
by ale870
Hello,
I was reading an article on an italian magazine, and I found the following code:
Code: Select all
(defun foo (n)
(lambda (i) (incf n i)))
Well, this is an accumulator, and it returns another function that takes another number "i" and return "n" increased by "i".
Can you help me?
Thank you!
Re: How to translate this Common LISP code in newLisp?
Posted: Mon Oct 26, 2009 1:32 pm
by ale870
Maybe can I use "curry" function? Is this good way to follow?
Re: How to translate this Common LISP code in newLisp?
Posted: Mon Oct 26, 2009 1:53 pm
by Lutz
newLISP uses namespaces instead of closures in Common Lisp
Code: Select all
> (define (acc:acc i) (inc acc:value i))
(lambda (i) (inc acc:value i))
> (acc 1)
1
> (acc 3)
4
> (acc 6)
10
>
see also:
http://www.newlisp.org/downloads/newlis ... unc_memory
Re: How to translate this Common LISP code in newLisp?
Posted: Mon Oct 26, 2009 2:02 pm
by ale870
Thank you Lutz, I forgot that article!
I noticed you no more include "if" statement. I think using "if" is more clear, but the example you sent me before is better for standard Lisp comparison (closures).
Maybe you could include it in the official documentation.
I think even a small article in the official PDF document about closures could be useful too...
Thank you!
Re: How to translate this Common LISP code in newLisp?
Posted: Mon Oct 26, 2009 2:20 pm
by Lutz