kputnam/bee — Issue #5: interactive development
Author: kputnam
Created: 2012-01-05 08:00:11+00:00
State: open
Labels: feature

Implementing some functions can be a puzzle where its difficult to think left-to-right. In cases where you know some parts of the definition and need to experiment before filling in the rest, being able to invoke the REPL at runtime would be a novel feature.

For a simple example, in defining `length`, we know we're going to use `fold` and the empty list will have length 0, but maybe we can't remember which arguments are given to the non-empty case. We could write something like `0 [ repl ] fold` which would execute until evaluating `repl`.

This term would break execution, spawn a temporary REPL initialized with a copy of the current stack, and allow substituting the current `repl` for an arbitrary list of terms. You could reset the REPL to its initial state, use the type-checker to ensure your replacement terms are valid, etc. So in the example above, `null 3 cons 2 cons 1 cons 0 [ repl ] fold` would break with `(2 3) 1 0` on the stack and we could figure out we should pop the second element `1` and add one to the top: `[ pop ] dip 1 +`.