Can hash-tables be used as continuations in scheme?

4 points by naughtysriram ↗ HN
I am new to scheme/lisp/functional programming. I wrote a small scheme interpreter in C for the know-how of scheme internals. I was wondering whether hash-tables can be used for continuations as continuations mostly contain a key/value pairs. Also as they are not directly manipulated by the code and only accessed during the eval phase (please correct me if I am wrong).

2 comments

[ 4.0 ms ] story [ 13.5 ms ] thread
In theory, yes. In practice, they're often too slow if you care about such things.

The continuation pretty much contains the stack at the point it's captured, plus registers and the current instruction pointer. If you're in an interpreter, basically just the current environment and a pointer to the node being evaluated. You can represent the environment as a linked list of activation records, and each activation record as a hash-table mapping symbols to values.

In fact, it's probably faster than a SICP-style toy scheme interpreter that stores the environment as an association-list. It's just that neither comes close to a C-style runtime where the stack is just a contiguous block of memory and local variables are precomputed into memory offsets from the stack pointer.

Yes, nothing can come close to the C-style stack. What I thought was to maintain a stack or a hash-table of pointers to all the continuations (key/value implemented as pairs a.k.a cons cells) right from the root environment to the latest active environment, so i can kind of implement a push-pop for environments aka 'stack frame' i guess. In the eval phase I can have another function call-with-foreign-continuation where I provide a function and a target continuation to bind that with. Its like hijacking another functions continuation directly.