From e978beda66408179585fe271bfec1900f21df8b5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 1 May 2018 21:13:08 -0400 Subject: - Re-named lux/control/cont to lux/control/continuation. --- stdlib/test/test/lux/control/cont.lux | 77 --------------------------- stdlib/test/test/lux/control/continuation.lux | 77 +++++++++++++++++++++++++++ stdlib/test/test/lux/data/coll/stream.lux | 3 +- stdlib/test/tests.lux | 2 +- 4 files changed, 79 insertions(+), 80 deletions(-) delete mode 100644 stdlib/test/test/lux/control/cont.lux create mode 100644 stdlib/test/test/lux/control/continuation.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/control/cont.lux b/stdlib/test/test/lux/control/cont.lux deleted file mode 100644 index 7afc84fc2..000000000 --- a/stdlib/test/test/lux/control/cont.lux +++ /dev/null @@ -1,77 +0,0 @@ -(.module: - lux - (lux [io] - (control ["M" monad #+ do Monad] - ["&" cont]) - (data [text "Text/" Monoid] - text/format - [number] - [product] - (coll [list])) - ["r" math/random]) - lux/test) - -(context: "Continuations" - (<| (times +100) - (do @ - [sample r.nat - #let [(^open "&/") &.Monad] - elems (r.list +3 r.nat)] - ($_ seq - (test "Can run continuations to compute their values." - (n/= sample (&.run (&/wrap sample)))) - - (test "Can use functor." - (n/= (n/inc sample) (&.run (&/map n/inc (&/wrap sample))))) - - (test "Can use applicative." - (n/= (n/inc sample) (&.run (&/apply (&/wrap n/inc) (&/wrap sample))))) - - (test "Can use monad." - (n/= (n/inc sample) (&.run (do &.Monad - [func (wrap n/inc) - arg (wrap sample)] - (wrap (func arg)))))) - - (test "Can use the current-continuation as a escape hatch." - (n/= (n/* +2 sample) - (&.run (do &.Monad - [value (&.call/cc - (function (_ k) - (do @ - [temp (k sample)] - ## If this code where to run, - ## the output would be - ## (n/* +4 sample) - (k temp))))] - (wrap (n/* +2 value)))))) - - (test "Can use the current-continuation to build a time machine." - (n/= (n/+ +100 sample) - (&.run (do &.Monad - [[restart [output idx]] (&.portal [sample +0])] - (if (n/< +10 idx) - (restart [(n/+ +10 output) (n/inc idx)]) - (wrap output)))))) - - (test "Can use delimited continuations with shifting." - (let [(^open "&/") &.Monad - (^open "L/") (list.Eq number.Eq) - visit (: (-> (List Nat) - (&.Cont (List Nat) (List Nat))) - (function (visit xs) - (case xs - #.Nil - (&/wrap #.Nil) - - (#.Cons x xs') - (do &.Monad - [output (&.shift (function (_ k) - (do @ - [tail (k xs')] - (wrap (#.Cons x tail)))))] - (visit output)))))] - (L/= elems - (&.run (&.reset (visit elems)))) - )) - )))) diff --git a/stdlib/test/test/lux/control/continuation.lux b/stdlib/test/test/lux/control/continuation.lux new file mode 100644 index 000000000..db274189e --- /dev/null +++ b/stdlib/test/test/lux/control/continuation.lux @@ -0,0 +1,77 @@ +(.module: + lux + (lux [io] + (control ["M" monad #+ do Monad] + ["&" continuation]) + (data [text "Text/" Monoid] + text/format + [number] + [product] + (coll [list])) + ["r" math/random]) + lux/test) + +(context: "Continuations" + (<| (times +100) + (do @ + [sample r.nat + #let [(^open "&/") &.Monad] + elems (r.list +3 r.nat)] + ($_ seq + (test "Can run continuations to compute their values." + (n/= sample (&.run (&/wrap sample)))) + + (test "Can use functor." + (n/= (n/inc sample) (&.run (&/map n/inc (&/wrap sample))))) + + (test "Can use applicative." + (n/= (n/inc sample) (&.run (&/apply (&/wrap n/inc) (&/wrap sample))))) + + (test "Can use monad." + (n/= (n/inc sample) (&.run (do &.Monad + [func (wrap n/inc) + arg (wrap sample)] + (wrap (func arg)))))) + + (test "Can use the current-continuation as a escape hatch." + (n/= (n/* +2 sample) + (&.run (do &.Monad + [value (&.call/cc + (function (_ k) + (do @ + [temp (k sample)] + ## If this code where to run, + ## the output would be + ## (n/* +4 sample) + (k temp))))] + (wrap (n/* +2 value)))))) + + (test "Can use the current-continuation to build a time machine." + (n/= (n/+ +100 sample) + (&.run (do &.Monad + [[restart [output idx]] (&.portal [sample +0])] + (if (n/< +10 idx) + (restart [(n/+ +10 output) (n/inc idx)]) + (wrap output)))))) + + (test "Can use delimited continuations with shifting." + (let [(^open "&/") &.Monad + (^open "L/") (list.Eq number.Eq) + visit (: (-> (List Nat) + (&.Cont (List Nat) (List Nat))) + (function (visit xs) + (case xs + #.Nil + (&/wrap #.Nil) + + (#.Cons x xs') + (do &.Monad + [output (&.shift (function (_ k) + (do @ + [tail (k xs')] + (wrap (#.Cons x tail)))))] + (visit output)))))] + (L/= elems + (&.run (&.reset (visit elems)))) + )) + )))) diff --git a/stdlib/test/test/lux/data/coll/stream.lux b/stdlib/test/test/lux/data/coll/stream.lux index 1fe325782..cbdfcab49 100644 --- a/stdlib/test/test/lux/data/coll/stream.lux +++ b/stdlib/test/test/lux/data/coll/stream.lux @@ -2,8 +2,7 @@ lux (lux [io] (control [monad #+ do Monad] - comonad - [cont]) + comonad) (data [maybe] [text "Text/" Monoid] text/format diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 850abc865..05118f921 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -18,7 +18,7 @@ (control ["_." exception] ["_." interval] ["_." pipe] - ["_." cont] + ["_." continuation] ["_." reader] ["_." writer] ["_." state] -- cgit v1.2.3