Dynamic variables

Alaric B. Williams alaric@abwillms.demon.co.uk
Fri, 16 May 1997 20:27:21 +0000


> >Note that recently bound dynamic variables are found very fast,
> >they are at the top of the stack.
> 
> If I start talking about dynamic variables, I'll probably be talking
> nonsense, but here goes...
> 
> Can't dynamic variables be implemented efficiently by storing the
> current value in the global place, and pushing the old global value on
> the stack. When the local binding of the variable goes out of scope
> you pop the old value off the stack and replace the global position
> with the original value. Thus lookups are always constant and fast.

There's a problem with parallel threads there...
 
> It's a bit the opposite of what most languages do, by making the
> global storage the local lookup, and pushing the old values on the
> stack, rather than the new ones.
 
Well, I'm toying with the idea of a reified stack as an extension to
continuations. Basically, if a function asks for it's continuation,
it receives a list of call frames, each containing the continuation
of that call, and some optional extra data.

Something like catch/throw would be written by making a call with a special
marker in the stack, which throw looks for and recontinues from there.

Something like dynamic binding would be written by putting alists in
the special markers, and having a (dyna-get '<symbol>) to read them
back.

Many other interesting tricks are also doable with this mechanism...

ABW
--
Alaric B. Williams (alaric@abwillms.demon.co.uk)

   ---<## OpenDOS FAQ ##>---

Plain HTML: http://www.delorie.com/opendos/faq/
            http://www.deltasoft.com/faq.html

Fancy HTML: http://www.deltasoft.com/faq0000.html