lama_byterun/stdlib/Lazy.lama
2020-02-20 12:43:52 +03:00

25 lines
No EOL
470 B
Text

-- Lazy.
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
--
-- Deferred computations.
public fun makeLazy (f) {
local value, set = false;
fun () {
if set
then value
else
local c; -- need this temporary since in value := f () value would
-- create an intermediate managed pointer
set := true;
c := f ();
value := c;
c
fi
}
}
public fun force (f) {
f ()
}