Closures
Posted: Fri Oct 26, 2007 12:12 pm
What's the difference between newLISP closures and Lisp/Scheme closures? I've been reading http://lispy.wordpress.com/2007/10/25/w ... -hurt-you/:
Although this looks like a procedure with state, I know that Lutz has said that newLISP 'context closures' aren't closures...
So, what's the difference between newLISP 'closures' and Lisp/Scheme closures?
The 'classic example' of the accumulator built-in to a function that he mentions has appeared on this forum too:So a closure turns out to be just a procedure with state.
Code: Select all
(context 'gen)
(define (foo)
(if (number? acc)
(inc 'acc)
(set 'acc 0)))
(context MAIN)
> (gen:foo)
0
> (gen:foo)
1
> (gen:foo)
2
> (gen:foo)
3
So, what's the difference between newLISP 'closures' and Lisp/Scheme closures?