[plt-scheme] Getting all bound identifiers

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun May 20 20:24:21 EDT 2007

At Mon, 21 May 2007 00:26:14 +0200, Jakub Piotr Cłapa wrote:
> Is it possible to get a list of all currently (in terms of the current 
> scope) bound identifiers?

Not in general.

> I think it should be possible in a macro

You could do it if you have a macro on the outside that cooperates with
one on the inside:

 (start-remembering-bound-identifiers
   ... (current-bound-identifiers) ...)

The `start-remembering-bound-variables' macro would have to force
expansion of its body via `local-expand', leaving
`(current-bound-identifiers)' intact. It could then traverse the
result, and wrap it with something (maybe a `syntax-parameterize') to
communicate the discovered bindings to `(current-bound-identifiers)'.

This strategy can fail if a `current-bound-identifiers' expression has
any sub-expressions. Expanding via `local-expand' always works if you
stop at primitive expression forms or if you fully expand all
expressions, but partial expansion of expressions via `local-expand'
(e.g., expanding through to `current-bound-identifiers' but not to its
sub-expressions) runs into trouble with internal-definition forms and
local syntax bindings.

Matthew



Posted on the users mailing list.