mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-07 15:28:49 +00:00
19 lines
266 B
Text
19 lines
266 B
Text
|
|
fun makeLazy (f) {
|
||
|
|
var flag = [0], value = [0];
|
||
|
|
|
||
|
|
fun () {
|
||
|
|
if flag[0]
|
||
|
|
then value[0]
|
||
|
|
else
|
||
|
|
value[0] := f ();
|
||
|
|
flag[0] := 1;
|
||
|
|
value[0]
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
val l = makeLazy (fun () {write (1); 800});
|
||
|
|
val x = read ();
|
||
|
|
|
||
|
|
write (l ());
|
||
|
|
write (l ())
|