2 ;; The EVAL function in the original XLISP evaluated in the current lexical
3 ;; context. This was changed to evaluate in the NIL (global) context to
4 ;; match Common Lisp. But this created a problem: how do you EVAL an
5 ;; expression in the current lexical context?
7 ;; The answer is you can use the evalhook facility. The evalhook function
8 ;; will evaluate an expression using an environment given to it as an
9 ;; argument. But then the problem is "how do you get the current
10 ;; environment?" Well the getenv macro, below obtains the environent by
11 ;; using an *evalhook* form.
13 ;; The following two macros do the job. Insteading of executing (eval <expr>)
14 ;; just execute (eval-env <expr>). If you want, you can dispense with the
15 ;; macros and execute:
17 ;;(evalhook <expr> nil nil (let ((*evalhook* (lambda (x env) env)))
24 '(let ((*evalhook
* (lambda (x env
) env
)))
25 (eval nil
))) ; hook function evaluates by returning
28 (defmacro eval-env
(arg) ; evaluate in current environment
29 `(evalhook ,arg nil nil
(getenv)))