home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.lisp
- Subject: Re: Evaluating in given environment?
- Date: 23 Nov 1992 03:49:15 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 29
- Distribution: usa
- Message-ID: <1epkbrINN1g8@early-bird.think.com>
- References: <1992Nov23.025931.27024@beaver.cs.washington.edu>
- NNTP-Posting-Host: gandalf.think.com
-
- In article <1992Nov23.025931.27024@beaver.cs.washington.edu> cthomas@cs.washington.edu (Christopher Thomas) writes:
- >Problem: I have a macro that takes a form as an argument, and the expansion
- >passes that form to a function. I want the function to evaluate the form,
- >but in the lexical environment of the macro expansion.
-
- You should package it up into a lambda expression, and use the FUNCTION
- special form to capture the lexical environment.
-
- > (defmacro eval-it (form &environment env)
- > `(function-eval-it ',form ',env))
-
- (defmacro eval-it (form)
- `(function-eval-it #'(lambda () (progn ,form))))
-
- (defun function-eval-it (funarg)
- (funcall funarg))
-
- > (defun function-eval-it (form &rest env)
- > (evalhook form nil nil env))
-
- FYI, that should be "&optional env", shouldn't it? That isn't even
- guaranteed to work for your purposes, since &environment only captures the
- macro environment, not the full lexical environment (e.g. variable bindings
- aren't necessarily there).
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-