Delimited continuations in lone lisp Lone now supports delimited continuations! It took me a long time but it's finally here: lone now supports one of the most powerful control mechanisms there is. (import (lone print lambda control transfer) (math +)) (print (+ 1 (control (+ 98 (transfer 41)) (lambda (value continuation) (continuation 1))))) Implementing this feature will pave the way to many others, such as exception handling and generators. However, before moving on with development, I thought it would be worthwhile to write down the story of this feature's implementation. I want to write the article I wish I had read before I began. If nothing else, this will serve as documentation for the future version of myself whose brain has deleted all this context. Iteration Lone was growing in complexity. I already had all these data types, all of these collections. I was having quite a lot of fun implementing these things. I was learning so much. Hash tables? Powerful stuff. However, there was something I was secretly avoiding: iteration. Well, that's not entirely true. I didn't completely avoid the issue. Inspired by Ruby, I added some each primitives to the intrinsic modules. (import (lone lambda print) (vector each)) (each [10 20 30] (lambda (value) (print value))) The way the each function works internally is it iterates over the contents of the vector and calls the provided function with each element as its sole argument. LONE_LISP_PRIMITIVE(vector_each) { struct lone_lisp_value vector, f, entry; size_t i; LONE_LISP_VECTOR_FOR_EACH(entry, vector, i) { arguments = lone_lisp_list_build(lone, 1, &entry); lone_lisp_apply(lone, module, environment, f, arguments); } return lone_lisp_nil(); } I cheated a little: I left the actual iteration up to the C compiler. That FOR_EACH macro simply evaluates to a good old for loop. The C code iterates on behalf of lone, applying the current element to the provided function. So what is the issue? I mean, this works. This actually wor...
First seen: 2025-10-06 10:05
Last seen: 2025-10-06 19:06