Dynamic scope & lexical scope — how?
So I started a new branch (which will be on Github pretty soon); on this new version all the interpreter is implemented in “continuation-returning-style”, if I may say so—instead of calling another function, or returning a value, each expression returns a function that knows what to do next. The evaluation means to call a function, and the returned function, and the function returned from the returned function, until the cows come home. (trampoline-style)
This incidentally gave me call/cc “for free”, which is nice (I already gave up my dreams of implementing a subset of Common Lisp, so I'll implement a superset instead :-p). However dynamic variables turn out to be quite a hassle now. I don't have the luxury of using the exceptions of the underlying language, because the stack is cleared after each expression evaluates. Somehow I need to catch the moment when a scope exits, in order to restore the dynamic variables that it modified, but I'm not quite sure how—and the problem is exaggerated by having continuations... Grr, I'll think of it some more this weekend.
Update: this is it:
Still no dynamic scope.