3 ms·
I've been working on something similar for the last few years. It's a neat idea that has some interesting properties: a code block is a triple: code, value and
by sambeau 15y ago
I've been working on something similar for the last few years. It's a neat idea that has some interesting properties: a code block is a triple: code, value and map (and quite possibly a closure so that it can be repeatedly re-evaluated). You can easily build complex iterative lazy structures as well as all the ordinary things like for-loops, function calls etc using the same basic structures.
It's a similar idea, in many ways, to the way Javascript does objects: run some code get a map back. Where it gets interesting is that you can choose to use the evaluated value and the scope that was generated in evaluating it. Objects, maps, code, scope, closures and lazy evaluation become the same thing: you declare a block of code, you evaluate it into a closure (with scope and a stack) you query it for results, rinse-repeat.
A for-loop becomes a function that takes two blocks: one that lazily generates values in and one that lazily consumes them. It is the two closures that remember their state - not the for-loop function. The 'for-function' just passes the current value to the second block to use it.
Javascript, REBOL and Lua do have these capabilities but none have the elegance (nor simplicity) of Lisp. I'd love to see a language that does.