[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Features you would like to see
- From: David Given <dg@...>
- Date: Wed, 22 Aug 2007 01:21:32 +0100
-----BEGIN PGP SIGNED MESSAGE-----
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})
end
local f2 = function(dchain)
-- basic block 2; returns from aRoutine
return dchain.fn(dchain.next)
end
-- starts execution by jumping to f1
return f1(dchain)
end
function utilityFunc(dchain)
-- just returns immediately
return dchain.dn(dchain.next)
end
Ouch. (And probably containing fundamental conceptual errors.) But a compiler
stage could generate it easily.
Hmm. Cross-reference to Stackless Python.
- --
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│
│ "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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGy4GMf9E0noFvlzgRAm/2AKDNx1haTStgL2GPTCZ2RWYXekXgmgCgu9fx
XXY3gJHfVxvRRO5eMcCQCXU=
=FPJK
-----END PGP SIGNATURE-----