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

  1. Path: sparky!uunet!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Evaluating in given environment?
  5. Date: 23 Nov 1992 03:49:15 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 29
  8. Distribution: usa
  9. Message-ID: <1epkbrINN1g8@early-bird.think.com>
  10. References: <1992Nov23.025931.27024@beaver.cs.washington.edu>
  11. NNTP-Posting-Host: gandalf.think.com
  12.  
  13. In article <1992Nov23.025931.27024@beaver.cs.washington.edu> cthomas@cs.washington.edu (Christopher Thomas) writes:
  14. >Problem: I have a macro that takes a form as an argument, and the expansion
  15. >passes that form to a function.  I want the function to evaluate the form,
  16. >but in the lexical environment of the macro expansion.  
  17.  
  18. You should package it up into a lambda expression, and use the FUNCTION
  19. special form to capture the lexical environment.
  20.  
  21. >  (defmacro eval-it (form &environment env)
  22. >    `(function-eval-it ',form ',env))
  23.  
  24. (defmacro eval-it (form)
  25.   `(function-eval-it #'(lambda () (progn ,form))))
  26.  
  27. (defun function-eval-it (funarg)
  28.   (funcall funarg))
  29.  
  30. >  (defun function-eval-it (form &rest env)
  31. >    (evalhook form nil nil env))
  32.  
  33. FYI, that should be "&optional env", shouldn't it?  That isn't even
  34. guaranteed to work for your purposes, since &environment only captures the
  35. macro environment, not the full lexical environment (e.g. variable bindings
  36. aren't necessarily there).
  37. -- 
  38. Barry Margolin
  39. System Manager, Thinking Machines Corp.
  40.  
  41. barmar@think.com          {uunet,harvard}!think!barmar
  42.