mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Cosmetics in stdlib
This commit is contained in:
parent
7fd85f27ef
commit
5933f4c3b1
15 changed files with 105 additions and 79 deletions
|
|
@ -1,10 +1,21 @@
|
|||
-- 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 set := true; value := f (); 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue