updated version, but need to update installation scripts
[cls.git] / xlisponly / lsp / evalenv.lsp
blobab217a8bd137e9527a44c87dcbf8504d61739f7c
1 ;;
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?
6 ;;
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)))
18 ;; (eval nil)))
20 ;; Tom Almy 10/91
23 (defmacro getenv ()
24 '(let ((*evalhook* (lambda (x env) env)))
25 (eval nil))) ; hook function evaluates by returning
26 ; environment
28 (defmacro eval-env (arg) ; evaluate in current environment
29 `(evalhook ,arg nil nil (getenv)))