Abstractly, a continuation is a representation of the state of an execution, and especially its "execution stack" [http://en.wikipedia.org/wiki/Continuation]. There's a delightful article explaining continuations at [http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudgeons]. ''[DKF] 17-Apr-2005:'' Interesting. I just wish it was easy to apply in Tcl, but our openness to extension, especially by C libraries, makes this very tricky indeed. ''[WHD] 17-Apr-2005:'' Damn. I want this. The idea of User Interface Continuations makes me drool. ''[jcw] - Yeah, me too, same reaction. DKF, yes the C stack can cause trouble, but only when C calls back into Tcl. There are probably many cases when this need not be a show stopper. I think there are ways to get there. Might be something to discuss at the tcl2005e conf - are you going to be there?'' ''[NEM] 18-Apr-2005:'' You could sort of get this to work, if we went a similar route to Stackless Python (from what little I know of that project). You'd have to change all the C-API so that instead of re-calling into the interpreter with Tcl_Eval* APIs, they instead return a TCL_CALL or similar code with some code of where to go next in the interpreter result (i.e. [trampoline]). This is very similar to the recent proposals for tail-call optimisation (which is also very connected to continuations, through continuation-passing style, CPS). Obviously, it'd be an enormous amount of work to restructure the core and many many C extensions to do things this way. Continuations rock. (I should be at tcl2005e, and would love to discuss these ideas with people). ''The core is not that far from doing it. At one point I had an experimental patch working, which copied the C stack away and back. Not sure it covered all the cases, but it was definitely very close to full contins across all of Tcl and C. -[jcw]'' ''[WHD]:'' I don't see why the C stack is an issue, based on what the article says. A closure consists of a stack frame and its parent stack frame, and so on recursively, it says; but a continuation, so far as I can tell, is a single stack frame. Suppose we made the rule that you could "yield" only from the body of a normal proc.... '''Oh.''' If you do it from within a while loop, say, you've got the C stack involved. '''Never mind.''' (Or is there something else I'm missing?) ''Will, the stack becomes a tree, because processing (and further nesting) can proceed at any continuation point. Yes, C loops and C re-entering Tcl (as foreach and proc do now when evaluating their bodies) is where things get tricky. -[jcw]'' '''[RHS]''' ''17Apr2005'' One of the most interesting (and informative) descriptions I've seen of the use of continuations was in the area of web programming. The programmers used them to use web pages as if they were stateful. The "process" that the web pages are involved with work linearly. Each time it needs input from the user it saves its current continuation (which contains everything about where it is in the process) in a hashtable. It then returns a web page with a form to the user, and one of the elements of the form (a hidden one, I presume) contains the key into the hash table for the current continuation. Once the user fills in the form and hits submit, the process can look up the continuation in the hash table and continue right where it left off... Only, now, it has the data it needs to continue, as provided by the form. ---- [Category Concept]