2 ms·
In Clozure Common Lisp: ? (defun closure-test () (let ((x 32)) (list (lambda (y) (+ y 10)) (lambda (y) (+ x y))))) CL
by lispm 11y ago
In Clozure Common Lisp:
? (defun closure-test ()
(let ((x 32))
(list (lambda (y) (+ y 10))
(lambda (y) (+ x y)))))
CLOSURE-TEST
? (closure-test)
(#<Compiled-function (:INTERNAL CLOSURE-TEST) (Non-Global) #x302000CBD71F>
#<COMPILED-LEXICAL-CLOSURE (:INTERNAL CLOSURE-TEST) #x302000D1EE2F>)
- gsg 11y agoWeird that it doesn't propagate the constant such that both functions are closed - maybe with a higher optimisation level.
- lispm 11y agoSince CCL uses the compiler everywhere, even for interactive use, it is useful to have quick/dumb and slower/optimizing modes. Some Lisps use an Interpreter for interactive use in the Listener and the compiler for the rest. It's a typical tradeoff.