diff options
author | Eduardo Julian | 2020-11-05 02:31:55 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-11-05 02:31:55 -0400 |
commit | 11cc4a67001162d689eb827f755424a07b99fccb (patch) | |
tree | a689186bf0bef21056a3ad13e8f06f313a3a6989 /stdlib/source/spec | |
parent | 8ac980fd3b6d2050edc0e631a00028c1e6c28c73 (diff) |
Lightweight machinery for agent-oriented programming.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/spec/lux/world/console.lux | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/stdlib/source/spec/lux/world/console.lux b/stdlib/source/spec/lux/world/console.lux new file mode 100644 index 000000000..b9e1c0720 --- /dev/null +++ b/stdlib/source/spec/lux/world/console.lux @@ -0,0 +1,49 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)]] + [control + ["." try] + [security + ["!" capability]] + [concurrency + ["." promise (#+ Promise)]]] + [math + ["." random]]] + {1 + ["." /]}) + +(def: #export (spec console) + (-> (/.Console Promise) Test) + (<| (_.with-cover [/.Console]) + (do {! random.monad} + [message (random.ascii/alpha 10)] + (wrap (do promise.monad + [?read (!.use (:: console read) []) + ?read-line (!.use (:: console read-line) []) + ?write (!.use (:: console write) [message]) + ?close/good (!.use (:: console close) []) + ?close/bad (!.use (:: console close) [])] + ($_ _.and' + (_.claim [/.Can-Read] + (case [?read ?read-line] + [(#try.Success _) (#try.Success _)] + true + + _ + false)) + (_.claim [/.Can-Write] + (case ?write + (#try.Success _) + true + + _ + false)) + (_.claim [/.Can-Close] + (case [?close/good ?close/bad] + [(#try.Success _) (#try.Failure _)] + true + + _ + false)))))))) |