Scheme

Started by
2 comments, last by Colin Jeanne 17 years, 11 months ago
I need to modify the interpreter so that the free variables are evaluated at the time the procedure is called, not when it is created. Any hints?
Advertisement
Could you clarify? Unless I'm misunderstanding you, Scheme does that already. Also, what interpreter?
We are "creating" the interpreter, and now it evaluates the free variables when it is created.
This is a difficult question when we dont know how your interpreter is written. When I wrote a Scheme interpreter in Scheme last year each closure had its own environment. There was also a global environment. When I went to evaluate a variable I first searched for it in the most local environment and if it wasnt there then in the environment of the next closest scope.

If you're evaluating a variable in a function which is has global scope then you first try to find it in the function's environment. Since the variable is free, it wont be there. So then you search for it in the global environment.

If you still cant find it then you throw your hands up and tell the user "Undefined variable"

Hope that helps

This topic is closed to new replies.

Advertisement