home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / lisp / 2933 < prev    next >
Encoding:
Text File  |  1992-11-22  |  2.0 KB  |  55 lines

  1. Path: sparky!uunet!spool.mu.edu!uwm.edu!ogicse!news.u.washington.edu!uw-beaver!cthomas
  2. From: cthomas@cs.washington.edu (Christopher Thomas)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Evaluating in given environment?
  5. Message-ID: <1992Nov23.025931.27024@beaver.cs.washington.edu>
  6. Date: 23 Nov 92 02:59:31 GMT
  7. Article-I.D.: beaver.1992Nov23.025931.27024
  8. Sender: news@beaver.cs.washington.edu (USENET News System)
  9. Distribution: usa
  10. Organization: University of Washington Computer Science
  11. Lines: 42
  12.  
  13.  
  14. I have a problem to solve in Common Lisp, and a solution that seems to work.
  15. I am posting this to get feedback on the solution.
  16.  
  17. Problem: I have a macro that takes a form as an argument, and the expansion
  18. passes that form to a function.  I want the function to evaluate the form,
  19. but in the lexical environment of the macro expansion.  Here is a simplified
  20. example of my problem:
  21.  
  22.   (defmacro eval-it (form &environment env)
  23.     `(function-eval-it ',form ',env))
  24.  
  25.    ... Meanwhile, in another lexical environment...
  26.  
  27.   (defun function-eval-it (form &rest env)
  28.     (evalhook form nil nil env))
  29.  
  30.   (setf x 40)
  31.   (let ((x 10))
  32.     (eval-it (print x)))
  33.  
  34.    10
  35.    => 10
  36.  
  37. As I said, this seems to do the right thing, but, I am wondering
  38. if there is a more elegant way to do this, such as a better way to
  39. evaluate the form, rather than EVALHOOK.  Am I using EVALHOOK properly?
  40.  
  41. Thanks in advance,
  42.  
  43. **************************************************************************
  44. * Christopher Thomas             * What do you mean, an African swallow, *
  45. * Univ. of WA Computer Science   *    or a European swallow?             *
  46. * cthomas@cs.washington.edu      *       - King Arthur                   *
  47. **************************************************************************
  48.  
  49.  
  50. -- 
  51. **************************************************************************
  52. * Christopher Thomas             * What do you mean, an African swallow, *
  53. * Univ. of WA Computer Science   *    or a European swallow?             *
  54. * cthomas@cs.washington.edu      *       - King Arthur                   *
  55.