lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hash: SHA1

Mark Hamburg wrote:
> Really. Scheme will keep the dynamic chain around as long as the
> continuation exists and you can return up the chain again. It's interesting
> for implementing things like backtracking. Or think of it as setjmp/longjmp
> taken to its logical conclusion.

So let's consider my original example, where the closure is an event handler.

Doesn't this mean that when the closure returns, it'll abandon the dynamic
chain containing the event loop and replace it with a clone of the dynamic
chain that called the setup code? Which means you end up with no event loop?
Of course, for this situation to occur at all, then the returning setup code
must eventually arrive at a call to the event loop, which means that the
cloned dynamic chain will arrive at the same call, and... I think my head hurts!

(Are there any Googleable terms where I can go and read up on this? I did try
various keywords earlier, but the results were awfully fuzzy.)

I think you could probably implement this in Lua, but it would have to be a
layer on top of the existing language, where all calls and returns happened
using tail calls (thanks to Bret Victor for demonstrating that these are
equivalent to gotos).

function aRoutine(dchain, params...)
	local l1, l2, l3 -- so they become visible to all subclocks
	local f1 = function(dchain)
		-- basic block 1; calls utilityFunc and returns to f2
		return utilityFunc({next=dchain, fn=f2})
	local f2 = function(dchain)
		-- basic block 2; returns from aRoutine
		return dchain.fn(
	-- starts execution by jumping to f1
	return f1(dchain)

function utilityFunc(dchain)
	-- just returns immediately
	return dchain.dn(

Ouch. (And probably containing fundamental conceptual errors.) But a compiler
stage could generate it easily.

Hmm. Cross-reference to Stackless Python.

- --
┌── ─── ───────────────────
│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla -