Thursday, 15 November 2012

Discontinuous Existence

I had to laugh when I read about the discontinuous state of variables with fluid-let (on account of re-usable continuations).

It related nicely to the discontinuous existence of the planet earth as revealed in the extended trilogy, that wholly remarkable book, the Hitchhikers Guide to the Galaxy.

You can read about the discontinuities introduced with fluid-let and continuations here: http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Dynamic-Binding.html but you should remember those largely friendly letters on the front of the other book: Don't Panic

I quote the key phrases here:
The extent of a dynamic binding is defined to be the time period during which the variable contains the new value. Normally this time period begins when the body is entered and ends when it is exited; on a sequential machine it is normally a contiguous time period. However, because Scheme has first-class continuations, it is possible to leave the body and then reenter it, as many times as desired. In this situation, the extent becomes non-contiguous. 
When the body is exited by invoking a continuation, the new value is saved, and the variable is set to the old value. Then, if the body is reentered by invoking a continuation, the old value is saved, and the variable is set to the new value. In addition, side effects to the variable that occur both inside and outside of body are preserved, even if continuations are used to jump in and out of body repeatedly.
I'm going to have fun with fluid-let but I just wonder about the hackiness that went into implementing that, and is (I suspect) related to dynamic-unwind.

No comments:

Post a Comment