Thunk blocks
Closed this issue · 5 comments
These are handy. We would like to implement them.
I'm sorry, this is ambiguous.
If you mean Thunk like scheme, you have lambdas and thus you have thunk blocks.
If you mean Thunk like Intel Architecture, then I am confused.
If you mean Thunk like React/Redux, then I misunderstand the scope.
Could you elaborate?
Yes like in scheme -- as nice syntactic sugar for lambdas. Maybe something like
lazy[x + 10];
or
(| x + 10 |)
But this would mean that the language would hide when it is computed.
If you want this, then it is no big deal to hide empty brackets as well as in Scala when call a function without arguments.
With that you have:
function a():Int {return x+10;} // or
var b = fn(): Int => { return x+10; };
var c = a;
Together memoization or macros you could make this more concise and performant, if you wish.
(Using C++ syntax)
#define lazy(expression) \
fn() => {return expression;}
var b = lazy(x+10);
var c = b
Maybe something like delay
and force
could be borrowed from scheme?
delay
returns a promise to perform a computation, and force
resolves that promise.
The neat thing with this is that delay
caches the resolved promise, so calling force
on an already resolved promise value just returns the cached value.
Closing this as it may interfere with other techniques we are planning to try out.