aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2017-07-29 10:50:20 -0400
committerEduardo Julian2017-07-29 10:50:20 -0400
commit909bc37ba2b96f12eb1eeb0ebed87994a46beb43 (patch)
tree27ed5b34e222429816af29020e27a7e4d759c6d3 /stdlib/source
parente92f7da685b9719f2aea67e4ebe630b98715368f (diff)
- Renamed "Thunk" to "Lazy", and moved it from lux/control/thunk to lux/data/lazy.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/thunk.lux33
-rw-r--r--stdlib/source/lux/data/lazy.lux34
2 files changed, 34 insertions, 33 deletions
diff --git a/stdlib/source/lux/control/thunk.lux b/stdlib/source/lux/control/thunk.lux
deleted file mode 100644
index a78f78023..000000000
--- a/stdlib/source/lux/control/thunk.lux
+++ /dev/null
@@ -1,33 +0,0 @@
-(;module:
- lux
- (lux [io]
- (control monad)
- (concurrency ["A" atom])
- [macro]
- (macro ["s" syntax #+ syntax:])))
-
-(type: #export (Thunk a)
- (-> [] a))
-
-(def: #hidden (freeze' generator)
- (All [a] (-> (-> [] a) (-> [] a)))
- (let [cache (: (A;Atom (Maybe ($ +0)))
- (A;atom #;None))]
- (function [_]
- (case (io;run (A;get cache))
- (#;Some value)
- value
-
- _
- (let [value (generator [])]
- (exec (io;run (A;compare-and-swap _ (#;Some value) cache))
- value))))))
-
-(syntax: #export (freeze expr)
- (do @
- [g!arg (macro;gensym "")]
- (wrap (list (` (freeze' (function [(~ g!arg)] (~ expr))))))))
-
-(def: #export (thaw thunk)
- (All [a] (-> (Thunk a) a))
- (thunk []))
diff --git a/stdlib/source/lux/data/lazy.lux b/stdlib/source/lux/data/lazy.lux
new file mode 100644
index 000000000..1f4566eee
--- /dev/null
+++ b/stdlib/source/lux/data/lazy.lux
@@ -0,0 +1,34 @@
+(;module:
+ lux
+ (lux [io]
+ (control monad)
+ (concurrency ["A" atom])
+ [macro]
+ (macro ["s" syntax #+ syntax:])
+ (type model)))
+
+(model: #export (Lazy a)
+ (-> [] a)
+
+ (def: #hidden (freeze' generator)
+ (All [a] (-> (-> [] a) (Lazy a)))
+ (let [cache (: (A;Atom (Maybe ($ +0)))
+ (A;atom #;None))]
+ (@model (function [_]
+ (case (io;run (A;get cache))
+ (#;Some value)
+ value
+
+ _
+ (let [value (generator [])]
+ (exec (io;run (A;compare-and-swap _ (#;Some value) cache))
+ value)))))))
+
+ (def: #export (thaw l-value)
+ (All [a] (-> (Lazy a) a))
+ ((@repr l-value) [])))
+
+(syntax: #export (freeze expr)
+ (do @
+ [g!_ (macro;gensym "_")]
+ (wrap (list (` (freeze' (function [(~ g!_)] (~ expr))))))))