I would like to try out lazy expression evaluation, but I do not want to dive into Haskel right now. Please, can you help to find what other languages have this feature?
You could simulate it in many languages. this is a generic lazy evaluator for C++, for example. As the article says, its also supported by .NET languages (Thats what the article is trying to emulate).
C++ expression templates are other form of lazy evaluation, for example.
Python's generators are lazy.
Any dataflow language is lazy.
There's also Lazy Racket. Racket is a Scheme derivative.
SWI Prolog has freeze
predicate, which suspends evaluation on a logical variable until it is needed, making possible e.g. this:
fibs(X):- X = [0,1|Z], genfibs(X, Z).
genfibs([A|Y], Z):- Y = [B|Z], freeze(Z, (C is A+B, Z = [C|W], genfibs(Y, W))).
Testing:
13 ?- fibs(X), length(A,15), append(A,_,X), writeln(A).
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
freeze(_G2517, (_G2582 is 233+377, _G2517=[_G2582|_G2595], genfibs([377|_G2517], _G2595))).
This is a translation of Haskell's
fibs = x where x = 0 : 1 : (gen x)
gen (a: y@(b:_)) = (a+b) : (gen y)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With