[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
re: Issue SYNTACTIC-ENVIRONMENT-ACCESS
- To: Rob.MacLachlan@WB1.CS.CMU.EDU
- Subject: re: Issue SYNTACTIC-ENVIRONMENT-ACCESS
- From: Kim A. Barrett <IIM@ECLA.USC.EDU>
- Date: Thu 23 Feb 89 21:35:11-PST
- Cc: cl-compiler@SAIL.STANFORD.EDU, iim@ECLA.USC.EDU
I think you may be missing the point of AUGMENT-ENVIRONMENT. First, it can't
possibly introduce retroactive local bindings. It does not side-effect the
environment argument, it returns a new environment which contains everything
in the environment argument, plus the stuff specified by the keyword arguments.
Perhaps an example (as you requested) might help.
I can't think of any really simple examples of using augment-environment off
hand. This is a handler for the LET special form from a hypothetical code
walker. I don't guarantee that the semantics implemented by this function
match any particular varient of Common Lisp, though I was thinking in terms of
X3J13 CL. Also, this example is far from self-contained, containing numerous
references to helper functions which are not described here, though hopefully
they shouldn't be too confusing.
(defun walk-let (form env walk-function)
(multiple-value-bind (body decls)
(extract-declarations (cddr form))
(multiple-value-bind (special-decls type ftype)
(parse-declarations decls)
(let ((vars ())
(inits ()))
(dolist (binding (second form))
(cond ((symbolp binding)
(push binding vars)
(push nil inits))
(t
(push (car binding) vars)
(push (walk-form (cadr binding) env walk-function) inits))))
(let ((lexicals ()))
(dolist (var vars)
(or (member var special-decls)
(variable-globally-special-p var env)
(push var lexicals)))
`(let ,(mapcar #'list (nreverse vars) (nreverse inits))
,@decls
,@(let ((new-env (augment-environment env
:lexical lexicals
:special special-decls
:type type
:ftype ftype)))
(mapcar #'(lambda (form)
(walk-form form new-env walk-function))
body))))))))
Note that this example points out a possible misfeature of the current
description of AUGMENT-ENVIRONMENT. Namely, it might be better to simply
specify all the variables being bound, along with a list of local special
declarations, and let augment-environment figure out the split between lexicals
and specials.
I discussed the question of the extent of these things in a recent message
regarding the WITH-COMPILATION-UNIT issue.
kab
-------