Can hash-tables be used as continuations in scheme?
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 ] threadThe 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.