Fork me on GitHub

Hey team, would love your opinion on something: I’m writing a lisp interpreter, which eventually will run PG’s Bel. Right now, I’m trying to support continuations. To make things simple, my eval was recursive, and to support continuations, I used callbacks. (bel-eval env form done-f) But, since supporting continuations, I found that this has quickly led to stack overflow. Curious, how would you tackle it? Am currently thinking of representing my own stack, so bel-eval would no longer be recursive: it would work on top of a stack, that I pass around and update as needed.

(let [stack (atom [x])] 
   ;; take first element, 
   ;; based on work, pass `stack` to other functions
   ;; other functions can add to the stack 
If I go this approach though, am already worried that it’s going to get complicated, and I’m going to need some custom “breakpoints”, to get back to the right places in the code. Is there another way you’d approach it?


Hah, you know what, can just try to increase the stack size for now 😅. Still open for new ideas though!

Ben Sless13:08:17

@stopachka you have a couple of option: a. reify the stack. Look at malli's regex schema for an example b. Just target project loom which has continuations