diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test/lux/function/cont.lux | 30 |
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)))))) )) |