[Openmcl-devel] accessing lexical variables (lexical-environment vs definition-environment)

Gary Byers gb at clozure.com
Tue Jul 19 18:17:51 UTC 2005



On Tue, 19 Jul 2005, Marco Baringer wrote:

>
> i need a function which, at macro expansion time, collects the names
> (as symbols) of all the visibile lexical variables. is there anything
> which looks blatently wrong with this?
>
> (defun lexical-variables (environment)
>  (loop
>     for env = environment
>          then (ccl::lexenv.parent-env env)
>     while (and env
>                (not (ccl::istruct-typep env 'ccl::definition-environment)))
>     for vars = (ccl::lexenv.variables env)
>     when (listp vars)
>     append (mapcar (lambda (var)
>                      ;; ccl::var-name is a macro, se we can't do #'ccl::var-name directly
>                      (ccl::var-name var))
>                    vars)))
>
> in particular i want to make sure that i can stop looking for
> variables as soon as i hit a definition-environment object.
>
> tia.

The "definition environment" roughly corresponds to "things defined during
COMPILE-FILE"; it may not be there (as the oldest ancestor of some lexical
environment), but if it is there, there's nothing older in the chain.  (I.e,
the terminating condition of your loop above looks correct.)

I think that the CCL::LEXENV.VARIABLES slot of a CCL::LEXICAL-ENVIRONMENT
can contain information about "things in the variable namespace" (i.e.,
SYMBOL-MACROs) as well as actual (traditional) variable bindings.



More information about the Openmcl-devel mailing list