How to translate this Common LISP code in newLisp?

Q&A's, tips, howto's
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

How to translate this Common LISP code in newLisp?

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

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Re: How to translate this Common LISP code in newLisp?

Post by ale870 »

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: How to translate this Common LISP code in newLisp?

Post 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

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Re: How to translate this Common LISP code in newLisp?

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: How to translate this Common LISP code in newLisp?

Post by Lutz »


Locked