[plt-scheme] Lazy evaluation and tail calls
On Jan 18, James Coglan wrote:
>
> I've managed to rig together a system whereby, when a new promise is
> formed, it inspects the symbols it contains to find out if they
> point to other promises. That way a tree of dependencies/dependents
> is built up. When you force a promise, I iteratively flatten the
> dependency tree and use that to eval the promises in the same order
> as you'd get in eager mode. Each promise sends its value to those
> that depend on it, allowing you to invert the call order and keep
> the stack flat.
>
> Unfortunately, while this runs with a flat stack, it's extremely
> slow and probably eats memory as I need two-way references between
> lots of promises. Still, I'm only using lazy mode for lambda
> calculus right now, not sliging lots of data around with it so maybe
> this optimisation isn't worth it.
You *should* definitely look into what scheme/promise is doing.
Here's a link to make it easier:
http://svn.plt-scheme.org/plt/trunk/collects/scheme/promise.ss
It's the `force' and `force-proc' functions near the end.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!