[plt-scheme] determine free variables

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Mar 24 20:01:52 EDT 2008

YC wrote:
> Hi all -
> What's the best approach to determine free variables at source level?
> What i am trying to accomplish is to take a scheme expression from a 
> file, say
> (+ foo bar)
> and transform
> (lambda (foo bar)
>   (+ foo bar))
> for arbitrary scheme expressions. 
> Are there procedures that would allow me to determine whether a symbol 
> has a binding?  Given scheme identifier can be bound to different 
> values, it seems like this would require some sort of runtime 
> environment inspection - is that true?
> Thanks,
> yc

It depends on whether you know this Scheme expression is at top level 
(or, in a known environment), or it lives in some dynamic environment. 
In the former case, you can just treat the expression as a S-exp and 
write a procedure that traverse the expression to find out free 
variables(tip: this procedure will look like a "eval" as every Schemer 
learned). Hope this helps.


Posted on the users mailing list.