From 11cc4a67001162d689eb827f755424a07b99fccb Mon Sep 17 00:00:00 2001
From: Eduardo Julian
Date: Thu, 5 Nov 2020 02:31:55 -0400
Subject: Lightweight machinery for agent-oriented programming.

---
 stdlib/source/spec/lux/world/console.lux | 49 ++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 stdlib/source/spec/lux/world/console.lux

(limited to 'stdlib/source/spec')

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))))))))
-- 
cgit v1.2.3