How to translate this Common LISP code in newLisp?

Started by ale870, October 26, 2009, 06:27:47 AM

Previous topic - Next topic

ale870

Hello,



I was reading an article on an italian magazine, and I found the following code:



(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!
--

ale870

#1
Maybe can I use "curry" function? Is this good way to follow?
--

Lutz

#2
newLISP uses namespaces instead of closures in Common Lisp


> (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/newlisp_manual.html#func_memory">http://www.newlisp.org/downloads/newlis ... unc_memory">http://www.newlisp.org/downloads/newlisp_manual.html#func_memory

ale870

#3
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!
--

Lutz

#4
http://www.newlisp.org/index.cgi?Closures">http://www.newlisp.org/index.cgi?Closures



also referenced from here:



http://www.newlisp.org/index.cgi?page=Differences_to_Other_LISPs">http://www.newlisp.org/index.cgi?page=D ... ther_LISPs">http://www.newlisp.org/index.cgi?page=Differences_to_Other_LISPs