mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 14:58:50 +00:00
25 lines
No EOL
470 B
Text
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 ()
|
|
} |