[racket] metacircular interpreter, lexical scope, environment

From: Hendrik Boom (hendrik at topoi.pooq.com)
Date: Thu Dec 2 09:27:29 EST 2010

On Wed, Dec 01, 2010 at 11:22:49PM -0700, Ryan Culpepper wrote:
> Hendrik Boom wrote:
>>
>> Yes, that's the fast way.  It can be made faster in a compiler, where  
>> you can compile the exact list steps through the chain of frames 
>> instead of looking up names at run-time.
>
> It's easy to "compile away" the name lookup even in an interpreter by  
> having a pre-pass* replace variable references with their "lexical  
> addresses" (see also "rib-cage environment"). That seems to be a very  
> common exercise in interpreter-based PL classes.

Yes.

>
> In fact, lexical variables are so easy to analyze that you can try other  
> representations too. For example, you can annotate every lambda  
> expression with its free lexical variables and create flat closures. But  
> beware of variable mutation in that case!

That's why you haave to have a location somewhere that contains the 
variable's value, and let your closures point to it.

-- hendrik

>
> Ryan
>
> *Arguably, this is a very small, simple compiler.

Yes.  The boundary between compilation and choosing an in-memory 
representation for interpretation is vague.




Posted on the users mailing list.