home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xl21hos2.zip / EVALENV.LSP < prev    next >
Text File  |  1995-12-27  |  1KB  |  32 lines

  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.
  12. ;;
  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:
  16. ;;
  17. ;;(evalhook <expr> nil nil (let ((*evalhook* (lambda (x env) env)))
  18. ;;                (eval nil)))
  19. ;;
  20. ;; Tom Almy  10/91
  21. ;;
  22.  
  23. (defmacro getenv () 
  24.       '(let ((*evalhook* (lambda (x env) env)))
  25.         (eval nil)))    ; hook function evaluates by returning 
  26.                 ; environment
  27.                 
  28. (defmacro eval-env (arg)    ; evaluate in current environment
  29.       `(evalhook ,arg nil nil (getenv)))
  30.  
  31.  
  32.