aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2017-04-08 19:51:06 -0400
committerEduardo Julian2017-04-08 19:51:06 -0400
commit2b551329f9f622bfa3e2c0cbf4d223bcfa8496f7 (patch)
tree6f9115b6909b60aee9ab748019a7bd259954ce21 /stdlib/test
parent5cc044086c0e7332bf8b5c2adb98d3419c675aec (diff)
- Improved the implementation of continuations.
Diffstat (limited to '')
-rw-r--r--stdlib/test/test/lux/function/cont.lux30
1 files changed, 22 insertions, 8 deletions
diff --git a/stdlib/test/test/lux/function/cont.lux b/stdlib/test/test/lux/function/cont.lux
index c2e36a06b..97058c22f 100644
--- a/stdlib/test/test/lux/function/cont.lux
+++ b/stdlib/test/test/lux/function/cont.lux
@@ -15,10 +15,10 @@
#let [(^open "&/") &;Monad<Cont>]]
($_ seq
(assert "Can run continuations to compute their values."
- (n.= sample (&;run (&;@lazy sample))))
+ (n.= sample (&;run (&/wrap sample))))
(assert "Can use functor."
- (n.= (n.inc sample) (&;run (&/map n.inc (&;@lazy sample)))))
+ (n.= (n.inc sample) (&;run (&/map n.inc (&/wrap sample)))))
(assert "Can use applicative."
(n.= (n.inc sample) (&;run (&/apply (&/wrap n.inc) (&/wrap sample)))))
@@ -29,10 +29,24 @@
arg (wrap sample)]
(wrap (func arg))))))
- ## (assert "Can access current continuation."
- ## (n.= (n.dec sample) (&;run (do &;Monad<Cont>
- ## [func (wrap n.inc)
- ## _ (&;call/cc (lambda [k] (k (n.dec sample))))
- ## arg (wrap sample)]
- ## (wrap (func arg))))))
+ (assert "Can use the current-continuation as a escape hatch."
+ (n.= (n.* +2 sample)
+ (&;run (do &;Monad<Cont>
+ [value (&;call/cc
+ (lambda [k]
+ (do @
+ [temp (k sample)]
+ ## If this code where to run,
+ ## the output would be
+ ## (n.* +4 sample)
+ (k temp))))]
+ (wrap (n.* +2 value))))))
+
+ (assert "Can use the current-continuation to build a time machine."
+ (n.= (n.+ +100 sample)
+ (&;run (do &;Monad<Cont>
+ [[restart [output idx]] (&;portal [sample +0])]
+ (if (n.< +10 idx)
+ (restart [(n.+ +10 output) (n.inc idx)])
+ (wrap output))))))
))