Delimited continuations in lone lisp
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.
... continue reading