Arc's eval works by compiling an expression sans lexical environment, then calling mzscheme's eval on the result. (xdef eval (lambda (e)
(eval (ac (ac-denil e) '()))))
So, it obviously can't evaluate lexical variables: arc> (= x 5)
5
arc> (eval 'x)
5
arc> (let x 10 (eval 'x))
5
arc> (let y 10 (eval 'y))
Error: "reference to undefined identifier: _y"
Perhaps this is intentional. It's the way Common Lisp's eval works, though at least you can reify the environment $ clisp
[1]> (setf x 5)
5
[2]> (eval 'x)
5
[3]> (let ((x 10)) (eval 'x))
5
[4]> (let ((x 10)) (the-environment))
#(#(X 10 NIL) NIL NIL NIL ((DECLARATION XLIB::CLX-VALUES VALUES OPTIMIZE DECLARATION)))
and use this with evalhook, which takes the environment as an argument [5]> (let ((x 10)) (evalhook 'x nil nil (the-environment)))
10
It's even the way mzscheme's eval works (to the best of my knowledge), so we can't just do something like (xdef eval (lambda (expr env)
(eval (ac (ac-denil expr) (ac-denil env)))))
since Scheme's eval still won't know what to do with the lexical variables compiled out by ac.I've tried hacking various solutions into ac.scm, but my Scheme-fu is pathetic, and I haven't gotten anything working 100%. I suspect there's some relevant mzscheme feature or other, but I'm pretty tired of wrestling with this. Can anyone help? |