From fecfb6c1dd653e491e541233395ea4a7d8ae7409 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 16 Oct 2017 19:28:04 -0400 Subject: - Re-named "Result" type back to "Error". --- stdlib/source/lux/cli.lux | 48 +++---- stdlib/source/lux/concurrency/task.lux | 30 ++-- stdlib/source/lux/control/codec.lux | 6 +- stdlib/source/lux/control/exception.lux | 36 ++--- stdlib/source/lux/control/parser.lux | 92 ++++++------ stdlib/source/lux/data/coll/tree/parser.lux | 18 +-- stdlib/source/lux/data/error.lux | 98 +++++++++++++ stdlib/source/lux/data/format/context.lux | 12 +- stdlib/source/lux/data/format/json.lux | 74 +++++----- stdlib/source/lux/data/format/xml.lux | 26 ++-- stdlib/source/lux/data/number.lux | 74 +++++----- stdlib/source/lux/data/number/complex.lux | 4 +- stdlib/source/lux/data/number/ratio.lux | 6 +- stdlib/source/lux/data/result.lux | 98 ------------- stdlib/source/lux/data/text/lexer.lux | 68 ++++----- stdlib/source/lux/data/text/regex.lux | 40 +++--- stdlib/source/lux/macro.lux | 102 +++++++------- stdlib/source/lux/macro/poly.lux | 54 +++---- stdlib/source/lux/macro/poly/json.lux | 6 +- stdlib/source/lux/macro/syntax.lux | 74 +++++----- stdlib/source/lux/test.lux | 24 ++-- stdlib/source/lux/time/date.lux | 4 +- stdlib/source/lux/time/duration.lux | 4 +- stdlib/source/lux/time/instant.lux | 4 +- stdlib/source/lux/type/check.lux | 164 +++++++++++----------- stdlib/source/lux/type/opaque.lux | 6 +- stdlib/source/lux/world/blob.jvm.lux | 40 +++--- stdlib/source/lux/world/file.lux | 12 +- stdlib/source/lux/world/net/tcp.jvm.lux | 22 +-- stdlib/source/lux/world/net/udp.jvm.lux | 16 +-- stdlib/test/test/lux.lux | 44 +++--- stdlib/test/test/lux/cli.lux | 8 +- stdlib/test/test/lux/concurrency/actor.lux | 6 +- stdlib/test/test/lux/concurrency/atom.lux | 8 +- stdlib/test/test/lux/concurrency/promise.lux | 2 +- stdlib/test/test/lux/concurrency/stm.lux | 2 +- stdlib/test/test/lux/control/cont.lux | 6 +- stdlib/test/test/lux/control/exception.lux | 20 +-- stdlib/test/test/lux/control/interval.lux | 34 ++--- stdlib/test/test/lux/control/parser.lux | 18 +-- stdlib/test/test/lux/control/pipe.lux | 2 +- stdlib/test/test/lux/control/state.lux | 18 +-- stdlib/test/test/lux/data/bit.lux | 6 +- stdlib/test/test/lux/data/bool.lux | 4 +- stdlib/test/test/lux/data/coll/array.lux | 26 ++-- stdlib/test/test/lux/data/coll/list.lux | 32 ++--- stdlib/test/test/lux/data/coll/priority-queue.lux | 16 +-- stdlib/test/test/lux/data/coll/queue.lux | 10 +- stdlib/test/test/lux/data/coll/seq.lux | 24 ++-- stdlib/test/test/lux/data/coll/set.lux | 14 +- stdlib/test/test/lux/data/coll/stack.lux | 10 +- stdlib/test/test/lux/data/coll/stream.lux | 14 +- stdlib/test/test/lux/data/coll/vector.lux | 12 +- stdlib/test/test/lux/data/error.lux | 56 ++++++++ stdlib/test/test/lux/data/format/json.lux | 6 +- stdlib/test/test/lux/data/format/xml.lux | 18 +-- stdlib/test/test/lux/data/ident.lux | 14 +- stdlib/test/test/lux/data/number.lux | 108 +++++++------- stdlib/test/test/lux/data/number/complex.lux | 16 +-- stdlib/test/test/lux/data/number/ratio.lux | 14 +- stdlib/test/test/lux/data/result.lux | 56 -------- stdlib/test/test/lux/data/text/lexer.lux | 24 ++-- stdlib/test/test/lux/host.js.lux | 2 +- stdlib/test/test/lux/macro/code.lux | 2 +- stdlib/test/test/lux/macro/syntax.lux | 6 +- stdlib/test/test/lux/math/logic/continuous.lux | 6 +- stdlib/test/test/lux/math/logic/fuzzy.lux | 36 ++--- stdlib/test/test/lux/time/date.lux | 6 +- stdlib/test/test/lux/time/duration.lux | 6 +- stdlib/test/test/lux/time/instant.lux | 6 +- stdlib/test/test/lux/type.lux | 56 ++++---- stdlib/test/test/lux/type/auto.lux | 6 +- stdlib/test/test/lux/world/blob.lux | 28 ++-- stdlib/test/test/lux/world/file.lux | 26 ++-- stdlib/test/test/lux/world/net/tcp.lux | 4 +- stdlib/test/test/lux/world/net/udp.lux | 4 +- stdlib/test/tests.lux | 2 +- 77 files changed, 1053 insertions(+), 1053 deletions(-) create mode 100644 stdlib/source/lux/data/error.lux delete mode 100644 stdlib/source/lux/data/result.lux create mode 100644 stdlib/test/test/lux/data/error.lux delete mode 100644 stdlib/test/test/lux/data/result.lux diff --git a/stdlib/source/lux/cli.lux b/stdlib/source/lux/cli.lux index ba0689e89..ef8b05e41 100644 --- a/stdlib/source/lux/cli.lux +++ b/stdlib/source/lux/cli.lux @@ -5,7 +5,7 @@ (data (coll [list "L/" Monoid Monad]) [text "T/" Monoid] text/format - ["R" result] + ["E" error] [sum]) [io] [macro #+ with-gensyms Functor Monad] @@ -19,18 +19,18 @@ ## [Combinators] (def: #export (run inputs parser) - (All [a] (-> (List Text) (CLI a) (R;Result a))) + (All [a] (-> (List Text) (CLI a) (E;Error a))) (case (p;run inputs parser) - (#R;Success [remaining output]) + (#E;Success [remaining output]) (case remaining #;Nil - (#R;Success output) + (#E;Success output) _ - (#R;Error (format "Remaining CLI inputs: " (text;join-with " " remaining)))) + (#E;Error (format "Remaining CLI inputs: " (text;join-with " " remaining)))) - (#R;Error error) - (#R;Error error))) + (#E;Error error) + (#E;Error error))) (def: #export any {#;doc "Just returns the next input without applying any logic."} @@ -38,26 +38,26 @@ (function [inputs] (case inputs (#;Cons arg inputs') - (#R;Success [inputs' arg]) + (#E;Success [inputs' arg]) _ - (#R;Error "Cannot parse empty arguments.")))) + (#E;Error "Cannot parse empty arguments.")))) (def: #export (parse parser) {#;doc "Parses the next input with a parsing function."} - (All [a] (-> (-> Text (R;Result a)) (CLI a))) + (All [a] (-> (-> Text (E;Error a)) (CLI a))) (function [inputs] (case inputs (#;Cons arg inputs') (case (parser arg) - (#R;Success value) - (#R;Success [inputs' value]) + (#E;Success value) + (#E;Success [inputs' value]) - (#R;Error parser-error) - (#R;Error parser-error)) + (#E;Error parser-error) + (#E;Error parser-error)) _ - (#R;Error "Cannot parse empty arguments.")))) + (#E;Error "Cannot parse empty arguments.")))) (def: #export (option names) {#;doc "Checks that a given option (with multiple possible names) has a value."} @@ -66,13 +66,13 @@ (let [[pre post] (list;split-with (. ;not (list;member? text;Eq names)) inputs)] (case post #;Nil - (#R;Error ($_ T/compose "Missing option (" (text;join-with " " names) ")")) + (#E;Error ($_ T/compose "Missing option (" (text;join-with " " names) ")")) (^ (list& _ value post')) - (#R;Success [(L/compose pre post') value]) + (#E;Success [(L/compose pre post') value]) _ - (#R;Error ($_ T/compose "Option lacks value (" (text;join-with " " names) ")")) + (#E;Error ($_ T/compose "Option lacks value (" (text;join-with " " names) ")")) )))) (def: #export (flag names) @@ -82,18 +82,18 @@ (let [[pre post] (list;split-with (. ;not (list;member? text;Eq names)) inputs)] (case post #;Nil - (#R;Success [pre false]) + (#E;Success [pre false]) (#;Cons _ post') - (#R;Success [(L/compose pre post') true]))))) + (#E;Success [(L/compose pre post') true]))))) (def: #export end {#;doc "Ensures there are no more inputs."} (CLI Unit) (function [inputs] (case inputs - #;Nil (#R;Success [inputs []]) - _ (#R;Error (T/compose "Unknown parameters: " (text;join-with " " inputs)))))) + #;Nil (#E;Success [inputs []]) + _ (#E;Error (T/compose "Unknown parameters: " (text;join-with " " inputs)))))) ## [Syntax] (type: Program-Args @@ -145,10 +145,10 @@ [] (~ body))))) (~ g!args)) - (#R;Success [(~ g!_) (~ g!output)]) + (#E;Success [(~ g!_) (~ g!output)]) (~ g!output) - (#R;Error (~ g!message)) + (#E;Error (~ g!message)) (error! (~ g!message)) ))) ))) diff --git a/stdlib/source/lux/concurrency/task.lux b/stdlib/source/lux/concurrency/task.lux index 4be7ead9d..374acee46 100644 --- a/stdlib/source/lux/concurrency/task.lux +++ b/stdlib/source/lux/concurrency/task.lux @@ -1,6 +1,6 @@ (;module: lux - (lux (data ["R" result]) + (lux (data ["E" error]) (control ["F" functor] ["A" applicative] monad @@ -11,11 +11,11 @@ )) (type: #export (Task a) - (P;Promise (R;Result a))) + (P;Promise (E;Error a))) (def: #export (fail error) (All [a] (-> Text (Task a))) - (:: P;Applicative wrap (#R;Error error))) + (:: P;Applicative wrap (#E;Error error))) (def: #export (throw exception message) (All [a] (-> Exception Text (Task a))) @@ -23,22 +23,22 @@ (def: #export (return value) (All [a] (-> a (Task a))) - (:: P;Applicative wrap (#R;Success value))) + (:: P;Applicative wrap (#E;Success value))) (def: #export (try computation) - (All [a] (-> (Task a) (Task (R;Result a)))) - (:: P;Functor map (|>. #R;Success) computation)) + (All [a] (-> (Task a) (Task (E;Error a)))) + (:: P;Functor map (|>. #E;Success) computation)) (struct: #export _ (F;Functor Task) (def: (map f fa) (:: P;Functor map (function [fa'] (case fa' - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success a) - (#R;Success (f a)))) + (#E;Success a) + (#E;Success (f a)))) fa))) (struct: #export _ (A;Applicative Task) @@ -50,7 +50,7 @@ (do P;Monad [ff' ff fa' fa] - (wrap (do R;Monad + (wrap (do E;Monad [f ff' a fa'] (wrap (f a))))))) @@ -62,10 +62,10 @@ (do P;Monad [mma' mma] (case mma' - (#R;Error error) - (wrap (#R;Error error)) + (#E;Error error) + (wrap (#E;Error error)) - (#R;Success ma) + (#E;Success ma) ma)))) (syntax: #export (task [type s;any]) @@ -76,4 +76,4 @@ (def: #export (from-promise promise) (All [a] (-> (P;Promise a) (Task a))) - (:: P;Functor map (|>. #R;Success) promise)) + (:: P;Functor map (|>. #E;Success) promise)) diff --git a/stdlib/source/lux/control/codec.lux b/stdlib/source/lux/control/codec.lux index e11f08016..55095ee3c 100644 --- a/stdlib/source/lux/control/codec.lux +++ b/stdlib/source/lux/control/codec.lux @@ -1,14 +1,14 @@ (;module: lux (lux (control monad) - (data ["R" result]))) + (data ["E" error]))) ## [Signatures] (sig: #export (Codec m a) {#;doc "A way to move back-and-forth between a type and an alternative representation for it."} (: (-> a m) encode) - (: (-> m (R;Result a)) + (: (-> m (E;Error a)) decode)) ## [Values] @@ -22,7 +22,7 @@ (:: Codec encode))) (def: (decode cy) - (do R;Monad + (do E;Monad [by (:: Codec decode cy)] (:: Codec decode by))) ) diff --git a/stdlib/source/lux/control/exception.lux b/stdlib/source/lux/control/exception.lux index fda8103f2..b8be7b70d 100644 --- a/stdlib/source/lux/control/exception.lux +++ b/stdlib/source/lux/control/exception.lux @@ -1,7 +1,7 @@ -(;module: {#;doc "Exception-handling functionality built on top of the Result type."} +(;module: {#;doc "Exception-handling functionality built on top of the Error type."} lux (lux (control monad) - (data ["R" result] + (data ["E" error] [maybe] [text "text/" Monoid]) [macro] @@ -30,41 +30,41 @@ If no exception was detected, or a different one from the one being checked, then pass along the original value."} (All [a] - (-> Exception (-> Text a) (R;Result a) - (R;Result a))) + (-> Exception (-> Text a) (E;Error a) + (E;Error a))) (case try - (#R;Success output) - (#R;Success output) + (#E;Success output) + (#E;Success output) - (#R;Error error) + (#E;Error error) (let [reference (exception "")] (if (text;starts-with? reference error) - (#R;Success (|> error + (#E;Success (|> error (text;clip (text;size reference) (text;size error)) maybe;assume then)) - (#R;Error error))))) + (#E;Error error))))) (def: #export (otherwise to-do try) {#;doc "If no handler could be found to catch the exception, then run a function as a last-resort measure."} (All [a] - (-> (-> Text a) (R;Result a) a)) + (-> (-> Text a) (E;Error a) a)) (case try - (#R;Success output) + (#E;Success output) output - (#R;Error error) + (#E;Error error) (to-do error))) (def: #export (return value) - {#;doc "A way to lift normal values into the result-handling context."} - (All [a] (-> a (R;Result a))) - (#R;Success value)) + {#;doc "A way to lift normal values into the error-handling context."} + (All [a] (-> a (E;Error a))) + (#E;Success value)) (def: #export (throw exception message) - {#;doc "Decorate an error message with an Exception and lift it into the result-handling context."} - (All [a] (-> Exception Text (R;Result a))) - (#R;Error (exception message))) + {#;doc "Decorate an error message with an Exception and lift it into the error-handling context."} + (All [a] (-> Exception Text (E;Error a))) + (#E;Error (exception message))) (syntax: #export (exception: [_ex-lev csr;export] [name s;local-symbol]) {#;doc (doc "Define a new exception type." diff --git a/stdlib/source/lux/control/parser.lux b/stdlib/source/lux/control/parser.lux index 606d8d448..166826519 100644 --- a/stdlib/source/lux/control/parser.lux +++ b/stdlib/source/lux/control/parser.lux @@ -6,43 +6,43 @@ [codec]) (data (coll [list "list/" Functor Monoid]) [product] - ["R" result]))) + ["E" error]))) (type: #export (Parser s a) {#;doc "A generic parser."} - (-> s (R;Result [s a]))) + (-> s (E;Error [s a]))) ## [Structures] (struct: #export Functor (All [s] (Functor (Parser s))) (def: (map f ma) (function [input] (case (ma input) - (#R;Error msg) - (#R;Error msg) + (#E;Error msg) + (#E;Error msg) - (#R;Success [input' a]) - (#R;Success [input' (f a)]))))) + (#E;Success [input' a]) + (#E;Success [input' (f a)]))))) (struct: #export Applicative (All [s] (Applicative (Parser s))) (def: functor Functor) (def: (wrap x) (function [input] - (#R;Success [input x]))) + (#E;Success [input x]))) (def: (apply ff fa) (function [input] (case (ff input) - (#R;Success [input' f]) + (#E;Success [input' f]) (case (fa input') - (#R;Success [input'' a]) - (#R;Success [input'' (f a)]) + (#E;Success [input'' a]) + (#E;Success [input'' (f a)]) - (#R;Error msg) - (#R;Error msg)) + (#E;Error msg) + (#E;Error msg)) - (#R;Error msg) - (#R;Error msg))))) + (#E;Error msg) + (#E;Error msg))))) (struct: #export Monad (All [s] (Monad (Parser s))) (def: applicative Applicative) @@ -50,10 +50,10 @@ (def: (join mma) (function [input] (case (mma input) - (#R;Error msg) - (#R;Error msg) + (#E;Error msg) + (#E;Error msg) - (#R;Success [input' ma]) + (#E;Success [input' ma]) (ma input'))))) ## [Parsers] @@ -62,8 +62,8 @@ (All [s] (-> Text Bool (Parser s Unit))) (function [input] (if test - (#R;Success [input []]) - (#R;Error message)))) + (#E;Success [input []]) + (#E;Error message)))) (def: #export (maybe p) {#;doc "Optionality combinator."} @@ -71,12 +71,12 @@ (-> (Parser s a) (Parser s (Maybe a)))) (function [input] (case (p input) - (#R;Error _) (#R;Success [input #;None]) - (#R;Success [input' x]) (#R;Success [input' (#;Some x)])))) + (#E;Error _) (#E;Success [input #;None]) + (#E;Success [input' x]) (#E;Success [input' (#;Some x)])))) (def: #export (run input p) (All [s a] - (-> s (Parser s a) (R;Result [s a]))) + (-> s (Parser s a) (E;Error [s a]))) (p input)) (def: #export (some p) @@ -85,8 +85,8 @@ (-> (Parser s a) (Parser s (List a)))) (function [input] (case (p input) - (#R;Error _) (#R;Success [input (list)]) - (#R;Success [input' x]) (run input' + (#E;Error _) (#E;Success [input (list)]) + (#E;Success [input' x]) (run input' (do Monad [xs (some p)] (wrap (list& x xs))) @@ -116,8 +116,8 @@ (-> (Parser s a) (Parser s b) (Parser s (| a b)))) (function [tokens] (case (p1 tokens) - (#R;Success [tokens' x1]) (#R;Success [tokens' (+0 x1)]) - (#R;Error _) (run tokens + (#E;Success [tokens' x1]) (#E;Success [tokens' (+0 x1)]) + (#E;Error _) (run tokens (do Monad [x2 p2] (wrap (+1 x2)))) @@ -129,7 +129,7 @@ (-> (Parser s a) (Parser s a) (Parser s a))) (function [tokens] (case (pl tokens) - (#R;Error _) (pr tokens) + (#E;Error _) (pr tokens) output output ))) @@ -157,10 +157,10 @@ (if (n.> +0 n) (function [input] (case (p input) - (#R;Error msg) - (#R;Success [input (list)]) + (#E;Error msg) + (#E;Success [input (list)]) - (#R;Success [input' x]) + (#E;Success [input' x]) (run input' (do Monad [xs (at-most (n.dec n) p)] @@ -195,32 +195,32 @@ (All [s a] (-> (Parser s a) (Parser s Unit))) (function [input] (case (p input) - (#R;Error msg) - (#R;Success [input []]) + (#E;Error msg) + (#E;Success [input []]) _ - (#R;Error "Expected to fail; yet succeeded.")))) + (#E;Error "Expected to fail; yet succeeded.")))) (def: #export (fail message) (All [s a] (-> Text (Parser s a))) (function [input] - (#R;Error message))) + (#E;Error message))) (def: #export (default value parser) {#;doc "If the given parser fails, returns the default value."} (All [s a] (-> a (Parser s a) (Parser s a))) (function [input] (case (parser input) - (#R;Error error) - (#R;Success [input value]) + (#E;Error error) + (#E;Success [input value]) - (#R;Success [input' output]) - (#R;Success [input' output])))) + (#E;Success [input' output]) + (#E;Success [input' output])))) (def: #export remaining (All [s] (Parser s s)) (function [inputs] - (#R;Success [inputs inputs]))) + (#E;Success [inputs inputs]))) (def: #export (rec parser) {#;doc "Combinator for recursive parser."} @@ -252,13 +252,13 @@ (All [s a z] (-> (codec;Codec a z) (Parser s a) (Parser s z))) (function [input] (case (parser input) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [input' to-decode]) + (#E;Success [input' to-decode]) (case (:: Codec decode to-decode) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success value) - (#R;Success [input' value]))))) + (#E;Success value) + (#E;Success [input' value]))))) diff --git a/stdlib/source/lux/data/coll/tree/parser.lux b/stdlib/source/lux/data/coll/tree/parser.lux index 203f55b16..3b2400b92 100644 --- a/stdlib/source/lux/data/coll/tree/parser.lux +++ b/stdlib/source/lux/data/coll/tree/parser.lux @@ -2,7 +2,7 @@ lux (lux (control ["p" parser] ["ex" exception #+ exception:]) - (data ["R" result])) + (data ["E" error])) (.. ["T" rose] ["Z" zipper])) @@ -10,22 +10,22 @@ (p;Parser (Z;Zipper t) a)) (def: #export (run-zipper zipper parser) - (All [t a] (-> (Z;Zipper t) (Parser t a) (R;Result a))) + (All [t a] (-> (Z;Zipper t) (Parser t a) (E;Error a))) (case (p;run zipper parser) - (#R;Success [zipper output]) - (#R;Success output) + (#E;Success [zipper output]) + (#E;Success output) - (#R;Error error) - (#R;Error error))) + (#E;Error error) + (#E;Error error))) (def: #export (run tree parser) - (All [t a] (-> (T;Tree t) (Parser t a) (R;Result a))) + (All [t a] (-> (T;Tree t) (Parser t a) (E;Error a))) (run-zipper (Z;zip tree) parser)) (def: #export value (All [t] (Parser t t)) (function [zipper] - (#R;Success [zipper (Z;value zipper)]))) + (#E;Success [zipper (Z;value zipper)]))) (exception: #export Cannot-Move-Further) @@ -36,7 +36,7 @@ (let [next ( zipper)] (if (is zipper next) (ex;throw Cannot-Move-Further "") - (#R;Success [next []])))))] + (#E;Success [next []])))))] [up Z;up] [down Z;down] diff --git a/stdlib/source/lux/data/error.lux b/stdlib/source/lux/data/error.lux new file mode 100644 index 000000000..e433d7454 --- /dev/null +++ b/stdlib/source/lux/data/error.lux @@ -0,0 +1,98 @@ +(;module: + lux + (lux (control ["F" functor] + ["A" applicative] + ["M" monad #+ do Monad]))) + +## [Types] +(type: #export (Error a) + (#Error Text) + (#Success a)) + +## [Structures] +(struct: #export _ (F;Functor Error) + (def: (map f ma) + (case ma + (#Error msg) (#Error msg) + (#Success datum) (#Success (f datum))))) + +(struct: #export _ (A;Applicative Error) + (def: functor Functor) + + (def: (wrap a) + (#Success a)) + + (def: (apply ff fa) + (case ff + (#Success f) + (case fa + (#Success a) + (#Success (f a)) + + (#Error msg) + (#Error msg)) + + (#Error msg) + (#Error msg)) + )) + +(struct: #export _ (Monad Error) + (def: applicative Applicative) + + (def: (join mma) + (case mma + (#Error msg) (#Error msg) + (#Success ma) ma))) + +(struct: #export (ErrorT Monad) + (All [M] (-> (Monad M) (Monad (All [a] (M (Error a)))))) + (def: applicative (A;compose (get@ #M;applicative Monad) Applicative)) + (def: (join MeMea) + (do Monad + [eMea MeMea] + (case eMea + (#Error error) + (wrap (#Error error)) + + (#Success Mea) + Mea)))) + +(def: #export (lift Monad) + (All [M a] (-> (Monad M) (-> (M a) (M (Error a))))) + (M;lift Monad (:: Monad wrap))) + +(def: #export (succeed value) + (All [a] (-> a (Error a))) + (#Success value)) + +(def: #export (fail message) + (All [a] (-> Text (Error a))) + (#Error message)) + +(def: #export (assume error) + (All [a] (-> (Error a) a)) + (case error + (#Success value) + value + + (#Error message) + (error! message))) + +(macro: #export (default tokens compiler) + {#;doc (doc "Allows you to provide a default value that will be used" + "if a (Error x) value turns out to be #Error." + (is 10 + (default 20 (#Success 10))) + (is 20 + (default 20 (#Error "KABOOM!"))))} + (case tokens + (^ (list else error)) + (#Success [compiler (list (` (case (~ error) + (#;;Success (~' g!temp)) + (~' g!temp) + + (#;;Error (~ [dummy-cursor (#;Symbol ["" ""])])) + (~ else))))]) + + _ + (#Error "Wrong syntax for default"))) diff --git a/stdlib/source/lux/data/format/context.lux b/stdlib/source/lux/data/format/context.lux index a515052c6..5f0d29b11 100644 --- a/stdlib/source/lux/data/format/context.lux +++ b/stdlib/source/lux/data/format/context.lux @@ -3,7 +3,7 @@ (lux (control ["p" parser] ["ex" exception #+ exception:] [monad #+ do]) - (data ["R" result] + (data ["E" error] (coll ["d" dict])))) (exception: #export Unknown-Property) @@ -25,10 +25,10 @@ (ex;throw Unknown-Property name)))) (def: #export (run context property) - (All [a] (-> Context (Property a) (R;Result a))) + (All [a] (-> Context (Property a) (E;Error a))) (case (property context) - (#R;Success [_ output]) - (#R;Success output) + (#E;Success [_ output]) + (#E;Success output) - (#R;Error error) - (#R;Error error))) + (#E;Error error) + (#E;Error error))) diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 867cec189..7eac167e1 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -11,7 +11,7 @@ (text ["l" lexer]) [number "frac/" Codec "nat/" Codec] [maybe] - ["R" result] + ["E" error] [sum] [product] (coll [list "list/" Fold Monad] @@ -96,52 +96,52 @@ (def: #export (get-fields json) {#;doc "Get all the fields in a JSON object."} - (-> JSON (R;Result (List String))) + (-> JSON (E;Error (List String))) (case json (#Object obj) - (#R;Success (dict;keys obj)) + (#E;Success (dict;keys obj)) _ - (#R;Error ($_ text/compose "Cannot get the fields of a non-object.")))) + (#E;Error ($_ text/compose "Cannot get the fields of a non-object.")))) (def: #export (get key json) {#;doc "A JSON object field getter."} - (-> String JSON (R;Result JSON)) + (-> String JSON (E;Error JSON)) (case json (#Object obj) (case (dict;get key obj) (#;Some value) - (#R;Success value) + (#E;Success value) #;None - (#R;Error ($_ text/compose "Missing field \"" key "\" on object."))) + (#E;Error ($_ text/compose "Missing field \"" key "\" on object."))) _ - (#R;Error ($_ text/compose "Cannot get field \"" key "\" of a non-object.")))) + (#E;Error ($_ text/compose "Cannot get field \"" key "\" of a non-object.")))) (def: #export (set key value json) {#;doc "A JSON object field setter."} - (-> String JSON JSON (R;Result JSON)) + (-> String JSON JSON (E;Error JSON)) (case json (#Object obj) - (#R;Success (#Object (dict;put key value obj))) + (#E;Success (#Object (dict;put key value obj))) _ - (#R;Error ($_ text/compose "Cannot set field \"" key "\" of a non-object.")))) + (#E;Error ($_ text/compose "Cannot set field \"" key "\" of a non-object.")))) (do-template [ ] [(def: #export ( key json) {#;doc (code;text ($_ text/compose "A JSON object field getter for " "."))} - (-> Text JSON (R;Result )) + (-> Text JSON (E;Error )) (case (get key json) - (#R;Success ( value)) - (#R;Success value) + (#E;Success ( value)) + (#E;Success value) - (#R;Success _) - (#R;Error ($_ text/compose "Wrong value type at key: " key)) + (#E;Success _) + (#E;Error ($_ text/compose "Wrong value type at key: " key)) - (#R;Error error) - (#R;Error error)))] + (#E;Error error) + (#E;Error error)))] [get-boolean #Boolean Boolean "booleans"] [get-number #Number Number "numbers"] @@ -195,23 +195,23 @@ (def: unconsumed-input-error Text "Unconsumed JSON.") (def: #export (run json parser) - (All [a] (-> JSON (Reader a) (R;Result a))) + (All [a] (-> JSON (Reader a) (E;Error a))) (case (p;run (list json) parser) - (#R;Success [remainder output]) + (#E;Success [remainder output]) (case remainder #;Nil - (#R;Success output) + (#E;Success output) _ - (#R;Error unconsumed-input-error)) + (#E;Error unconsumed-input-error)) - (#R;Error error) - (#R;Error error))) + (#E;Error error) + (#E;Error error))) (def: #export (fail error) (All [a] (-> Text (Reader a))) (function [inputs] - (#R;Error error))) + (#E;Error error))) (def: #export any {#;doc "Just returns the JSON input without applying any logic."} @@ -219,10 +219,10 @@ (<| (function [inputs]) (case inputs #;Nil - (#R;Error "Empty JSON stream.") + (#E;Error "Empty JSON stream.") (#;Cons head tail) - (#R;Success [tail head])))) + (#E;Success [tail head])))) (do-template [ ] [(def: #export @@ -289,10 +289,10 @@ (case head (#Array values) (case (p;run (vector;to-list values) parser) - (#R;Error error) + (#E;Error error) (fail error) - (#R;Success [remainder output]) + (#E;Success [remainder output]) (case remainder #;Nil (wrap output) @@ -310,7 +310,7 @@ [head any] (case head (#Object object) - (case (do R;Monad + (case (do E;Monad [] (|> (dict;entries object) (monad;map @ (function [[key val]] @@ -318,10 +318,10 @@ [val (run val parser)] (wrap [key val])))) (:: @ map (dict;from-list text;Hash)))) - (#R;Success table) + (#E;Success table) (wrap table) - (#R;Error error) + (#E;Error error) (fail error)) _ @@ -337,13 +337,13 @@ (case (dict;get field-name object) (#;Some value) (case (run value parser) - (#R;Success output) + (#E;Success output) (function [tail] - (#R;Success [(#;Cons (#Object (dict;remove field-name object)) + (#E;Success [(#;Cons (#Object (dict;remove field-name object)) tail) output])) - (#R;Error error) + (#E;Error error) (fail error)) _ @@ -438,10 +438,10 @@ offset (l;many l;decimal)] (wrap ($_ text/compose mark (if signed?' "-" "") offset))))] (case (frac/decode ($_ text/compose (if signed? "-" "") digits "." decimals exp)) - (#R;Error message) + (#E;Error message) (p;fail message) - (#R;Success value) + (#E;Success value) (wrap value)))) (def: escaped~ diff --git a/stdlib/source/lux/data/format/xml.lux b/stdlib/source/lux/data/format/xml.lux index 2be7afdd3..f2d1eb056 100644 --- a/stdlib/source/lux/data/format/xml.lux +++ b/stdlib/source/lux/data/format/xml.lux @@ -8,7 +8,7 @@ (data [text "text/" Eq Monoid] (text ["l" lexer]) [number] - ["R" result] + ["E" error] [product] [maybe "m/" Monad] [ident "ident/" Eq Codec] @@ -170,7 +170,7 @@ (p;after (p;maybe xml-header^)))) (def: #export (read input) - (-> Text (R;Result XML)) + (-> Text (E;Error XML)) (l;run input xml^)) (def: (sanitize-value input) @@ -262,7 +262,7 @@ (#;Cons head tail) (case head (#Text value) - (#R;Success [tail value]) + (#E;Success [tail value]) (#Node _) (ex;throw Unexpected-Input ""))))) @@ -285,20 +285,20 @@ (ex;throw Unknown-Attribute "") (#;Some value) - (#R;Success [docs value])))))) + (#E;Success [docs value])))))) (def: (run' docs reader) - (All [a] (-> (List XML) (Reader a) (R;Result a))) + (All [a] (-> (List XML) (Reader a) (E;Error a))) (case (p;run docs reader) - (#R;Success [remaining output]) + (#E;Success [remaining output]) (if (list;empty? remaining) - (#R;Success output) + (#E;Success output) (ex;throw Unconsumed-Inputs (|> remaining (L/map (:: Codec encode)) (text;join-with "\n\n")))) - (#R;Error error) - (#R;Error error))) + (#E;Error error) + (#E;Error error))) (def: #export (node tag) (-> Ident (Reader Unit)) @@ -314,7 +314,7 @@ (#Node _tag _attrs _children) (if (ident/= tag _tag) - (#R;Success [docs []]) + (#E;Success [docs []]) (ex;throw Wrong-Tag (ident/encode tag))))))) (def: #export (children reader) @@ -330,7 +330,7 @@ (ex;throw Unexpected-Input "") (#Node _tag _attrs _children) - (do R;Monad + (do E;Monad [output (run' _children reader)] (wrap [tail output])))))) @@ -342,8 +342,8 @@ (ex;throw Empty-Input "") (#;Cons head tail) - (#R;Success [tail []])))) + (#E;Success [tail []])))) (def: #export (run document reader) - (All [a] (-> XML (Reader a) (R;Result a))) + (All [a] (-> XML (Reader a) (E;Error a))) (run' (list document) reader)) diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux index 4f0c2b9d9..729c83979 100644 --- a/stdlib/source/lux/data/number.lux +++ b/stdlib/source/lux/data/number.lux @@ -8,7 +8,7 @@ enum interval codec) - (data ["R" result] + (data ["E" error] [maybe] [bit]))) @@ -163,10 +163,10 @@ (def: (decode input) (case (_lux_proc [input]) (#;Some value) - (#R;Success value) + (#E;Success value) #;None - (#R;Error ))))] + (#E;Error ))))] [Frac ["frac" "encode"] ["frac" "decode"] "Could not decode Frac"] ) @@ -200,16 +200,16 @@ (let [digit (maybe;assume (get-char input idx))] (case (_lux_proc ["text" "index"] [ digit +0]) #;None - (#R;Error (_lux_proc ["text" "append"] [ repr])) + (#E;Error (_lux_proc ["text" "append"] [ repr])) (#;Some index) (recur (n.inc idx) (|> output (n.* ) (n.+ index))))) - (#R;Success output)))) + (#E;Success output)))) _ - (#R;Error (_lux_proc ["text" "append"] [ repr]))) - (#R;Error (_lux_proc ["text" "append"] [ repr]))))))] + (#E;Error (_lux_proc ["text" "append"] [ repr]))) + (#E;Error (_lux_proc ["text" "append"] [ repr]))))))] [Binary@Codec +2 "01" "Invalid binary syntax for Nat: "] [Octal@Codec +8 "01234567" "Invalid octal syntax for Nat: "] @@ -251,13 +251,13 @@ (let [digit (maybe;assume (get-char input idx))] (case (_lux_proc ["text" "index"] [ digit +0]) #;None - (#R;Error ) + (#E;Error ) (#;Some index) (recur (n.inc idx) (|> output (i.* ) (i.+ (:! Int index)))))) - (#R;Success (i.* sign output))))) - (#R;Error )))))] + (#E;Success (i.* sign output))))) + (#E;Error )))))] [Binary@Codec 2 "01" "Invalid binary syntax for Int: "] [Octal@Codec 8 "01234567" "Invalid octal syntax for Int: "] @@ -291,11 +291,11 @@ (^multi (^ (#;Some (char "."))) [(:: decode (_lux_proc ["text" "append"] ["+" (de-prefix repr)])) (#;Some output)]) - (#R;Success (:! Deg output)) + (#E;Success (:! Deg output)) _ - (#R;Error (_lux_proc ["text" "append"] [ repr]))) - (#R;Error (_lux_proc ["text" "append"] [ repr]))))))] + (#E;Error (_lux_proc ["text" "append"] [ repr]))) + (#E;Error (_lux_proc ["text" "append"] [ repr]))))))] [Binary@Codec Binary@Codec +1 "Invalid binary syntax: "] [Octal@Codec Octal@Codec +3 "Invalid octal syntax: "] @@ -341,19 +341,19 @@ (f.* output)))) adjusted-decimal (|> decimal int-to-frac (f./ div-power)) dec-deg (case (:: Hex@Codec decode (_lux_proc ["text" "append"] ["." decimal-part])) - (#R;Success dec-deg) + (#E;Success dec-deg) dec-deg - (#R;Error error) + (#E;Error error) (error! error))] - (#R;Success (f.+ (int-to-frac whole) + (#E;Success (f.+ (int-to-frac whole) (f.* sign adjusted-decimal)))) _ - (#R;Error (_lux_proc ["text" "append"] [ repr])))) + (#E;Error (_lux_proc ["text" "append"] [ repr])))) _ - (#R;Error (_lux_proc ["text" "append"] [ repr])))))] + (#E;Error (_lux_proc ["text" "append"] [ repr])))))] [Binary@Codec Binary@Codec 2.0 "01" "Invalid binary syntax: "] ) @@ -531,14 +531,14 @@ [(if (f.= -1.0 sign) "-" "")] (_lux_proc ["text" "append"]))] (case (:: Binary@Codec decode as-binary) - (#R;Error _) - (#R;Error (_lux_proc ["text" "append"] [ repr])) + (#E;Error _) + (#E;Error (_lux_proc ["text" "append"] [ repr])) output output)) _ - (#R;Error (_lux_proc ["text" "append"] [ repr]))))))] + (#E;Error (_lux_proc ["text" "append"] [ repr]))))))] [Octal@Codec "Invalid octaladecimal syntax: " binary-to-octal octal-to-binary] [Hex@Codec "Invalid hexadecimal syntax: " binary-to-hex hex-to-binary] @@ -550,26 +550,26 @@ (case tokens (#;Cons [meta (#;Text repr)] #;Nil) (case (:: decode repr) - (#R;Success value) - (#R;Success [state (list [meta (#;Nat value)])]) + (#E;Success value) + (#E;Success [state (list [meta (#;Nat value)])]) - (^multi (#R;Error _) - [(:: decode repr) (#R;Success value)]) - (#R;Success [state (list [meta (#;Int value)])]) + (^multi (#E;Error _) + [(:: decode repr) (#E;Success value)]) + (#E;Success [state (list [meta (#;Int value)])]) - (^multi (#R;Error _) - [(:: decode repr) (#R;Success value)]) - (#R;Success [state (list [meta (#;Deg value)])]) + (^multi (#E;Error _) + [(:: decode repr) (#E;Success value)]) + (#E;Success [state (list [meta (#;Deg value)])]) - (^multi (#R;Error _) - [(:: decode repr) (#R;Success value)]) - (#R;Success [state (list [meta (#;Frac value)])]) + (^multi (#E;Error _) + [(:: decode repr) (#E;Success value)]) + (#E;Success [state (list [meta (#;Frac value)])]) _ - (#R;Error )) + (#E;Error )) _ - (#R;Error )))] + (#E;Error )))] [bin Binary@Codec Binary@Codec Binary@Codec Binary@Codec "Invalid binary syntax." @@ -764,11 +764,11 @@ (recur (digits-sub! power digits) (n.inc idx) (bit;set (n.- idx (n.dec bit;width)) output)))) - (#R;Success (:! Deg output)))) + (#E;Success (:! Deg output)))) #;None - (#R;Error (_lux_proc ["text" "append"] ["Wrong syntax for Deg: " input]))) - (#R;Error (_lux_proc ["text" "append"] ["Wrong syntax for Deg: " input])))) + (#E;Error (_lux_proc ["text" "append"] ["Wrong syntax for Deg: " input]))) + (#E;Error (_lux_proc ["text" "append"] ["Wrong syntax for Deg: " input])))) )) (def: (log2 input) diff --git a/stdlib/source/lux/data/number/complex.lux b/stdlib/source/lux/data/number/complex.lux index d2933a1ab..e1fbccb36 100644 --- a/stdlib/source/lux/data/number/complex.lux +++ b/stdlib/source/lux/data/number/complex.lux @@ -9,7 +9,7 @@ (data [number "f/" Number Codec] [text "text/" Monoid] text/format - ["R" result] + ["E" error] [maybe] (coll [list "L/" Monad])) [macro] @@ -323,7 +323,7 @@ (#;Left (text/compose "Wrong syntax for complex numbers: " input)) (#;Some [r' i']) - (do R;Monad + (do E;Monad [r (f/decode (text;trim r')) i (f/decode (text;trim i'))] (wrap {#real r diff --git a/stdlib/source/lux/data/number/ratio.lux b/stdlib/source/lux/data/number/ratio.lux index 391242a32..8db271d7d 100644 --- a/stdlib/source/lux/data/number/ratio.lux +++ b/stdlib/source/lux/data/number/ratio.lux @@ -10,7 +10,7 @@ (data [number "n/" Number Codec] [text "Text/" Monoid] text/format - ["R" result] + ["E" error] [product] [maybe]) [macro] @@ -131,7 +131,7 @@ (|>. n/encode (text;split +1) maybe;assume product;right)) (def: part-decode - (-> Text (R;Result Nat)) + (-> Text (E;Error Nat)) (|>. (format "+") n/decode)) (struct: #export _ (Codec Text Ratio) @@ -141,7 +141,7 @@ (def: (decode input) (case (text;split-with separator input) (#;Some [num denom]) - (do R;Monad + (do E;Monad [numerator (part-decode num) denominator (part-decode denom)] (wrap (normalize {#numerator numerator diff --git a/stdlib/source/lux/data/result.lux b/stdlib/source/lux/data/result.lux deleted file mode 100644 index df52522af..000000000 --- a/stdlib/source/lux/data/result.lux +++ /dev/null @@ -1,98 +0,0 @@ -(;module: - lux - (lux (control ["F" functor] - ["A" applicative] - ["M" monad #+ do Monad]))) - -## [Types] -(type: #export (Result a) - (#Error Text) - (#Success a)) - -## [Structures] -(struct: #export _ (F;Functor Result) - (def: (map f ma) - (case ma - (#Error msg) (#Error msg) - (#Success datum) (#Success (f datum))))) - -(struct: #export _ (A;Applicative Result) - (def: functor Functor) - - (def: (wrap a) - (#Success a)) - - (def: (apply ff fa) - (case ff - (#Success f) - (case fa - (#Success a) - (#Success (f a)) - - (#Error msg) - (#Error msg)) - - (#Error msg) - (#Error msg)) - )) - -(struct: #export _ (Monad Result) - (def: applicative Applicative) - - (def: (join mma) - (case mma - (#Error msg) (#Error msg) - (#Success ma) ma))) - -(struct: #export (ResultT Monad) - (All [M] (-> (Monad M) (Monad (All [a] (M (Result a)))))) - (def: applicative (A;compose (get@ #M;applicative Monad) Applicative)) - (def: (join MeMea) - (do Monad - [eMea MeMea] - (case eMea - (#Error error) - (wrap (#Error error)) - - (#Success Mea) - Mea)))) - -(def: #export (lift Monad) - (All [M a] (-> (Monad M) (-> (M a) (M (Result a))))) - (M;lift Monad (:: Monad wrap))) - -(def: #export (succeed value) - (All [a] (-> a (Result a))) - (#Success value)) - -(def: #export (fail message) - (All [a] (-> Text (Result a))) - (#Error message)) - -(def: #export (assume result) - (All [a] (-> (Result a) a)) - (case result - (#Success value) - value - - (#Error message) - (error! message))) - -(macro: #export (default tokens compiler) - {#;doc (doc "Allows you to provide a default value that will be used" - "if a (Result x) value turns out to be #Error." - (is 10 - (default 20 (#Success 10))) - (is 20 - (default 20 (#Error "KABOOM!"))))} - (case tokens - (^ (list else result)) - (#Success [compiler (list (` (case (~ result) - (#;;Success (~' g!temp)) - (~' g!temp) - - (#;;Error (~ [dummy-cursor (#;Symbol ["" ""])])) - (~ else))))]) - - _ - (#Error "Wrong syntax for default"))) diff --git a/stdlib/source/lux/data/text/lexer.lux b/stdlib/source/lux/data/text/lexer.lux index 1f76e833a..3803414e4 100644 --- a/stdlib/source/lux/data/text/lexer.lux +++ b/stdlib/source/lux/data/text/lexer.lux @@ -5,7 +5,7 @@ (data [text "text/" Monoid] [product] [maybe] - ["R" result] + ["E" error] (coll [list])) (macro [code]))) @@ -27,15 +27,15 @@ ($_ text/compose "Unconsumed input: " (remaining offset tape))) (def: #export (run input lexer) - (All [a] (-> Text (Lexer a) (R;Result a))) + (All [a] (-> Text (Lexer a) (E;Error a))) (case (lexer [start-offset input]) - (#R;Error msg) - (#R;Error msg) + (#E;Error msg) + (#E;Error msg) - (#R;Success [[end-offset _] output]) + (#E;Success [[end-offset _] output]) (if (n.= end-offset (text;size input)) - (#R;Success output) - (#R;Error (unconsumed-input-error end-offset input))) + (#E;Success output) + (#E;Error (unconsumed-input-error end-offset input))) )) (def: #export any @@ -44,10 +44,10 @@ (function [[offset tape]] (case (text;nth offset tape) (#;Some output) - (#R;Success [[(n.inc offset) tape] (text;from-code output)]) + (#E;Success [[(n.inc offset) tape] (text;from-code output)]) _ - (#R;Error cannot-lex-error)) + (#E;Error cannot-lex-error)) )) (def: #export (not p) @@ -55,11 +55,11 @@ (All [a] (-> (Lexer a) (Lexer Text))) (function [input] (case (p input) - (#R;Error msg) + (#E;Error msg) (any input) _ - (#R;Error "Expected to fail; yet succeeded.")))) + (#E;Error "Expected to fail; yet succeeded.")))) (def: #export (this reference) {#;doc "Lex a text if it matches the given sample."} @@ -67,10 +67,10 @@ (function [[offset tape]] (case (text;index-of reference offset tape) (^multi (#;Some where) (n.= offset where)) - (#R;Success [[(n.+ (text;size reference) offset) tape] []]) + (#E;Success [[(n.+ (text;size reference) offset) tape] []]) _ - (#R;Error ($_ text/compose "Could not match: " (text;encode reference) " @ " tape))))) + (#E;Error ($_ text/compose "Could not match: " (text;encode reference) " @ " tape))))) (def: #export (this? reference) {#;doc "Lex a text if it matches the given sample."} @@ -78,24 +78,24 @@ (function [(^@ input [offset tape])] (case (text;index-of reference offset tape) (^multi (#;Some where) (n.= offset where)) - (#R;Success [[(n.+ (text;size reference) offset) tape] true]) + (#E;Success [[(n.+ (text;size reference) offset) tape] true]) _ - (#R;Success [input false])))) + (#E;Success [input false])))) (def: #export end {#;doc "Ensure the lexer's input is empty."} (Lexer Unit) (function [(^@ input [offset tape])] (if (n.= offset (text;size tape)) - (#R;Success [input []]) - (#R;Error (unconsumed-input-error offset tape))))) + (#E;Success [input []]) + (#E;Error (unconsumed-input-error offset tape))))) (def: #export end? {#;doc "Ask if the lexer's input is empty."} (Lexer Bool) (function [(^@ input [offset tape])] - (#R;Success [input (n.= offset (text;size tape))]))) + (#E;Success [input (n.= offset (text;size tape))]))) (def: #export peek {#;doc "Lex the next character (without consuming it from the input)."} @@ -103,17 +103,17 @@ (function [(^@ input [offset tape])] (case (text;nth offset tape) (#;Some output) - (#R;Success [input (text;from-code output)]) + (#E;Success [input (text;from-code output)]) _ - (#R;Error cannot-lex-error)) + (#E;Error cannot-lex-error)) )) (def: #export get-input {#;doc "Get all of the remaining input (without consuming it)."} (Lexer Text) (function [(^@ input [offset tape])] - (#R;Success [input (remaining offset tape)]))) + (#E;Success [input (remaining offset tape)]))) (def: #export (range bottom top) {#;doc "Only lex characters within a range."} @@ -164,11 +164,11 @@ (#;Some output) (let [output (text;from-code output)] (if (text;contains? output options) - (#R;Success [[(n.inc offset) tape] output]) - (#R;Error ($_ text/compose "Character (" output ") is not one of: " options)))) + (#E;Success [[(n.inc offset) tape] output]) + (#E;Error ($_ text/compose "Character (" output ") is not one of: " options)))) _ - (#R;Error cannot-lex-error)))) + (#E;Error cannot-lex-error)))) (def: #export (none-of options) {#;doc "Only lex characters that are not part of a piece of text."} @@ -178,11 +178,11 @@ (#;Some output) (let [output (text;from-code output)] (if (;not (text;contains? output options)) - (#R;Success [[(n.inc offset) tape] output]) - (#R;Error ($_ text/compose "Character (" output ") is one of: " options)))) + (#E;Success [[(n.inc offset) tape] output]) + (#E;Error ($_ text/compose "Character (" output ") is one of: " options)))) _ - (#R;Error cannot-lex-error)))) + (#E;Error cannot-lex-error)))) (def: #export (satisfies p) {#;doc "Only lex characters that satisfy a predicate."} @@ -191,11 +191,11 @@ (case (text;nth offset tape) (#;Some output) (if (p output) - (#R;Success [[(n.inc offset) tape] (text;from-code output)]) - (#R;Error ($_ text/compose "Character does not satisfy predicate: " (text;from-code output)))) + (#E;Success [[(n.inc offset) tape] (text;from-code output)]) + (#E;Error ($_ text/compose "Character does not satisfy predicate: " (text;from-code output)))) _ - (#R;Error cannot-lex-error)))) + (#E;Error cannot-lex-error)))) (def: #export space {#;doc "Only lex white-space."} @@ -248,8 +248,8 @@ (All [a] (-> Text (Lexer a) (Lexer a))) (function [real-input] (case (run local-input lexer) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success value) - (#R;Success [real-input value])))) + (#E;Success value) + (#E;Success [real-input value])))) diff --git a/stdlib/source/lux/data/text/regex.lux b/stdlib/source/lux/data/text/regex.lux index 11139cd6a..a425224cb 100644 --- a/stdlib/source/lux/data/text/regex.lux +++ b/stdlib/source/lux/data/text/regex.lux @@ -7,7 +7,7 @@ text/format [number "Int/" Codec] [product] - ["R" result] + ["E" error] [maybe] (coll [list "L/" Fold Monad])) [macro #- run] @@ -276,14 +276,14 @@ [Int (List Code) (List (List Code))]) (function [part [idx names steps]] (case part - (^or (#R;Error complex) (#R;Success [#Non-Capturing complex])) + (^or (#E;Error complex) (#E;Success [#Non-Capturing complex])) [idx names (list& (list g!temp complex (' #let) (` [(~ g!total) (_Text/compose_ (~ g!total) (~ g!temp))])) steps)] - (#R;Success [(#Capturing [?name num-captures]) scoped]) + (#E;Success [(#Capturing [?name num-captures]) scoped]) (let [[idx! name!] (case ?name (#;Some _name) [idx (code;symbol ["" _name])] @@ -320,31 +320,31 @@ (All [l r] (-> (l;Lexer [Text l]) (l;Lexer [Text r]) (l;Lexer [Text (| l r)]))) (function [input] (case (left input) - (#R;Success [input' [lt lv]]) - (#R;Success [input' [lt (+0 lv)]]) + (#E;Success [input' [lt lv]]) + (#E;Success [input' [lt (+0 lv)]]) - (#R;Error _) + (#E;Error _) (case (right input) - (#R;Success [input' [rt rv]]) - (#R;Success [input' [rt (+1 rv)]]) + (#E;Success [input' [rt rv]]) + (#E;Success [input' [rt (+1 rv)]]) - (#R;Error error) - (#R;Error error))))) + (#E;Error error) + (#E;Error error))))) (def: #hidden (|||_^ left right) (All [l r] (-> (l;Lexer [Text l]) (l;Lexer [Text r]) (l;Lexer Text))) (function [input] (case (left input) - (#R;Success [input' [lt lv]]) - (#R;Success [input' lt]) + (#E;Success [input' [lt lv]]) + (#E;Success [input' lt]) - (#R;Error _) + (#E;Error _) (case (right input) - (#R;Success [input' [rt rv]]) - (#R;Success [input' rt]) + (#E;Success [input' [rt rv]]) + (#E;Success [input' rt]) - (#R;Error error) - (#R;Error error))))) + (#E;Error error) + (#E;Error error))))) (def: (prep-alternative [num-captures alt]) (-> [Nat Code] Code) @@ -462,11 +462,11 @@ (case (|> (regex^ current-module) (p;before l;end) (l;run pattern)) - (#R;Error error) + (#E;Error error) (macro;fail (format "Error while parsing regular-expression:\n" error)) - (#R;Success regex) + (#E;Success regex) (wrap (list regex)) ))) @@ -488,7 +488,7 @@ [g!temp (macro;gensym "temp")] (wrap (list& (` (^multi (~ g!temp) [(l;run (~ g!temp) (regex (~ (code;text pattern)))) - (#R;Success (~ (maybe;default g!temp + (#E;Success (~ (maybe;default g!temp bindings)))])) body branches)))) diff --git a/stdlib/source/lux/macro.lux b/stdlib/source/lux/macro.lux index 9f691c964..4fb0b08a4 100644 --- a/stdlib/source/lux/macro.lux +++ b/stdlib/source/lux/macro.lux @@ -8,43 +8,43 @@ [product] [ident "ident/" Codec Eq] [maybe] - ["R" result] + ["E" error] [text "text/" Monoid Eq] (coll [list "list/" Monoid Monad])))) ## (type: (Lux a) -## (-> Compiler (R;Result [Compiler a]))) +## (-> Compiler (E;Error [Compiler a]))) (struct: #export _ (F;Functor Lux) (def: (map f fa) (function [state] (case (fa state) - (#R;Error msg) - (#R;Error msg) + (#E;Error msg) + (#E;Error msg) - (#R;Success [state' a]) - (#R;Success [state' (f a)]))))) + (#E;Success [state' a]) + (#E;Success [state' (f a)]))))) (struct: #export _ (A;Applicative Lux) (def: functor Functor) (def: (wrap x) (function [state] - (#R;Success [state x]))) + (#E;Success [state x]))) (def: (apply ff fa) (function [state] (case (ff state) - (#R;Success [state' f]) + (#E;Success [state' f]) (case (fa state') - (#R;Success [state'' a]) - (#R;Success [state'' (f a)]) + (#E;Success [state'' a]) + (#E;Success [state'' (f a)]) - (#R;Error msg) - (#R;Error msg)) + (#E;Error msg) + (#E;Error msg)) - (#R;Error msg) - (#R;Error msg))))) + (#E;Error msg) + (#E;Error msg))))) (struct: #export _ (Monad Lux) (def: applicative Applicative) @@ -52,10 +52,10 @@ (def: (join mma) (function [state] (case (mma state) - (#R;Error msg) - (#R;Error msg) + (#E;Error msg) + (#E;Error msg) - (#R;Success [state' ma]) + (#E;Success [state' ma]) (ma state'))))) (def: (get k plist) @@ -71,53 +71,53 @@ (get k plist')))) (def: #export (run' compiler action) - (All [a] (-> Compiler (Lux a) (R;Result [Compiler a]))) + (All [a] (-> Compiler (Lux a) (E;Error [Compiler a]))) (action compiler)) (def: #export (run compiler action) - (All [a] (-> Compiler (Lux a) (R;Result a))) + (All [a] (-> Compiler (Lux a) (E;Error a))) (case (action compiler) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [_ output]) - (#R;Success output))) + (#E;Success [_ output]) + (#E;Success output))) (def: #export (either left right) {#;doc "Pick whichever computation succeeds."} (All [a] (-> (Lux a) (Lux a) (Lux a))) (function [compiler] (case (left compiler) - (#R;Error error) + (#E;Error error) (right compiler) - (#R;Success [compiler' output]) - (#R;Success [compiler' output])))) + (#E;Success [compiler' output]) + (#E;Success [compiler' output])))) (def: #export (assert message test) {#;doc "Fails with the given message if the test is false."} (-> Text Bool (Lux Unit)) (function [compiler] (if test - (#R;Success [compiler []]) - (#R;Error message)))) + (#E;Success [compiler []]) + (#E;Error message)))) (def: #export (fail msg) {#;doc "Fails with the given message."} (All [a] (-> Text (Lux a))) (function [_] - (#R;Error msg))) + (#E;Error msg))) (def: #export (find-module name) (-> Text (Lux Module)) (function [state] (case (get name (get@ #;modules state)) (#;Some module) - (#R;Success [state module]) + (#E;Success [state module]) _ - (#R;Error ($_ text/compose "Unknown module: " name))))) + (#E;Error ($_ text/compose "Unknown module: " name))))) (def: #export current-module-name (Lux Text) @@ -126,13 +126,13 @@ (#;Some scope) (case (get@ #;name scope) (#;Cons m-name #;Nil) - (#R;Success [state m-name]) + (#E;Success [state m-name]) _ - (#R;Error "Improper name for scope.")) + (#E;Error "Improper name for scope.")) _ - (#R;Error "Empty environment!") + (#E;Error "Empty environment!") ))) (def: #export current-module @@ -261,7 +261,7 @@ (let [[module name] ident] (: (Lux (Maybe Macro)) (function [state] - (#R;Success [state (find-macro' (get@ #;modules state) this-module module name)])))))) + (#E;Success [state (find-macro' (get@ #;modules state) this-module module name)])))))) (def: #export (normalize ident) {#;doc "If given an identifier without a module prefix, gives it the current module's name as prefix. @@ -360,7 +360,7 @@ A prefix can be given (or just be empty text \"\") to better identify the code for debugging purposes."} (-> Text (Lux Code)) (function [state] - (#R;Success [(update@ #;seed n.inc state) + (#E;Success [(update@ #;seed n.inc state) (code;symbol ["" ($_ text/compose "__gensym__" prefix (:: number;Codec encode (get@ #;seed state)))])]))) (def: (get-local-symbol ast) @@ -411,7 +411,7 @@ (def: #export (module-exists? module) (-> Text (Lux Bool)) (function [state] - (#R;Success [state (case (get module (get@ #;modules state)) + (#E;Success [state (case (get module (get@ #;modules state)) (#;Some _) true @@ -445,10 +445,10 @@ (get@ [#;captured #;mappings] scope)))] (wrap type)) (#;Some var-type) - (#R;Success [state var-type]) + (#E;Success [state var-type]) #;None - (#R;Error ($_ text/compose "Unknown variable: " name)))))) + (#E;Error ($_ text/compose "Unknown variable: " name)))))) (def: #export (find-def name) {#;doc "Looks-up a definition's whole data in the available modules (including the current one)."} @@ -460,10 +460,10 @@ (^slots [#;defs]) (get v-prefix (get@ #;modules state))] (get v-name defs))) (#;Some _anns) - (#R;Success [state _anns]) + (#E;Success [state _anns]) _ - (#R;Error ($_ text/compose "Unknown definition: " (ident/encode name)))))) + (#E;Error ($_ text/compose "Unknown definition: " (ident/encode name)))))) (def: #export (find-def-type name) {#;doc "Looks-up a definition's type in the available modules (including the current one)."} @@ -494,8 +494,8 @@ (-> Text (Lux (List [Text Def]))) (function [state] (case (get module-name (get@ #;modules state)) - #;None (#R;Error ($_ text/compose "Unknown module: " module-name)) - (#;Some module) (#R;Success [state (get@ #;defs module)]) + #;None (#E;Error ($_ text/compose "Unknown module: " module-name)) + (#;Some module) (#E;Success [state (get@ #;defs module)]) ))) (def: #export (exports module-name) @@ -515,7 +515,7 @@ (|> state (get@ #;modules) [state] - #R;Success))) + #E;Success))) (def: #export (tags-of type-name) {#;doc "All the tags associated with a type definition."} @@ -534,7 +534,7 @@ {#;doc "The cursor of the current expression being analyzed."} (Lux Cursor) (function [state] - (#R;Success [state (get@ #;cursor state)]))) + (#E;Success [state (get@ #;cursor state)]))) (def: #export expected-type {#;doc "The expected type of the current expression being analyzed."} @@ -542,10 +542,10 @@ (function [state] (case (get@ #;expected state) (#;Some type) - (#R;Success [state type]) + (#E;Success [state type]) #;None - (#R;Error "Not expecting any type.")))) + (#E;Error "Not expecting any type.")))) (def: #export (imported-modules module-name) {#;doc "All the modules imported by a specified module."} @@ -590,10 +590,10 @@ (function [state] (case (list;inits (get@ #;scopes state)) #;None - (#R;Error "No local environment") + (#E;Error "No local environment") (#;Some scopes) - (#R;Success [state + (#E;Success [state (list/map (|>. (get@ [#;locals #;mappings]) (list/map (function [[name [type _]]] [name type]))) @@ -616,12 +616,12 @@ {#;doc "Obtains the current state of the compiler."} (Lux Compiler) (function [compiler] - (#R;Success [compiler compiler]))) + (#E;Success [compiler compiler]))) (def: #export type-context (Lux Type-Context) (function [compiler] - (#R;Success [compiler (get@ #;type-context compiler)]))) + (#E;Success [compiler (get@ #;type-context compiler)]))) (do-template [ ] [(macro: #export ( tokens) diff --git a/stdlib/source/lux/macro/poly.lux b/stdlib/source/lux/macro/poly.lux index d744a28f7..fc6c7120f 100644 --- a/stdlib/source/lux/macro/poly.lux +++ b/stdlib/source/lux/macro/poly.lux @@ -12,7 +12,7 @@ [bool] [maybe] [ident "ident/" Eq Codec] - ["R" result]) + ["E" error]) [macro #+ with-gensyms] (macro [code] ["s" syntax #+ syntax: Syntax] @@ -31,70 +31,70 @@ (def: #export fresh Env (dict;new number;Hash)) (def: (run' env types poly) - (All [a] (-> Env (List Type) (Poly a) (R;Result a))) + (All [a] (-> Env (List Type) (Poly a) (E;Error a))) (case (p;run [env types] poly) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [[env' remaining] output]) + (#E;Success [[env' remaining] output]) (case remaining #;Nil - (#R;Success output) + (#E;Success output) _ - (#R;Error (|> remaining + (#E;Error (|> remaining (list/map type;to-text) (text;join-with ", ") (text/compose "Unconsumed types: ")))))) (def: #export (run type poly) - (All [a] (-> Type (Poly a) (R;Result a))) + (All [a] (-> Type (Poly a) (E;Error a))) (run' fresh (list type) poly)) (def: #export env (Poly Env) (;function [[env inputs]] - (#R;Success [[env inputs] env]))) + (#E;Success [[env inputs] env]))) (def: (with-env temp poly) (All [a] (-> Env (Poly a) (Poly a))) (;function [[env inputs]] (case (p;run [temp inputs] poly) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [[_ remaining] output]) - (#R;Success [[env remaining] output])))) + (#E;Success [[_ remaining] output]) + (#E;Success [[env remaining] output])))) (def: #export peek (Poly Type) (;function [[env inputs]] (case inputs #;Nil - (#R;Error "Empty stream of types.") + (#E;Error "Empty stream of types.") (#;Cons headT tail) - (#R;Success [[env inputs] headT])))) + (#E;Success [[env inputs] headT])))) (def: #export any (Poly Type) (;function [[env inputs]] (case inputs #;Nil - (#R;Error "Empty stream of types.") + (#E;Error "Empty stream of types.") (#;Cons headT tail) - (#R;Success [[env tail] headT])))) + (#E;Success [[env tail] headT])))) (def: #export (local types poly) (All [a] (-> (List Type) (Poly a) (Poly a))) (;function [[env pass-through]] (case (run' env types poly) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success output) - (#R;Success [[env pass-through] output])))) + (#E;Success output) + (#E;Success [[env pass-through] output])))) (def: (label idx) (-> Nat Code) @@ -108,11 +108,11 @@ (case (p;run [(dict;put current-id [type g!var] env) inputs] poly) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [[_ inputs'] output]) - (#R;Success [[env inputs'] [g!var output]]))))) + (#E;Success [[_ inputs'] output]) + (#E;Success [[env inputs'] [g!var output]]))))) (do-template [ ] [(def: #export @@ -149,10 +149,10 @@ deg frac text)) - (#R;Error error) + (#E;Error error) (p;fail error) - (#R;Success _) + (#E;Success _) (wrap headT)))) (do-template [ ] diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux index 1c3510b85..1b66e39f5 100644 --- a/stdlib/source/lux/macro/poly/json.lux +++ b/stdlib/source/lux/macro/poly/json.lux @@ -10,7 +10,7 @@ (text ["l" lexer]) [number "frac/" Codec "nat/" Codec] maybe - ["R" result] + ["E" error] [sum] [product] (coll [list "list/" Fold Monad] @@ -63,7 +63,7 @@ (struct: #hidden _ (Codec JSON Int) (def: encode (|>. int-to-nat (:: Codec encode))) (def: decode - (|>. (:: Codec decode) (:: R;Functor map nat-to-int)))) + (|>. (:: Codec decode) (:: E;Functor map nat-to-int)))) (def: #hidden (nullable writer) {#;doc "Builds a JSON generator for potentially inexistent values."} @@ -78,7 +78,7 @@ (def: encode (|>. unit;out (:: Codec encode))) (def: decode - (|>. (:: Codec decode) (:: R;Functor map (unit;in carrier))))) + (|>. (:: Codec decode) (:: E;Functor map (unit;in carrier))))) (poly: #hidden Codec//encode (with-expansions diff --git a/stdlib/source/lux/macro/syntax.lux b/stdlib/source/lux/macro/syntax.lux index 4e431de82..a31eb8c6e 100644 --- a/stdlib/source/lux/macro/syntax.lux +++ b/stdlib/source/lux/macro/syntax.lux @@ -11,7 +11,7 @@ (coll [list "list/" Functor]) [product] [maybe] - ["R" result])) + ["E" error])) (.. [code "code/" Eq])) ## [Utils] @@ -38,8 +38,8 @@ (Syntax Code) (function [tokens] (case tokens - #;Nil (#R;Error "There are no tokens to parse!") - (#;Cons [t tokens']) (#R;Success [tokens' t])))) + #;Nil (#E;Error "There are no tokens to parse!") + (#;Cons [t tokens']) (#E;Success [tokens' t])))) (do-template [ ] [(def: #export @@ -48,10 +48,10 @@ (function [tokens] (case tokens (#;Cons [[_ ( x)] tokens']) - (#R;Success [tokens' x]) + (#E;Success [tokens' x]) _ - (#R;Error ($_ text/compose "Cannot parse " (remaining-inputs tokens))))))] + (#E;Error ($_ text/compose "Cannot parse " (remaining-inputs tokens))))))] [ bool Bool #;Bool bool;Eq "bool"] [ nat Nat #;Nat number;Eq "nat"] @@ -73,10 +73,10 @@ remaining (if is-it? tokens' tokens)] - (#R;Success [remaining is-it?])) + (#E;Success [remaining is-it?])) _ - (#R;Success [tokens false])))) + (#E;Success [tokens false])))) (def: #export (this ast) {#;doc "Ensures the given Code is the next input."} @@ -85,12 +85,12 @@ (case tokens (#;Cons [token tokens']) (if (code/= ast token) - (#R;Success [tokens' []]) - (#R;Error ($_ text/compose "Expected a " (code;to-text ast) " but instead got " (code;to-text token) + (#E;Success [tokens' []]) + (#E;Error ($_ text/compose "Expected a " (code;to-text ast) " but instead got " (code;to-text token) (remaining-inputs tokens)))) _ - (#R;Error "There are no tokens to parse!")))) + (#E;Error "There are no tokens to parse!")))) (do-template [ ] [(def: #export @@ -111,10 +111,10 @@ (function [tokens] (case tokens (#;Cons [[_ ( ["" x])] tokens']) - (#R;Success [tokens' x]) + (#E;Success [tokens' x]) _ - (#R;Error ($_ text/compose "Cannot parse local " (remaining-inputs tokens))))))] + (#E;Error ($_ text/compose "Cannot parse local " (remaining-inputs tokens))))))] [local-symbol #;Symbol "symbol"] [ local-tag #;Tag "tag"] @@ -129,11 +129,11 @@ (case tokens (#;Cons [[_ ( members)] tokens']) (case (p members) - (#R;Success [#;Nil x]) (#R;Success [tokens' x]) - _ (#R;Error ($_ text/compose "Syntax was expected to fully consume " (remaining-inputs tokens)))) + (#E;Success [#;Nil x]) (#E;Success [tokens' x]) + _ (#E;Error ($_ text/compose "Syntax was expected to fully consume " (remaining-inputs tokens)))) _ - (#R;Error ($_ text/compose "Cannot parse " (remaining-inputs tokens))))))] + (#E;Error ($_ text/compose "Cannot parse " (remaining-inputs tokens))))))] [ form #;Form "form"] [tuple #;Tuple "tuple"] @@ -147,38 +147,38 @@ (case tokens (#;Cons [[_ (#;Record pairs)] tokens']) (case (p (join-pairs pairs)) - (#R;Success [#;Nil x]) (#R;Success [tokens' x]) - _ (#R;Error ($_ text/compose "Syntax was expected to fully consume record" (remaining-inputs tokens)))) + (#E;Success [#;Nil x]) (#E;Success [tokens' x]) + _ (#E;Error ($_ text/compose "Syntax was expected to fully consume record" (remaining-inputs tokens)))) _ - (#R;Error ($_ text/compose "Cannot parse record" (remaining-inputs tokens)))))) + (#E;Error ($_ text/compose "Cannot parse record" (remaining-inputs tokens)))))) (def: #export end! {#;doc "Ensures there are no more inputs."} (Syntax Unit) (function [tokens] (case tokens - #;Nil (#R;Success [tokens []]) - _ (#R;Error ($_ text/compose "Expected list of tokens to be empty!" (remaining-inputs tokens)))))) + #;Nil (#E;Success [tokens []]) + _ (#E;Error ($_ text/compose "Expected list of tokens to be empty!" (remaining-inputs tokens)))))) (def: #export end? {#;doc "Checks whether there are no more inputs."} (Syntax Bool) (function [tokens] (case tokens - #;Nil (#R;Success [tokens true]) - _ (#R;Success [tokens false])))) + #;Nil (#E;Success [tokens true]) + _ (#E;Success [tokens false])))) (def: #export (on compiler action) {#;doc "Run a Lux operation as if it was a Syntax parser."} (All [a] (-> Compiler (Lux a) (Syntax a))) (function [input] (case (macro;run compiler action) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success value) - (#R;Success [input value]) + (#E;Success value) + (#E;Success [input value]) ))) (def: #export (local local-inputs syntax) @@ -186,16 +186,16 @@ (All [a] (-> (List Code) (Syntax a) (Syntax a))) (function [real-inputs] (case (syntax local-inputs) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [unconsumed-inputs value]) + (#E;Success [unconsumed-inputs value]) (case unconsumed-inputs #;Nil - (#R;Success [real-inputs value]) + (#E;Success [real-inputs value]) _ - (#R;Error (text/compose "Unconsumed inputs: " + (#E;Error (text/compose "Unconsumed inputs: " (|> (list/map code;to-text unconsumed-inputs) (text;join-with ", ")))))))) @@ -265,10 +265,10 @@ g!end (code;symbol ["" ""]) error-msg (code;text (text/compose "Wrong syntax for " name)) export-ast (: (List Code) (case exported? - (#;Some #R;Error) + (#;Some #E;Error) (list (' #hidden)) - (#;Some #R;Success) + (#;Some #E;Success) (list (' #export)) _ @@ -280,15 +280,15 @@ (: (Syntax (Lux (List Code))) (do ;;_Monad_ [(~@ (join-pairs vars+parsers)) - (~ g!end) end!] + (~ g!end) ;;end!] ((~' wrap) (do macro;Monad [] (~ body)))))) - (#R;Success [(~ g!tokens) (~ g!body)]) + (#E;Success [(~ g!tokens) (~ g!body)]) ((~ g!body) (~ g!state)) - (#R;Error (~ g!msg)) - (#R;Error (text.join-with ": " (list (~ error-msg) (~ g!msg)))))))))))) + (#E;Error (~ g!msg)) + (#E;Error (text.join-with ": " (list (~ error-msg) (~ g!msg)))))))))))) _ (macro;fail "Wrong syntax for syntax:")))) diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index 6d21a074b..e25f685cf 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -11,11 +11,11 @@ [maybe] [text] text/format - ["E" result]) + ["E" error]) [io #- run] (time [instant] [duration]) - ["R" math/random])) + ["r" math/random])) ## [Host] (do-template [ ] @@ -83,18 +83,18 @@ (|>. product;right (n.> +0))) (def: (try seed random-test) - (-> Seed (R;Random Test) (Promise [Seed [Counters Text]])) - (let [[prng [new-seed test]] (R;run (R;pcg-32 [pcg-32-magic-inc seed]) - (do R;Monad + (-> Seed (r;Random Test) (Promise [Seed [Counters Text]])) + (let [[prng [new-seed test]] (r;run (r;pcg-32 [pcg-32-magic-inc seed]) + (do r;Monad [test random-test - next-seed R;nat] + next-seed r;nat] (wrap [next-seed test])))] (do Monad [result test] (wrap [new-seed result])))) (def: (repeat' seed times random-test) - (-> Seed Nat (R;Random Test) Test) + (-> Seed Nat (r;Random Test) Test) (if (n.= +0 times) (fail "Cannot try a test 0 times.") (do Monad @@ -110,9 +110,9 @@ (repeat' seed' (n.dec times) random-test))))) (def: #hidden (repeat ?seed times random-test) - (-> (Maybe Nat) Nat (R;Random Test) Test) + (-> (Maybe Nat) Nat (r;Random Test) Test) (repeat' (maybe;default (|> (io;run instant;now) instant;to-millis int-to-nat) - ?seed) + ?seed) (case ?seed #;None times (#;Some _) +1) @@ -197,10 +197,10 @@ (test "Can have defaults for Maybe values." (and (is "yolo" (maybe;default "yolo" - #;None)) + #;None)) (is "lol" (maybe;default "yolo" - (#;Some "lol"))))) + (#;Some "lol"))))) )) "Also works with random generation of values for property-based testing." (context: "Addition & Substraction" @@ -240,7 +240,7 @@ bindings' (|> bindings (L/map pair-to-list) L/join)] (` (repeat (~ =seed) (~ (code;nat =times)) - (do R;Monad + (do r;Monad [(~@ bindings')] ((~' wrap) (;;try-body (io;io (~ body)))))))) diff --git a/stdlib/source/lux/time/date.lux b/stdlib/source/lux/time/date.lux index 9f2d2972b..b513ef07c 100644 --- a/stdlib/source/lux/time/date.lux +++ b/stdlib/source/lux/time/date.lux @@ -6,7 +6,7 @@ codec ["p" parser] [monad #+ do]) - (data ["R" result] + (data ["E" error] [maybe] [number "int/" Codec] [text "text/" Monoid] @@ -311,7 +311,7 @@ #day (int-to-nat utc-day)}))) (def: (decode input) - (-> Text (R;Result Date)) + (-> Text (E;Error Date)) (l;run input lex-date)) (struct: #export _ diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 003a84a97..35911a6cc 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -8,7 +8,7 @@ (data [number "int/" Codec Number] [text "text/" Monoid] (text ["l" lexer]) - ["R" result]) + ["E" error]) (type opaque))) (opaque: #export Duration @@ -134,7 +134,7 @@ (merge (scale (sign utc-millis) milli)))))) (def: (decode input) - (-> Text (R;Result Duration)) + (-> Text (E;Error Duration)) (l;run input lex-duration)) (struct: #export _ diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index c76f108fb..31da7dc29 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -10,7 +10,7 @@ (data [text "text/" Monoid] (text ["l" lexer]) [number "int/" Codec] - ["R" result] + ["E" error] [maybe] (coll [list "L/" Fold Functor] ["v" vector "v/" Functor Fold])) @@ -296,7 +296,7 @@ (shift (duration;scale utc-millis duration;milli)))))) (def: (decode input) - (-> Text (R;Result Instant)) + (-> Text (E;Error Instant)) (l;run input lex-instant)) (struct: #export _ diff --git a/stdlib/source/lux/type/check.lux b/stdlib/source/lux/type/check.lux index 769b45391..f51ba5a15 100644 --- a/stdlib/source/lux/type/check.lux +++ b/stdlib/source/lux/type/check.lux @@ -2,57 +2,57 @@ Very useful for writing advanced macros."} lux - (lux (control ["F" functor] - ["A" applicative] - ["M" monad #+ do Monad]) + (lux (control [functor #+ Functor] + [applicative #+ Applicative] + [monad #+ do Monad]) (data [text "text/" Monoid Eq] [number "nat/" Codec] maybe [product] (coll [list]) - ["R" result]) - [type "Type/" Eq] + ["E" error]) + [type "type/" Eq] )) (type: #export Assumptions (List [[Type Type] Bool])) (type: #export (Check a) - (-> Type-Context (R;Result [Type-Context a]))) + (-> Type-Context (E;Error [Type-Context a]))) (type: #export Type-Vars (List [Nat (Maybe Type)])) -(struct: #export _ (F;Functor Check) +(struct: #export _ (Functor Check) (def: (map f fa) (function [context] (case (fa context) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [context' output]) - (#R;Success [context' (f output)]) + (#E;Success [context' output]) + (#E;Success [context' (f output)]) )))) -(struct: #export _ (A;Applicative Check) +(struct: #export _ (Applicative Check) (def: functor Functor) (def: (wrap x) (function [context] - (#R;Success [context x]))) + (#E;Success [context x]))) (def: (apply ff fa) (function [context] (case (ff context) - (#R;Success [context' f]) + (#E;Success [context' f]) (case (fa context') - (#R;Success [context'' a]) - (#R;Success [context'' (f a)]) + (#E;Success [context'' a]) + (#E;Success [context'' (f a)]) - (#R;Error error) - (#R;Error error)) + (#E;Error error) + (#E;Error error)) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) ))) ) @@ -62,20 +62,20 @@ (def: (join ffa) (function [context] (case (ffa context) - (#R;Success [context' fa]) + (#E;Success [context' fa]) (case (fa context') - (#R;Success [context'' a]) - (#R;Success [context'' a]) + (#E;Success [context'' a]) + (#E;Success [context'' a]) - (#R;Error error) - (#R;Error error)) + (#E;Error error) + (#E;Error error)) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) ))) ) -(open Monad "Check/") +(open Monad "check/") (def: (var::get id plist) (-> Nat Type-Vars (Maybe (Maybe Type))) @@ -121,30 +121,30 @@ ## [[Logic]] (def: #export (run context proc) - (All [a] (-> Type-Context (Check a) (R;Result a))) + (All [a] (-> Type-Context (Check a) (E;Error a))) (case (proc context) - (#R;Error error) - (#R;Error error) + (#E;Error error) + (#E;Error error) - (#R;Success [context' output]) - (#R;Success output))) + (#E;Success [context' output]) + (#E;Success output))) (def: (apply-type! t-func t-arg) (-> Type Type (Check Type)) (function [context] (case (type;apply (list t-arg) t-func) #;None - (#R;Error ($_ text/compose "Invalid type application: " (type;to-text t-func) " on " (type;to-text t-arg))) + (#E;Error ($_ text/compose "Invalid type application: " (type;to-text t-func) " on " (type;to-text t-arg))) (#;Some output) - (#R;Success [context output])))) + (#E;Success [context output])))) (def: #export existential {#;doc "A producer of existential types."} (Check [Nat Type]) (function [context] (let [id (get@ #;ex-counter context)] - (#R;Success [(update@ #;ex-counter n.inc context) + (#E;Success [(update@ #;ex-counter n.inc context) [id (#;Ex id)]])))) (def: #export (bound? id) @@ -152,62 +152,62 @@ (function [context] (case (|> context (get@ #;var-bindings) (var::get id)) (#;Some (#;Some _)) - (#R;Success [context true]) + (#E;Success [context true]) (#;Some #;None) - (#R;Success [context false]) + (#E;Success [context false]) #;None - (#R;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) + (#E;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) (def: #export (read id) (-> Nat (Check Type)) (function [context] (case (|> context (get@ #;var-bindings) (var::get id)) (#;Some (#;Some type)) - (#R;Success [context type]) + (#E;Success [context type]) (#;Some #;None) - (#R;Error ($_ text/compose "Unbound type-var: " (nat/encode id))) + (#E;Error ($_ text/compose "Unbound type-var: " (nat/encode id))) #;None - (#R;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) + (#E;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) (def: #export (write id type) (-> Nat Type (Check Unit)) (function [context] (case (|> context (get@ #;var-bindings) (var::get id)) (#;Some (#;Some bound)) - (#R;Error ($_ text/compose "Cannot rebind type-var: " (nat/encode id) " | Current type: " (type;to-text bound))) + (#E;Error ($_ text/compose "Cannot rebind type-var: " (nat/encode id) " | Current type: " (type;to-text bound))) (#;Some #;None) - (#R;Success [(update@ #;var-bindings (var::put id (#;Some type)) context) + (#E;Success [(update@ #;var-bindings (var::put id (#;Some type)) context) []]) #;None - (#R;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) + (#E;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) (def: (update id type) (-> Nat Type (Check Unit)) (function [context] (case (|> context (get@ #;var-bindings) (var::get id)) (#;Some _) - (#R;Success [(update@ #;var-bindings (var::put id (#;Some type)) context) + (#E;Success [(update@ #;var-bindings (var::put id (#;Some type)) context) []]) #;None - (#R;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) + (#E;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) (def: #export (clear id) (-> Nat (Check Unit)) (function [context] (case (|> context (get@ #;var-bindings) (var::get id)) (#;Some _) - (#R;Success [(update@ #;var-bindings (var::put id #;None) context) + (#E;Success [(update@ #;var-bindings (var::put id #;None) context) []]) #;None - (#R;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) + (#E;Error ($_ text/compose "Unknown type-var: " (nat/encode id)))))) (def: #export (clean t-id type) (-> Nat Type (Check Type)) @@ -243,7 +243,7 @@ (#;Host name params) (do Monad - [=params (M;map @ (clean t-id) params)] + [=params (monad;map @ (clean t-id) params)] (wrap (#;Host name =params))) (^template [] @@ -260,7 +260,7 @@ (^template [] ( env body) (do Monad - [=env (M;map @ (clean t-id) env) + [=env (monad;map @ (clean t-id) env) =body (clean t-id body)] ## TODO: DO NOT CLEAN THE BODY (wrap ( =env =body)))) ([#;UnivQ] @@ -274,7 +274,7 @@ (Check [Nat Type]) (function [context] (let [id (get@ #;var-counter context)] - (#R;Success [(|> context + (#E;Success [(|> context (update@ #;var-counter n.inc) (update@ #;var-bindings (var::put id #;None))) [id (#;Var id)]])))) @@ -282,19 +282,19 @@ (def: get-bindings (Check (List [Nat (Maybe Type)])) (function [context] - (#R;Success [context + (#E;Success [context (get@ #;var-bindings context)]))) (def: (set-bindings value) (-> (List [Nat (Maybe Type)]) (Check Unit)) (function [context] - (#R;Success [(set@ #;var-bindings value context) + (#E;Success [(set@ #;var-bindings value context) []]))) (def: #export (delete id) (-> Nat (Check Unit)) (function [context] - (#R;Success [(update@ #;var-bindings (var::remove id) context) + (#E;Success [(update@ #;var-bindings (var::remove id) context) []]))) (def: #export (with k) @@ -316,16 +316,16 @@ (All [a] (-> (Check a) (Check (Maybe a)))) (function [context] (case (op context) - (#R;Success [context' output]) - (#R;Success [context' (#;Some output)]) + (#E;Success [context' output]) + (#E;Success [context' (#;Some output)]) - (#R;Error _) - (#R;Success [context #;None])))) + (#E;Error _) + (#E;Success [context #;None])))) (def: #export (fail message) (All [a] (-> Text (Check a))) (function [context] - (#R;Error message))) + (#E;Error message))) (def: (fail-check expected actual) (All [a] (-> Type Type (Check a))) @@ -337,18 +337,18 @@ (All [a] (-> (Check a) (Check a) (Check a))) (function [context] (case (left context) - (#R;Success [context' output]) - (#R;Success [context' output]) + (#E;Success [context' output]) + (#E;Success [context' output]) - (#R;Error _) + (#E;Error _) (right context)))) (def: (assumed? [e a] assumptions) (-> [Type Type] Assumptions (Maybe Bool)) (:: Monad map product;right (list;find (function [[[fe fa] status]] - (and (Type/= e fe) - (Type/= a fa))) + (and (type/= e fe) + (type/= a fa))) assumptions))) (def: (assume! ea status assumptions) @@ -370,11 +370,11 @@ {#;doc "Type-check to ensure that the 'expected' type subsumes the 'actual' type."} (-> Type Type Assumptions (Check Assumptions)) (if (is expected actual) - (Check/wrap assumptions) + (check/wrap assumptions) (case [expected actual] [(#;Var e-id) (#;Var a-id)] (if (n.= e-id a-id) - (Check/wrap assumptions) + (check/wrap assumptions) (do Monad [ebound (attempt (read e-id)) abound (attempt (read a-id))] @@ -394,12 +394,12 @@ (check' etype atype assumptions)))) [(#;Var id) _] - (on id actual (Check/wrap assumptions) + (on id actual (check/wrap assumptions) (function [bound] (check' bound actual assumptions))) [_ (#;Var id)] - (on id expected (Check/wrap assumptions) + (on id expected (check/wrap assumptions) (function [bound] (check' expected bound assumptions))) @@ -433,7 +433,7 @@ (case (assumed? fx-pair assumptions) (#;Some ?) (if ? - (Check/wrap assumptions) + (check/wrap assumptions) (fail-check expected actual)) #;None @@ -459,7 +459,7 @@ [actual' (apply-type! actual var) assumptions (check' expected actual' assumptions) _ (clean var-id expected)] - (Check/wrap assumptions)))) + (check/wrap assumptions)))) [(#;ExQ e!env e!def) _] (with @@ -468,7 +468,7 @@ [expected' (apply-type! expected var) assumptions (check' expected' actual assumptions) _ (clean var-id actual)] - (Check/wrap assumptions)))) + (check/wrap assumptions)))) [_ (#;ExQ a!env a!def)] (do Monad @@ -481,16 +481,16 @@ (n.= (list;size e-params) (list;size a-params))) (do Monad - [assumptions (M;fold Monad - (function [[e a] assumptions] (check' e a assumptions)) - assumptions - (list;zip2 e-params a-params))] - (Check/wrap assumptions)) + [assumptions (monad;fold Monad + (function [[e a] assumptions] (check' e a assumptions)) + assumptions + (list;zip2 e-params a-params))] + (check/wrap assumptions)) (fail-check expected actual)) (^template [ ] [ ] - (Check/wrap assumptions) + (check/wrap assumptions) [( eL eR) ( aL aR)] (do Monad @@ -506,7 +506,7 @@ [(#;Ex e!id) (#;Ex a!id)] (if (n.= e!id a!id) - (Check/wrap assumptions) + (check/wrap assumptions) (fail-check expected actual)) [(#;Named _ ?etype) _] @@ -529,13 +529,13 @@ {#;doc "A simple type-checking function that just returns a yes/no answer."} (-> Type Type Bool) (case (run fresh-context (check expected actual)) - (#R;Error error) + (#E;Error error) false - (#R;Success _) + (#E;Success _) true)) (def: #export get-context (Check Type-Context) (function [context] - (#R;Success [context context]))) + (#E;Success [context context]))) diff --git a/stdlib/source/lux/type/opaque.lux b/stdlib/source/lux/type/opaque.lux index b58e8d32e..00a27333a 100644 --- a/stdlib/source/lux/type/opaque.lux +++ b/stdlib/source/lux/type/opaque.lux @@ -4,7 +4,7 @@ [monad #+ do Monad] ["p" parser]) (data [text "text/" Eq Monoid] - ["R" result] + ["E" error] (coll [list "list/" Functor Monoid])) [macro] (macro [code] @@ -91,7 +91,7 @@ _ (macro;fail ($_ text/compose "Wrong syntax for " up-cast))))]))))]] (function [compiler] - (#R;Success [(update@ #;modules (put this-module-name this-module) compiler) + (#E;Success [(update@ #;modules (put this-module-name this-module) compiler) []])))) (def: (un-install-casts' this-module-name) @@ -102,7 +102,7 @@ (update@ #;defs (remove down-cast)) (update@ #;defs (remove up-cast)))]] (function [compiler] - (#R;Success [(update@ #;modules (put this-module-name this-module) compiler) + (#E;Success [(update@ #;modules (put this-module-name this-module) compiler) []])))) (syntax: #hidden (install-casts [name s;local-symbol] diff --git a/stdlib/source/lux/world/blob.jvm.lux b/stdlib/source/lux/world/blob.jvm.lux index 4d35a5658..88efc1859 100644 --- a/stdlib/source/lux/world/blob.jvm.lux +++ b/stdlib/source/lux/world/blob.jvm.lux @@ -5,7 +5,7 @@ [eq]) (data [bit] [maybe] - ["R" result] + ["E" error] text/format) [host])) @@ -31,23 +31,23 @@ (host;array byte size)) (def: #export (read-8 idx blob) - (-> Nat Blob (R;Result Nat)) + (-> Nat Blob (E;Error Nat)) (if (n.< (host;array-length blob) idx) - (|> (host;array-read idx blob) byte-to-nat #R;Success) + (|> (host;array-read idx blob) byte-to-nat #E;Success) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (read-16 idx blob) - (-> Nat Blob (R;Result Nat)) + (-> Nat Blob (E;Error Nat)) (if (n.< (host;array-length blob) (n.+ +1 idx)) - (#R;Success ($_ bit;or + (#E;Success ($_ bit;or (bit;shift-left +8 (byte-to-nat (host;array-read idx blob))) (byte-to-nat (host;array-read (n.+ +1 idx) blob)))) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (read-32 idx blob) - (-> Nat Blob (R;Result Nat)) + (-> Nat Blob (E;Error Nat)) (if (n.< (host;array-length blob) (n.+ +3 idx)) - (#R;Success ($_ bit;or + (#E;Success ($_ bit;or (bit;shift-left +24 (byte-to-nat (host;array-read idx blob))) (bit;shift-left +16 (byte-to-nat (host;array-read (n.+ +1 idx) blob))) (bit;shift-left +8 (byte-to-nat (host;array-read (n.+ +2 idx) blob))) @@ -55,9 +55,9 @@ (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (read-64 idx blob) - (-> Nat Blob (R;Result Nat)) + (-> Nat Blob (E;Error Nat)) (if (n.< (host;array-length blob) (n.+ +7 idx)) - (#R;Success ($_ bit;or + (#E;Success ($_ bit;or (bit;shift-left +56 (byte-to-nat (host;array-read idx blob))) (bit;shift-left +48 (byte-to-nat (host;array-read (n.+ +1 idx) blob))) (bit;shift-left +40 (byte-to-nat (host;array-read (n.+ +2 idx) blob))) @@ -69,35 +69,35 @@ (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-8 idx value blob) - (-> Nat Nat Blob (R;Result Unit)) + (-> Nat Nat Blob (E;Error Unit)) (if (n.< (host;array-length blob) idx) (exec (|> blob (host;array-write idx (host;l2b (:! Int value)))) - (#R;Success [])) + (#E;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-16 idx value blob) - (-> Nat Nat Blob (R;Result Unit)) + (-> Nat Nat Blob (E;Error Unit)) (if (n.< (host;array-length blob) (n.+ +1 idx)) (exec (|> blob (host;array-write idx (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n.+ +1 idx) (host;l2b (:! Int value)))) - (#R;Success [])) + (#E;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-32 idx value blob) - (-> Nat Nat Blob (R;Result Unit)) + (-> Nat Nat Blob (E;Error Unit)) (if (n.< (host;array-length blob) (n.+ +3 idx)) (exec (|> blob (host;array-write idx (host;l2b (:! Int (bit;shift-right +24 value)))) (host;array-write (n.+ +1 idx) (host;l2b (:! Int (bit;shift-right +16 value)))) (host;array-write (n.+ +2 idx) (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n.+ +3 idx) (host;l2b (:! Int value)))) - (#R;Success [])) + (#E;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-64 idx value blob) - (-> Nat Nat Blob (R;Result Unit)) + (-> Nat Nat Blob (E;Error Unit)) (if (n.< (host;array-length blob) (n.+ +7 idx)) (exec (|> blob (host;array-write idx (host;l2b (:! Int (bit;shift-right +56 value)))) @@ -108,7 +108,7 @@ (host;array-write (n.+ +5 idx) (host;l2b (:! Int (bit;shift-right +16 value)))) (host;array-write (n.+ +6 idx) (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n.+ +7 idx) (host;l2b (:! Int value)))) - (#R;Success [])) + (#E;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (size blob) @@ -116,7 +116,7 @@ (host;array-length blob)) (def: #export (slice from to blob) - (-> Nat Nat Blob (R;Result Blob)) + (-> Nat Nat Blob (E;Error Blob)) (with-expansions [ (as-is (format "from = " (%n from) " | " "to = " (%n to)))] (let [size (host;array-length blob)] (cond (not (n.<= to from)) @@ -127,10 +127,10 @@ (ex;throw Index-Out-Of-Bounds ) ## else - (#R;Success (Arrays.copyOfRange [blob (:! Int from) (:! Int (n.inc to))])))))) + (#E;Success (Arrays.copyOfRange [blob (:! Int from) (:! Int (n.inc to))])))))) (def: #export (slice' from blob) - (-> Nat Blob (R;Result Blob)) + (-> Nat Blob (E;Error Blob)) (slice from (n.dec (host;array-length blob)) blob)) (struct: #export _ (eq;Eq Blob) diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 4c0881e04..1c968b888 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -4,7 +4,7 @@ ["ex" exception #+ exception:]) (concurrency ["P" promise] ["T" task]) - (data ["R" result] + (data ["E" error] (coll [array])) (time ["i" instant] ["d" duration]) @@ -52,7 +52,7 @@ (do-template [ ] [(def: #export ( data file) (-> Blob File (T;Task Unit)) - (P;future (do (R;ResultT io;Monad) + (P;future (do (E;ErrorT io;Monad) [stream (FileOutputStream.new [(java.io.File.new file) ]) _ (OutputStream.write [data] stream) _ (OutputStream.flush [] stream)] @@ -64,7 +64,7 @@ (def: #export (read file) (-> File (T;Task Blob)) - (P;future (do (R;ResultT io;Monad) + (P;future (do (E;ErrorT io;Monad) [#let [file' (java.io.File.new file)] size (java.io.File.length [] file') #let [data (blob;create (int-to-nat size))] @@ -77,13 +77,13 @@ (def: #export (size file) (-> File (T;Task Nat)) - (P;future (do (R;ResultT io;Monad) + (P;future (do (E;ErrorT io;Monad) [size (java.io.File.length [] (java.io.File.new file))] (wrap (int-to-nat size))))) (def: #export (files dir) (-> File (T;Task (List File))) - (P;future (do (R;ResultT io;Monad) + (P;future (do (E;ErrorT io;Monad) [files (java.io.File.listFiles [] (java.io.File.new dir))] (monad;map @ (java.io.File.getAbsolutePath []) (array;to-list files))))) @@ -110,7 +110,7 @@ (def: #export (get-last-modified file) (-> File (T;Task i;Instant)) - (P;future (do (R;ResultT io;Monad) + (P;future (do (E;ErrorT io;Monad) [millis (java.io.File.lastModified [] (java.io.File.new file))] (wrap (|> millis d;from-millis i;absolute))))) diff --git a/stdlib/source/lux/world/net/tcp.jvm.lux b/stdlib/source/lux/world/net/tcp.jvm.lux index fec65e387..e8832b67e 100644 --- a/stdlib/source/lux/world/net/tcp.jvm.lux +++ b/stdlib/source/lux/world/net/tcp.jvm.lux @@ -4,7 +4,7 @@ (concurrency ["P" promise] ["T" task] [frp]) - (data ["R" result]) + (data ["E" error]) (type opaque) (world [blob #+ Blob]) [io] @@ -44,7 +44,7 @@ (def: #export (read data offset length self) (let [in (get@ #in (@repr self))] (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [bytes-read (InputStream.read [data (nat-to-int offset) (nat-to-int length)] in)] (wrap (int-to-nat bytes-read)))))) @@ -52,7 +52,7 @@ (def: #export (write data offset length self) (let [out (get@ #out (@repr self))] (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [_ (OutputStream.write [data (nat-to-int offset) (nat-to-int length)] out)] (Flushable.flush [] out))))) @@ -60,14 +60,14 @@ (def: #export (close self) (let [(^open) (@repr self)] (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [_ (AutoCloseable.close [] in) _ (AutoCloseable.close [] out)] (AutoCloseable.close [] socket))))) (def: (tcp-client socket) - (-> Socket (io;IO (R;Result TCP))) - (do (R;ResultT io;Monad) + (-> Socket (io;IO (E;Error TCP))) + (do (E;ErrorT io;Monad) [input (Socket.getInputStream [] socket) output (Socket.getOutputStream [] socket)] (wrap (@opaque {#socket socket @@ -77,7 +77,7 @@ (def: #export (client address port) (-> ..;Address ..;Port (T;Task TCP)) (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [socket (Socket.new [address (nat-to-int port)])] (tcp-client socket)))) @@ -102,21 +102,21 @@ (def: #export (server port) (-> ..;Port (T;Task (frp;Channel TCP))) (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [server (ServerSocket.new [(nat-to-int port)]) #let [output (frp;channel TCP) _ (: (P;Promise Bool) (P;future (loop [tail output] (do io;Monad - [?client (do (R;ResultT io;Monad) + [?client (do (E;ErrorT io;Monad) [socket (ServerSocket.accept [] server)] (tcp-client socket))] (case ?client - (#R;Error error) + (#E;Error error) (frp;close tail) - (#R;Success client) + (#E;Success client) (do @ [?tail' (frp;write client tail)] (case ?tail' diff --git a/stdlib/source/lux/world/net/udp.jvm.lux b/stdlib/source/lux/world/net/udp.jvm.lux index 89eaba448..29be4a920 100644 --- a/stdlib/source/lux/world/net/udp.jvm.lux +++ b/stdlib/source/lux/world/net/udp.jvm.lux @@ -5,7 +5,7 @@ (concurrency ["P" promise] ["T" task] [frp]) - (data ["R" result] + (data ["E" error] [maybe] (coll [array])) (type opaque) @@ -45,10 +45,10 @@ (exception: #export Multiple-Candidate-Addresses) (def: (resolve address) - (-> ..;Address (io;IO (R;Result InetAddress))) - (do (R;ResultT io;Monad) + (-> ..;Address (io;IO (E;Error InetAddress))) + (do (E;ErrorT io;Monad) [addresses (InetAddress.getAllByName [address])] - (: (io;IO (R;Result InetAddress)) + (: (io;IO (E;Error InetAddress)) (case (array;size addresses) +0 (io;io (ex;throw Cannot-Resolve-Address address)) +1 (wrap (maybe;assume (array;read +0 addresses))) @@ -62,7 +62,7 @@ (let [(^open) (@repr self) packet (DatagramPacket.new|receive [data (nat-to-int offset) (nat-to-int length)])] (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [_ (DatagramSocket.receive [packet] socket) #let [bytes-read (int-to-nat (DatagramPacket.getLength [] packet))]] (wrap [bytes-read @@ -72,7 +72,7 @@ (def: #export (write address port data offset length self) (-> ..;Address ..;Port Blob Nat Nat UDP (T;Task Unit)) (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [address (resolve address) #let [(^open) (@repr self)]] (DatagramSocket.send (DatagramPacket.new|send [data (nat-to-int offset) (nat-to-int length) address (nat-to-int port)]) @@ -87,14 +87,14 @@ (def: #export (client _) (-> Unit (T;Task UDP)) (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [socket (DatagramSocket.new|client [])] (wrap (@opaque (#socket socket)))))) (def: #export (server port) (-> ..;Port (T;Task UDP)) (P;future - (do (R;ResultT io;Monad) + (do (E;ErrorT io;Monad) [socket (DatagramSocket.new|server [(nat-to-int port)])] (wrap (@opaque (#socket socket)))))) ) diff --git a/stdlib/test/test/lux.lux b/stdlib/test/test/lux.lux index 546d7f14f..5ff53793c 100644 --- a/stdlib/test/test/lux.lux +++ b/stdlib/test/test/lux.lux @@ -4,7 +4,7 @@ (lux (control ["M" monad #+ do Monad]) [io] [math] - ["R" math/random] + ["r" math/random] (data [maybe] [text "T/" Eq] text/format) @@ -12,9 +12,9 @@ (macro ["s" syntax #+ syntax:]))) (context: "Value identity." - [size (|> R;nat (:: @ map (|>. (n.% +100) (n.max +10)))) - x (R;text size) - y (R;text size)] + [size (|> r;nat (:: @ map (|>. (n.% +100) (n.max +10)))) + x (r;text size) + y (r;text size)] ($_ seq (test "Every value is identical to itself, and the 'id' function doesn't change values in any way." (and (is x x) @@ -44,8 +44,8 @@ (and (|> value inc even?) (|> value dec even?)))))] - ["Nat" R;nat n.inc n.dec n.even? n.odd? n.= n.< n.>] - ["Int" R;int i.inc i.dec i.even? i.odd? i.= i.< i.>] + ["Nat" r;nat n.inc n.dec n.even? n.odd? n.= n.< n.>] + ["Int" r;int i.inc i.dec i.even? i.odd? i.= i.< i.>] ) (do-template [category rand-gen = < > <= >= min max] @@ -68,10 +68,10 @@ (>= y (max x y))) )))] - ["Int" R;int i.= i.< i.> i.<= i.>= i.min i.max] - ["Nat" R;nat n.= n.< n.> n.<= n.>= n.min n.max] - ["Frac" R;frac f.= f.< f.> f.<= f.>= f.min f.max] - ["Deg" R;deg d.= d.< d.> d.<= d.>= d.min d.max] + ["Int" r;int i.= i.< i.> i.<= i.>= i.min i.max] + ["Nat" r;nat n.= n.< n.> n.<= n.>= n.min n.max] + ["Frac" r;frac f.= f.< f.> f.<= f.>= f.min f.max] + ["Deg" r;deg d.= d.< d.> d.<= d.>= d.min d.max] ) (do-template [category rand-gen = + - * / <%> > <0> <1> %x ] @@ -104,7 +104,7 @@ [x (:: @ map rand-gen) y (|> rand-gen (:: @ map ) - (R;filter (|>. (= <0>) not))) + (r;filter (|>. (= <0>) not))) #let [r (<%> y x) x' (- r x)]] (test "" @@ -116,10 +116,10 @@ (|> x' (/ y) (* y) (= x')))) ))] - ["Nat" R;nat n.= n.+ n.- n.* n./ n.% n.> +0 +1 +1000000 %n (n.% +1000) id] - ["Int" R;int i.= i.+ i.- i.* i./ i.% i.> 0 1 1000000 %i (i.% 1000) id] - ["Frac" R;frac f.= f.+ f.- f.* f./ f.% f.> 0.0 1.0 1000000.0 %r id math;floor] - ["Deg" R;deg d.= d.+ d.- d.* d./ d.% d.> .0 (_lux_proc ["deg" "max-value"] []) (_lux_proc ["deg" "max-value"] []) %f id id] + ["Nat" r;nat n.= n.+ n.- n.* n./ n.% n.> +0 +1 +1000000 %n (n.% +1000) id] + ["Int" r;int i.= i.+ i.- i.* i./ i.% i.> 0 1 1000000 %i (i.% 1000) id] + ["Frac" r;frac f.= f.+ f.- f.* f./ f.% f.> 0.0 1.0 1000000.0 %r id math;floor] + ["Deg" r;deg d.= d.+ d.- d.* d./ d.% d.> .0 (_lux_proc ["deg" "max-value"] []) (_lux_proc ["deg" "max-value"] []) %f id id] ) (do-template [category rand-gen -> <- = %a %z] @@ -129,11 +129,11 @@ (test "" (|> value -> <- (= value))))] - ["Int->Nat" R;int int-to-nat nat-to-int i.= (i.% 1000000) %i %n] - ["Nat->Int" R;nat nat-to-int int-to-nat n.= (n.% +1000000) %n %i] - ["Int->Frac" R;int int-to-frac frac-to-int i.= (i.% 1000000) %i %r] - ["Frac->Int" R;frac frac-to-int int-to-frac f.= math;floor %r %i] - ## [R;frac frac-to-deg deg-to-frac f.= (f.% 1.0) %r %f] + ["Int->Nat" r;int int-to-nat nat-to-int i.= (i.% 1000000) %i %n] + ["Nat->Int" r;nat nat-to-int int-to-nat n.= (n.% +1000000) %n %i] + ["Int->Frac" r;int int-to-frac frac-to-int i.= (i.% 1000000) %i %r] + ["Frac->Int" r;frac frac-to-int int-to-frac f.= math;floor %r %i] + ## [r;frac frac-to-deg deg-to-frac f.= (f.% 1.0) %r %f] ) (context: "Simple macros and constructs" @@ -173,8 +173,8 @@ (i.+ (i.* x x) (i.* y y))) (context: "Templates" - [x R;int - y R;int] + [x r;int + y r;int] (test "Template application is a stand-in for the templated code." (i.= (i.+ (i.* x x) (i.* y y)) (hypotenuse x y)))) diff --git a/stdlib/test/test/lux/cli.lux b/stdlib/test/test/lux/cli.lux index fb7301359..6c6b113ea 100644 --- a/stdlib/test/test/lux/cli.lux +++ b/stdlib/test/test/lux/cli.lux @@ -11,14 +11,14 @@ [sum] (coll [list])) ["&" cli] - ["R" math/random]) + ["r" math/random]) lux/test) (context: "CLI" - [num-args (|> R;nat (:: @ map (n.% +10))) + [num-args (|> r;nat (:: @ map (n.% +10))) #let [(^open "Nat/") number;Codec - gen-arg (:: @ map Nat/encode R;nat)] - option-name (R;text +5) + gen-arg (:: @ map Nat/encode r;nat)] + option-name (r;text +5) singleton gen-arg] ($_ seq (test "Can read any argument." diff --git a/stdlib/test/test/lux/concurrency/actor.lux b/stdlib/test/test/lux/concurrency/actor.lux index 41618cb64..f5d230833 100644 --- a/stdlib/test/test/lux/concurrency/actor.lux +++ b/stdlib/test/test/lux/concurrency/actor.lux @@ -5,7 +5,7 @@ ["ex" exception]) (data [number] text/format - ["R" result]) + ["E" error]) (concurrency ["P" promise "P/" Monad] ["T" task] ["&" actor #+ actor: message:])) @@ -79,9 +79,9 @@ (n.= +3 output-3))))] (test "Can send messages to actors." (case result - (#R;Success outcome) + (#E;Success outcome) outcome - (#R;Error error) + (#E;Error error) false))) )) diff --git a/stdlib/test/test/lux/concurrency/atom.lux b/stdlib/test/test/lux/concurrency/atom.lux index d841a4e84..538e7d676 100644 --- a/stdlib/test/test/lux/concurrency/atom.lux +++ b/stdlib/test/test/lux/concurrency/atom.lux @@ -6,13 +6,13 @@ (coll [list "" Functor]) text/format) (concurrency ["&" atom]) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Atoms" - [value R;nat - swap-value R;nat - set-value R;nat + [value r;nat + swap-value r;nat + set-value r;nat #let [box (&;atom value)]] ($_ seq (test "Can obtain the value of an atom." diff --git a/stdlib/test/test/lux/concurrency/promise.lux b/stdlib/test/test/lux/concurrency/promise.lux index 21e2aa7db..7b8f3fdd3 100644 --- a/stdlib/test/test/lux/concurrency/promise.lux +++ b/stdlib/test/test/lux/concurrency/promise.lux @@ -6,7 +6,7 @@ (data [number] text/format) (concurrency ["&" promise "&/" Monad]) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Promises" diff --git a/stdlib/test/test/lux/concurrency/stm.lux b/stdlib/test/test/lux/concurrency/stm.lux index ade1700b5..52361b85a 100644 --- a/stdlib/test/test/lux/concurrency/stm.lux +++ b/stdlib/test/test/lux/concurrency/stm.lux @@ -8,7 +8,7 @@ text/format) (concurrency ["&" stm] [promise]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: iterations/processes Int 100) diff --git a/stdlib/test/test/lux/control/cont.lux b/stdlib/test/test/lux/control/cont.lux index 926525942..ea86ccb05 100644 --- a/stdlib/test/test/lux/control/cont.lux +++ b/stdlib/test/test/lux/control/cont.lux @@ -8,13 +8,13 @@ [number] [product] (coll [list])) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Continuations" - [sample R;nat + [sample r;nat #let [(^open "&/") &;Monad] - elems (R;list +3 R;nat)] + elems (r;list +3 r;nat)] ($_ seq (test "Can run continuations to compute their values." (n.= sample (&;run (&/wrap sample)))) diff --git a/stdlib/test/test/lux/control/exception.lux b/stdlib/test/test/lux/control/exception.lux index 5680b95f1..fc552b69c 100644 --- a/stdlib/test/test/lux/control/exception.lux +++ b/stdlib/test/test/lux/control/exception.lux @@ -3,11 +3,11 @@ (lux [io] (control ["M" monad #+ do Monad] ["&" exception #+ exception:]) - (data ["E" result] + (data ["E" error] [text] text/format [number]) - ["R" math/random]) + ["r" math/random]) lux/test) (exception: Some-Exception) @@ -17,13 +17,13 @@ (exception: Unknown-Exception) (context: "Exceptions" - [should-throw? R;bool - which? R;bool - should-catch? R;bool - default-val R;nat - some-val R;nat - another-val R;nat - otherwise-val R;nat + [should-throw? r;bool + which? r;bool + should-catch? r;bool + default-val r;nat + some-val r;nat + another-val r;nat + otherwise-val r;nat #let [this-ex (if should-catch? (if which? Some-Exception @@ -36,7 +36,7 @@ another-val) otherwise-val) default-val) - actual (|> (: (E;Result Nat) + actual (|> (: (E;Error Nat) (if should-throw? (&;throw this-ex "Uh-oh...") (&;return default-val))) diff --git a/stdlib/test/test/lux/control/interval.lux b/stdlib/test/test/lux/control/interval.lux index 8cf46012c..2ba5198bc 100644 --- a/stdlib/test/test/lux/control/interval.lux +++ b/stdlib/test/test/lux/control/interval.lux @@ -5,15 +5,15 @@ pipe ["&" interval]) [io] - ["R" math/random] + ["r" math/random] (data text/format [number] ["S" coll/set] ["L" coll/list]))) (context: "Equality." - [bottom R;int - top R;int + [bottom r;int + top r;int #let [(^open "&/") &;Eq]] ($_ seq (test "Every interval is equal to itself." @@ -25,8 +25,8 @@ (&/= self self)))))) (context: "Boundaries" - [bottom R;int - top R;int + [bottom r;int + top r;int #let [interval (&;between number;Enum bottom top)]] ($_ seq (test "Every boundary value belongs to it's interval." @@ -53,10 +53,10 @@ (do-template [ ] [(def: - (R;Random (&;Interval Int)) - (do R;Monad - [bottom R;int - top (|> R;int (R;filter (|>. (i.= bottom) not)))] + (r;Random (&;Interval Int)) + (do r;Monad + [bottom r;int + top (|> r;int (r;filter (|>. (i.= bottom) not)))] (if ( top bottom) (wrap (&;between number;Enum bottom top)) (wrap (&;between number;Enum top bottom)))))] @@ -66,14 +66,14 @@ ) (def: gen-singleton - (R;Random (&;Interval Int)) - (do R;Monad - [point R;int] + (r;Random (&;Interval Int)) + (do r;Monad + [point r;int] (wrap (&;singleton number;Enum point)))) (def: gen-interval - (R;Random (&;Interval Int)) - ($_ R;either + (r;Random (&;Interval Int)) + ($_ r;either gen-inner gen-outer gen-singleton)) @@ -129,7 +129,7 @@ )) (context: "Positioning/location" - [[l m r] (|> (R;set number;Hash +3 R;int) + [[l m r] (|> (r;set number;Hash +3 r;int) (:: @ map (|>. S;to-list (L;sort i.<) (case> (^ (list b t1 t2)) @@ -149,7 +149,7 @@ )) (context: "Touching intervals" - [[b t1 t2] (|> (R;set number;Hash +3 R;int) + [[b t1 t2] (|> (r;set number;Hash +3 r;int) (:: @ map (|>. S;to-list (L;sort i.<) (case> (^ (list b t1 t2)) @@ -174,7 +174,7 @@ (context: "Nesting & overlap" [some-interval gen-interval - [x0 x1 x2 x3] (|> (R;set number;Hash +4 R;int) + [x0 x1 x2 x3] (|> (r;set number;Hash +4 r;int) (:: @ map (|>. S;to-list (L;sort i.<) (case> (^ (list x0 x1 x2 x3)) diff --git a/stdlib/test/test/lux/control/parser.lux b/stdlib/test/test/lux/control/parser.lux index ae3fc2041..0f6b4a4b1 100644 --- a/stdlib/test/test/lux/control/parser.lux +++ b/stdlib/test/test/lux/control/parser.lux @@ -10,7 +10,7 @@ [number] [bool] [ident] - ["R" result]) + ["E" error]) ["r" math/random] [macro] (macro [code] @@ -19,15 +19,15 @@ ## [Utils] (def: (should-fail input) - (All [a] (-> (R;Result a) Bool)) + (All [a] (-> (E;Error a) Bool)) (case input - (#R;Error _) true + (#E;Error _) true _ false)) (def: (enforced? parser input) (All [s] (-> (&;Parser s Unit) s Bool)) (case (&;run input parser) - (#R;Success [_ []]) + (#E;Success [_ []]) true _ @@ -36,7 +36,7 @@ (def: (found? parser input) (All [s] (-> (&;Parser s Bool) s Bool)) (case (&;run input parser) - (#R;Success [_ true]) + (#E;Success [_ true]) true _ @@ -45,16 +45,16 @@ (def: (is? Eq test parser input) (All [s a] (-> (Eq a) a (&;Parser s a) s Bool)) (case (&;run input parser) - (#R;Success [_ output]) + (#E;Success [_ output]) (:: Eq = test output) _ false)) (def: (fails? input) - (All [a] (-> (R;Result a) Bool)) + (All [a] (-> (E;Error a) Bool)) (case input - (#R;Error _) + (#E;Error _) true _ @@ -62,7 +62,7 @@ (syntax: (match pattern input) (wrap (list (` (case (~ input) - (^ (#R;Success [(~' _) (~ pattern)])) + (^ (#E;Success [(~' _) (~ pattern)])) true (~' _) diff --git a/stdlib/test/test/lux/control/pipe.lux b/stdlib/test/test/lux/control/pipe.lux index 37f76e9af..23e6cfe60 100644 --- a/stdlib/test/test/lux/control/pipe.lux +++ b/stdlib/test/test/lux/control/pipe.lux @@ -8,7 +8,7 @@ [product] identity [text "T/" Eq]) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Pipes" diff --git a/stdlib/test/test/lux/control/state.lux b/stdlib/test/test/lux/control/state.lux index 87731de60..1447e61c3 100644 --- a/stdlib/test/test/lux/control/state.lux +++ b/stdlib/test/test/lux/control/state.lux @@ -8,7 +8,7 @@ text/format [number] [product]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: (with-conditions [state output] computation) @@ -19,8 +19,8 @@ (n.= output))) (context: "Basics" - [state R;nat - value R;nat] + [state r;nat + value r;nat] ($_ seq (test "Can get the state as a value." (with-conditions [state state] @@ -45,8 +45,8 @@ )) (context: "Structures" - [state R;nat - value R;nat] + [state r;nat + value r;nat] ($_ seq (test "Can use functor." (with-conditions [state (n.inc state)] @@ -69,9 +69,9 @@ )) (context: "Monad transformer" - [state R;nat - left R;nat - right R;nat] + [state r;nat + left r;nat + right r;nat] (let [(^open "io/") io;Monad] (test "Can add state functionality to any monad." (|> (: (&;State' io;IO Nat Nat) @@ -87,7 +87,7 @@ )) (context: "Loops" - [limit (|> R;nat (:: @ map (n.% +10))) + [limit (|> r;nat (:: @ map (n.% +10))) #let [condition (do &;Monad [state &;get] (wrap (n.< limit state)))]] diff --git a/stdlib/test/test/lux/data/bit.lux b/stdlib/test/test/lux/data/bit.lux index 53bebe088..8bbe8e599 100644 --- a/stdlib/test/test/lux/data/bit.lux +++ b/stdlib/test/test/lux/data/bit.lux @@ -4,12 +4,12 @@ (control ["M" monad #+ do Monad]) (data ["&" bit] number) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Bitwise operations." - [pattern R;nat - idx (:: @ map (n.% &;width) R;nat)] + [pattern r;nat + idx (:: @ map (n.% &;width) r;nat)] ($_ seq (test "Clearing and settings bits should alter the count." (and (n.< (&;count (&;set idx pattern)) diff --git a/stdlib/test/test/lux/data/bool.lux b/stdlib/test/test/lux/data/bool.lux index bbc867581..69366a3d2 100644 --- a/stdlib/test/test/lux/data/bool.lux +++ b/stdlib/test/test/lux/data/bool.lux @@ -3,11 +3,11 @@ (lux (control ["M" monad #+ do Monad]) [io] (data bool) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Boolean operations." - [value R;bool] + [value r;bool] (test "" (and (not (and value (not value))) (or value (not value)) diff --git a/stdlib/test/test/lux/data/coll/array.lux b/stdlib/test/test/lux/data/coll/array.lux index d5fde5a64..e32bf2e0f 100644 --- a/stdlib/test/test/lux/data/coll/array.lux +++ b/stdlib/test/test/lux/data/coll/array.lux @@ -7,17 +7,17 @@ [list]) [number] [maybe]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: bounded-size - (R;Random Nat) - (|> R;nat - (:: R;Monad map (|>. (n.% +100) (n.+ +1))))) + (r;Random Nat) + (|> r;nat + (:: r;Monad map (|>. (n.% +100) (n.+ +1))))) (context: "Arrays and their copies" [size bounded-size - original (R;array size R;nat) + original (r;array size r;nat) #let [clone (@;clone original) copy (: (Array Nat) (@;new size)) @@ -49,9 +49,9 @@ (context: "Array mutation" [size bounded-size - idx (:: @ map (n.% size) R;nat) - array (|> (R;array size R;nat) - (R;filter (|>. @;to-list (list;any? n.odd?)))) + idx (:: @ map (n.% size) r;nat) + array (|> (r;array size r;nat) + (r;filter (|>. @;to-list (list;any? n.odd?)))) #let [value (maybe;assume (@;read idx array))]] ($_ seq (test "Shouldn't be able to find a value in an unoccupied cell." @@ -75,8 +75,8 @@ (context: "Finding values." [size bounded-size - array (|> (R;array size R;nat) - (R;filter (|>. @;to-list (list;any? n.even?))))] + array (|> (r;array size r;nat) + (r;filter (|>. @;to-list (list;any? n.even?))))] ($_ seq (test "Can find values inside arrays." (|> (@;find n.even? array) @@ -92,7 +92,7 @@ (context: "Functor" [size bounded-size - array (R;array size R;nat)] + array (r;array size r;nat)] (let [(^open) @;Functor (^open) (@;Eq number;Eq)] ($_ seq @@ -109,8 +109,8 @@ (context: "Monoid" [sizeL bounded-size sizeR bounded-size - left (R;array sizeL R;nat) - right (R;array sizeR R;nat) + left (r;array sizeL r;nat) + right (r;array sizeR r;nat) #let [(^open) @;Monoid (^open) (@;Eq number;Eq) fusion (compose left right)]] diff --git a/stdlib/test/test/lux/data/coll/list.lux b/stdlib/test/test/lux/data/coll/list.lux index a3d091625..2b5146a65 100644 --- a/stdlib/test/test/lux/data/coll/list.lux +++ b/stdlib/test/test/lux/data/coll/list.lux @@ -9,21 +9,21 @@ [bool] [product] [maybe]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: bounded-size - (R;Random Nat) - (|> R;nat - (:: R;Monad map (|>. (n.% +100) (n.+ +10))))) + (r;Random Nat) + (|> r;nat + (:: r;Monad map (|>. (n.% +100) (n.+ +10))))) (context: "Lists: Part 1" [size bounded-size - idx (:: @ map (n.% size) R;nat) - sample (R;list size R;nat) + idx (:: @ map (n.% size) r;nat) + sample (r;list size r;nat) other-size bounded-size - other-sample (R;list other-size R;nat) - separator R;nat + other-sample (r;list other-size r;nat) + separator r;nat #let [(^open) (&;Eq number;Eq) (^open "&/") &;Functor]] ($_ seq @@ -63,11 +63,11 @@ (context: "Lists: Part 2" [size bounded-size - idx (:: @ map (n.% size) R;nat) - sample (R;list size R;nat) + idx (:: @ map (n.% size) r;nat) + sample (r;list size r;nat) other-size bounded-size - other-sample (R;list other-size R;nat) - separator R;nat + other-sample (r;list other-size r;nat) + separator r;nat #let [(^open) (&;Eq number;Eq) (^open "&/") &;Functor]] ($_ seq @@ -122,11 +122,11 @@ (context: "Lists: Part 3" [size bounded-size - idx (:: @ map (n.% size) R;nat) - sample (R;list size R;nat) + idx (:: @ map (n.% size) r;nat) + sample (r;list size r;nat) other-size bounded-size - other-sample (R;list other-size R;nat) - separator R;nat + other-sample (r;list other-size r;nat) + separator r;nat #let [(^open) (&;Eq number;Eq) (^open "&/") &;Functor]] ($_ seq diff --git a/stdlib/test/test/lux/data/coll/priority-queue.lux b/stdlib/test/test/lux/data/coll/priority-queue.lux index 51b9aee5e..07a2200a3 100644 --- a/stdlib/test/test/lux/data/coll/priority-queue.lux +++ b/stdlib/test/test/lux/data/coll/priority-queue.lux @@ -5,25 +5,25 @@ (data (coll ["&" priority-queue]) [number] [maybe]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: (gen-queue size) - (-> Nat (R;Random (&;Queue Nat))) - (do R;Monad - [inputs (R;list size R;nat)] + (-> Nat (r;Random (&;Queue Nat))) + (do r;Monad + [inputs (r;list size r;nat)] (monad;fold @ (function [head tail] (do @ - [priority R;nat] + [priority r;nat] (wrap (&;push priority head tail)))) &;empty inputs))) (context: "Queues" - [size (|> R;nat (:: @ map (n.% +100))) + [size (|> r;nat (:: @ map (n.% +100))) sample (gen-queue size) - non-member-priority R;nat - non-member (|> R;nat (R;filter (|>. (&;member? number;Eq sample) not)))] + non-member-priority r;nat + non-member (|> r;nat (r;filter (|>. (&;member? number;Eq sample) not)))] ($_ seq (test "I can query the size of a queue (and empty queues have size 0)." (n.= size (&;size sample))) diff --git a/stdlib/test/test/lux/data/coll/queue.lux b/stdlib/test/test/lux/data/coll/queue.lux index 08c905e95..ddccc282b 100644 --- a/stdlib/test/test/lux/data/coll/queue.lux +++ b/stdlib/test/test/lux/data/coll/queue.lux @@ -4,14 +4,14 @@ (control [monad #+ do Monad]) (data (coll ["&" queue]) [number]) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Queues" - [size (:: @ map (n.% +100) R;nat) - sample (R;queue size R;nat) - non-member (|> R;nat - (R;filter (. not (&;member? number;Eq sample))))] + [size (:: @ map (n.% +100) r;nat) + sample (r;queue size r;nat) + non-member (|> r;nat + (r;filter (. not (&;member? number;Eq sample))))] ($_ seq (test "I can query the size of a queue (and empty queues have size 0)." (if (n.= +0 size) diff --git a/stdlib/test/test/lux/data/coll/seq.lux b/stdlib/test/test/lux/data/coll/seq.lux index c6d25a0d8..801c5c2f1 100644 --- a/stdlib/test/test/lux/data/coll/seq.lux +++ b/stdlib/test/test/lux/data/coll/seq.lux @@ -11,20 +11,20 @@ [bool] [product] maybe) - ["R" math/random]) + ["r" math/random]) lux/test) (def: bounded-size - (R;Random Nat) - (|> R;nat - (:: R;Monad map (|>. (n.% +100) (n.+ +10) (n.max +1))))) + (r;Random Nat) + (|> r;nat + (:: r;Monad map (|>. (n.% +100) (n.+ +10) (n.max +1))))) (context: "Seqs: Part 1" [size bounded-size - idx (:: @ map (n.% size) R;nat) - sample (|> (R;list size R;nat) + idx (:: @ map (n.% size) r;nat) + sample (|> (r;list size r;nat) (:: @ map &;from-list)) - extra R;nat + extra r;nat #let [(^open "&/") (&;Eq number;Eq)]] ($_ seq (test "Can convert to/from list." @@ -75,7 +75,7 @@ (context: "Seqs: Part 2" [size bounded-size - sample (|> (R;list size R;nat) + sample (|> (r;list size r;nat) (:: @ map &;from-list)) #let [(^open "&/") (&;Eq number;Eq) (^open "&/") &;Functor]] @@ -97,13 +97,13 @@ (context: "Seqs: Part 3" [size bounded-size - idx (:: @ map (n.% size) R;nat) - sample (|> (R;list size R;nat) + idx (:: @ map (n.% size) r;nat) + sample (|> (r;list size r;nat) (:: @ map &;from-list)) other-size bounded-size - other-sample (|> (R;list other-size R;nat) + other-sample (|> (r;list other-size r;nat) (:: @ map &;from-list)) - elem R;nat + elem r;nat #let [(^open "&/") (&;Eq number;Eq) (^open "&/") &;Monad]] ($_ seq diff --git a/stdlib/test/test/lux/data/coll/set.lux b/stdlib/test/test/lux/data/coll/set.lux index 0aafdd580..38ca47f81 100644 --- a/stdlib/test/test/lux/data/coll/set.lux +++ b/stdlib/test/test/lux/data/coll/set.lux @@ -5,21 +5,21 @@ (data (coll ["&" set] [list "" Fold]) [number]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: gen-nat - (R;Random Nat) - (|> R;nat - (:: R;Monad map (n.% +100)))) + (r;Random Nat) + (|> r;nat + (:: r;Monad map (n.% +100)))) (context: "Sets" [sizeL gen-nat sizeR gen-nat - setL (R;set number;Hash sizeL gen-nat) - setR (R;set number;Hash sizeR gen-nat) + setL (r;set number;Hash sizeL gen-nat) + setR (r;set number;Hash sizeR gen-nat) non-member (|> gen-nat - (R;filter (. not (&;member? setL)))) + (r;filter (. not (&;member? setL)))) #let [(^open "&/") &;Eq]] ($_ seq (test "I can query the size of a set." diff --git a/stdlib/test/test/lux/data/coll/stack.lux b/stdlib/test/test/lux/data/coll/stack.lux index 981d73197..fc7e2f4b2 100644 --- a/stdlib/test/test/lux/data/coll/stack.lux +++ b/stdlib/test/test/lux/data/coll/stack.lux @@ -6,17 +6,17 @@ [list "" Fold]) [number] [maybe]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: gen-nat - (R;Random Nat) - (|> R;nat - (:: R;Monad map (n.% +100)))) + (r;Random Nat) + (|> r;nat + (:: r;Monad map (n.% +100)))) (context: "Stacks" [size gen-nat - sample (R;stack size gen-nat) + sample (r;stack size gen-nat) new-top gen-nat] ($_ seq (test "Can query the size of a stack." diff --git a/stdlib/test/test/lux/data/coll/stream.lux b/stdlib/test/test/lux/data/coll/stream.lux index 053228278..a5a978f49 100644 --- a/stdlib/test/test/lux/data/coll/stream.lux +++ b/stdlib/test/test/lux/data/coll/stream.lux @@ -10,16 +10,16 @@ (coll [list] ["&" stream]) [number "Nat/" Codec]) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Streams" - [size (|> R;nat (:: @ map (|>. (n.% +100) (n.max +2)))) - offset (|> R;nat (:: @ map (n.% +100))) - factor (|> R;nat (:: @ map (|>. (n.% +100) (n.max +2)))) - elem R;nat - cycle-seed (R;list size R;nat) - cycle-sample-idx (|> R;nat (:: @ map (n.% +1000))) + [size (|> r;nat (:: @ map (|>. (n.% +100) (n.max +2)))) + offset (|> r;nat (:: @ map (n.% +100))) + factor (|> r;nat (:: @ map (|>. (n.% +100) (n.max +2)))) + elem r;nat + cycle-seed (r;list size r;nat) + cycle-sample-idx (|> r;nat (:: @ map (n.% +1000))) #let [(^open "List/") (list;Eq number;Eq) sample0 (&;iterate n.inc +0) sample1 (&;iterate n.inc offset)]] diff --git a/stdlib/test/test/lux/data/coll/vector.lux b/stdlib/test/test/lux/data/coll/vector.lux index e605805a8..23fe64464 100644 --- a/stdlib/test/test/lux/data/coll/vector.lux +++ b/stdlib/test/test/lux/data/coll/vector.lux @@ -8,15 +8,15 @@ text/format [number] [maybe]) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Vectors" - [size (|> R;nat (:: @ map (|>. (n.% +100) (n.max +1)))) - idx (|> R;nat (:: @ map (n.% size))) - sample (R;vector size R;nat) - other-sample (R;vector size R;nat) - non-member (|> R;nat (R;filter (. not (&;member? number;Eq sample)))) + [size (|> r;nat (:: @ map (|>. (n.% +100) (n.max +1)))) + idx (|> r;nat (:: @ map (n.% size))) + sample (r;vector size r;nat) + other-sample (r;vector size r;nat) + non-member (|> r;nat (r;filter (. not (&;member? number;Eq sample)))) #let [(^open "&/") (&;Eq number;Eq) (^open "&/") &;Monad (^open "&/") &;Fold diff --git a/stdlib/test/test/lux/data/error.lux b/stdlib/test/test/lux/data/error.lux new file mode 100644 index 000000000..a72a45403 --- /dev/null +++ b/stdlib/test/test/lux/data/error.lux @@ -0,0 +1,56 @@ +(;module: + lux + (lux [io] + (control ["M" monad #+ do Monad] + pipe) + (data text/format + ["&" error])) + lux/test) + +(context: "Errors" + (let [(^open "&/") &;Monad] + ($_ seq + (test "Functor correctly handles both cases." + (and (|> (: (&;Error Int) (#&;Success 10)) + (&/map i.inc) + (case> (#&;Success 11) true _ false)) + + (|> (: (&;Error Int) (#&;Error "YOLO")) + (&/map i.inc) + (case> (#&;Error "YOLO") true _ false)) + )) + + (test "Applicative correctly handles both cases." + (and (|> (&/wrap 20) + (case> (#&;Success 20) true _ false)) + (|> (&/apply (&/wrap i.inc) (&/wrap 10)) + (case> (#&;Success 11) true _ false)) + (|> (&/apply (&/wrap i.inc) (#&;Error "YOLO")) + (case> (#&;Error "YOLO") true _ false)))) + + (test "Monad correctly handles both cases." + (and (|> (do &;Monad + [f (wrap i.+) + a (wrap 10) + b (wrap 20)] + (wrap (f a b))) + (case> (#&;Success 30) true _ false)) + (|> (do &;Monad + [f (wrap i.+) + a (#&;Error "YOLO") + b (wrap 20)] + (wrap (f a b))) + (case> (#&;Error "YOLO") true _ false)) + )) + ))) + +(context: "Monad transformer" + (let [lift (&;lift io;Monad) + (^open "io/") io;Monad] + (test "Can add error functionality to any monad." + (|> (io;run (do (&;ErrorT io;Monad) + [a (lift (io/wrap 123)) + b (wrap 456)] + (wrap (i.+ a b)))) + (case> (#&;Success 579) true + _ false))))) diff --git a/stdlib/test/test/lux/data/format/json.lux b/stdlib/test/test/lux/data/format/json.lux index 2eca6febd..89244d6fe 100644 --- a/stdlib/test/test/lux/data/format/json.lux +++ b/stdlib/test/test/lux/data/format/json.lux @@ -8,7 +8,7 @@ ["p" parser]) (data [text "Text/" Monoid] text/format - ["R" result] + ["E" error] [bool] [maybe] [number "i/" Number] @@ -166,8 +166,8 @@ (^open "@/") Codec]] (test "Can encode/decode arbitrary types." (|> sample @/encode @/decode - (case> (#R;Success result) + (case> (#E;Success result) (@/= sample result) - (#R;Error error) + (#E;Error error) false)))) diff --git a/stdlib/test/test/lux/data/format/xml.lux b/stdlib/test/test/lux/data/format/xml.lux index b43aee394..0a4179040 100644 --- a/stdlib/test/test/lux/data/format/xml.lux +++ b/stdlib/test/test/lux/data/format/xml.lux @@ -7,7 +7,7 @@ (data [text "text/" Eq] text/format [ident] - ["R" result] + ["E" error] [maybe] (format ["&" xml]) (coll [dict] @@ -84,28 +84,28 @@ (L/map (|>. #&;Text) children))]] ($_ seq (test "Can parse text." - (R;default false - (do R;Monad + (E;default false + (do E;Monad [output (&;run (#&;Text text) &;text)] (wrap (text/= text output))))) (test "Can parse attributes." - (R;default false - (do R;Monad + (E;default false + (do E;Monad [output (|> (&;attr attr) (p;before &;ignore) (&;run node))] (wrap (text/= value output))))) (test "Can parse nodes." - (R;default false - (do R;Monad + (E;default false + (do E;Monad [_ (|> (&;node tag) (p;before &;ignore) (&;run node))] (wrap true)))) (test "Can parse children." - (R;default false - (do R;Monad + (E;default false + (do E;Monad [outputs (|> (&;children (p;some &;text)) (&;run node))] (wrap (:: (list;Eq text;Eq) = diff --git a/stdlib/test/test/lux/data/ident.lux b/stdlib/test/test/lux/data/ident.lux index 6ca00d09f..cae265a45 100644 --- a/stdlib/test/test/lux/data/ident.lux +++ b/stdlib/test/test/lux/data/ident.lux @@ -6,23 +6,23 @@ (data ["&" ident] [text "Text/" Eq] text/format) - ["R" math/random]) + ["r" math/random]) lux/test) (def: (gen-part size) - (-> Nat (R;Random Text)) - (|> (R;text size) (R;filter (. not (text;contains? ";"))))) + (-> Nat (r;Random Text)) + (|> (r;text size) (r;filter (. not (text;contains? ";"))))) (context: "Idents" [## First Ident - sizeM1 (|> R;nat (:: @ map (n.% +100))) - sizeN1 (|> R;nat (:: @ map (|>. (n.% +100) (n.max +1)))) + sizeM1 (|> r;nat (:: @ map (n.% +100))) + sizeN1 (|> r;nat (:: @ map (|>. (n.% +100) (n.max +1)))) module1 (gen-part sizeM1) name1 (gen-part sizeN1) #let [ident1 [module1 name1]] ## Second Ident - sizeM2 (|> R;nat (:: @ map (n.% +100))) - sizeN2 (|> R;nat (:: @ map (|>. (n.% +100) (n.max +1)))) + sizeM2 (|> r;nat (:: @ map (n.% +100))) + sizeN2 (|> r;nat (:: @ map (|>. (n.% +100) (n.max +1)))) module2 (gen-part sizeM2) name2 (gen-part sizeN2) #let [ident2 [module2 name2]] diff --git a/stdlib/test/test/lux/data/number.lux b/stdlib/test/test/lux/data/number.lux index c33d06856..1a33fdc2c 100644 --- a/stdlib/test/test/lux/data/number.lux +++ b/stdlib/test/test/lux/data/number.lux @@ -6,7 +6,7 @@ (data number [text "Text/" Monoid Eq] text/format) - ["R" math/random]) + ["r" math/random]) lux/test) (do-template [category rand-gen ] @@ -18,10 +18,10 @@ (:: < y x) (:: > y x)))))] - ["Nat" R;nat Eq Order] - ["Int" R;int Eq Order] - ["Frac" R;frac Eq Order] - ["Deg" R;deg Eq Order] + ["Nat" r;nat Eq Order] + ["Int" r;int Eq Order] + ["Frac" r;frac Eq Order] + ["Deg" r;deg Eq Order] ) (do-template [category rand-gen ] @@ -39,10 +39,10 @@ (= x (* (signum x) (abs x)))))))] - ## ["Nat" R;nat Number] - ["Int" R;int Number Order] - ["Frac" R;frac Number Order] - ["Deg" R;deg Number Order] + ## ["Nat" r;nat Number] + ["Int" r;int Number Order] + ["Frac" r;frac Number Order] + ["Deg" r;deg Number Order] ) (do-template [category rand-gen ] @@ -61,28 +61,28 @@ (|> x (:: succ) (:: pred))) ))))] - ["Nat" R;nat Enum Number Order] - ["Int" R;int Enum Number Order] + ["Nat" r;nat Enum Number Order] + ["Int" r;int Enum Number Order] ) (do-template [category rand-gen ] [(context: (format "[" category "] " "Interval") - [x (|> rand-gen (R;filter )) + [x (|> rand-gen (r;filter )) #let [(^open) (^open) ]] (test "" (and (<= x (:: bottom)) (>= x (:: top)))))] - ["Nat" R;nat Number Order Interval (function [_] true)] - ["Int" R;int Number Order Interval (function [_] true)] + ["Nat" r;nat Number Order Interval (function [_] true)] + ["Int" r;int Number Order Interval (function [_] true)] ## Both min and max values will be positive (thus, greater than zero) - ["Frac" R;frac Number Order Interval (f.> 0.0)] - ["Deg" R;deg Number Order Interval (function [_] true)] + ["Frac" r;frac Number Order Interval (f.> 0.0)] + ["Deg" r;deg Number Order Interval (function [_] true)] ) (do-template [category rand-gen ] [(context: (format "[" category "] " "Monoid") - [x (|> rand-gen (:: @ map (|>. (:: abs) )) (R;filter )) + [x (|> rand-gen (:: @ map (|>. (:: abs) )) (r;filter )) #let [(^open) (^open) (^open) ]] @@ -91,22 +91,22 @@ (= x (compose x identity)) (= identity (compose identity identity)))))] - ["Nat/Add" R;nat Number Order Add@Monoid (n.% +1000) (function [_] true)] - ["Nat/Mul" R;nat Number Order Mul@Monoid (n.% +1000) (function [_] true)] - ["Nat/Min" R;nat Number Order Min@Monoid (n.% +1000) (function [_] true)] - ["Nat/Max" R;nat Number Order Max@Monoid (n.% +1000) (function [_] true)] - ["Int/Add" R;int Number Order Add@Monoid (i.% 1000) (function [_] true)] - ["Int/Mul" R;int Number Order Mul@Monoid (i.% 1000) (function [_] true)] - ["Int/Min" R;int Number Order Min@Monoid (i.% 1000) (function [_] true)] - ["Int/Max" R;int Number Order Max@Monoid (i.% 1000) (function [_] true)] - ["Frac/Add" R;frac Number Order Add@Monoid (f.% 1000.0) (f.> 0.0)] - ["Frac/Mul" R;frac Number Order Mul@Monoid (f.% 1000.0) (f.> 0.0)] - ["Frac/Min" R;frac Number Order Min@Monoid (f.% 1000.0) (f.> 0.0)] - ["Frac/Max" R;frac Number Order Max@Monoid (f.% 1000.0) (f.> 0.0)] - ["Deg/Add" R;deg Number Order Add@Monoid (d.% .125) (function [_] true)] - ## ["Deg/Mul" R;deg Number Order Mul@Monoid (d.% .125) (function [_] true)] - ["Deg/Min" R;deg Number Order Min@Monoid (d.% .125) (function [_] true)] - ["Deg/Max" R;deg Number Order Max@Monoid (d.% .125) (function [_] true)] + ["Nat/Add" r;nat Number Order Add@Monoid (n.% +1000) (function [_] true)] + ["Nat/Mul" r;nat Number Order Mul@Monoid (n.% +1000) (function [_] true)] + ["Nat/Min" r;nat Number Order Min@Monoid (n.% +1000) (function [_] true)] + ["Nat/Max" r;nat Number Order Max@Monoid (n.% +1000) (function [_] true)] + ["Int/Add" r;int Number Order Add@Monoid (i.% 1000) (function [_] true)] + ["Int/Mul" r;int Number Order Mul@Monoid (i.% 1000) (function [_] true)] + ["Int/Min" r;int Number Order Min@Monoid (i.% 1000) (function [_] true)] + ["Int/Max" r;int Number Order Max@Monoid (i.% 1000) (function [_] true)] + ["Frac/Add" r;frac Number Order Add@Monoid (f.% 1000.0) (f.> 0.0)] + ["Frac/Mul" r;frac Number Order Mul@Monoid (f.% 1000.0) (f.> 0.0)] + ["Frac/Min" r;frac Number Order Min@Monoid (f.% 1000.0) (f.> 0.0)] + ["Frac/Max" r;frac Number Order Max@Monoid (f.% 1000.0) (f.> 0.0)] + ["Deg/Add" r;deg Number Order Add@Monoid (d.% .125) (function [_] true)] + ## ["Deg/Mul" r;deg Number Order Mul@Monoid (d.% .125) (function [_] true)] + ["Deg/Min" r;deg Number Order Min@Monoid (d.% .125) (function [_] true)] + ["Deg/Max" r;deg Number Order Max@Monoid (d.% .125) (function [_] true)] ) (do-template [ ] @@ -122,30 +122,30 @@ (#;Left _) false))))] - ["Nat/Binary" R;nat Eq Binary@Codec] - ["Nat/Octal" R;nat Eq Octal@Codec] - ["Nat/Decimal" R;nat Eq Codec] - ["Nat/Hex" R;nat Eq Hex@Codec] - - ["Int/Binary" R;int Eq Binary@Codec] - ["Int/Octal" R;int Eq Octal@Codec] - ["Int/Decimal" R;int Eq Codec] - ["Int/Hex" R;int Eq Hex@Codec] - - ["Deg/Binary" R;deg Eq Binary@Codec] - ["Deg/Octal" R;deg Eq Octal@Codec] - ["Deg/Decimal" R;deg Eq Codec] - ["Deg/Hex" R;deg Eq Hex@Codec] - - ["Frac/Binary" R;frac Eq Binary@Codec] - ["Frac/Octal" R;frac Eq Octal@Codec] - ["Frac/Decimal" R;frac Eq Codec] - ["Frac/Hex" R;frac Eq Hex@Codec] + ["Nat/Binary" r;nat Eq Binary@Codec] + ["Nat/Octal" r;nat Eq Octal@Codec] + ["Nat/Decimal" r;nat Eq Codec] + ["Nat/Hex" r;nat Eq Hex@Codec] + + ["Int/Binary" r;int Eq Binary@Codec] + ["Int/Octal" r;int Eq Octal@Codec] + ["Int/Decimal" r;int Eq Codec] + ["Int/Hex" r;int Eq Hex@Codec] + + ["Deg/Binary" r;deg Eq Binary@Codec] + ["Deg/Octal" r;deg Eq Octal@Codec] + ["Deg/Decimal" r;deg Eq Codec] + ["Deg/Hex" r;deg Eq Hex@Codec] + + ["Frac/Binary" r;frac Eq Binary@Codec] + ["Frac/Octal" r;frac Eq Octal@Codec] + ["Frac/Decimal" r;frac Eq Codec] + ["Frac/Hex" r;frac Eq Hex@Codec] ) (context: "Can convert frac values to/from their bit patterns." - [raw R;frac - factor (|> R;nat (:: @ map (|>. (n.% +1000) (n.max +1)))) + [raw r;frac + factor (|> r;nat (:: @ map (|>. (n.% +1000) (n.max +1)))) #let [sample (|> factor nat-to-int int-to-frac (f.* raw))]] (test "Can convert frac values to/from their bit patterns." (|> sample frac-to-bits bits-to-frac (f.= sample)))) diff --git a/stdlib/test/test/lux/data/number/complex.lux b/stdlib/test/test/lux/data/number/complex.lux index 78155e061..5fb5f6cfe 100644 --- a/stdlib/test/test/lux/data/number/complex.lux +++ b/stdlib/test/test/lux/data/number/complex.lux @@ -11,7 +11,7 @@ (coll [list "List/" Fold Functor]) [product]) [math] - ["R" math/random]) + ["r" math/random]) lux/test) ## Based on org.apache.commons.math4.complex.Complex @@ -29,16 +29,16 @@ (f.< margin imgn-dist)))) (def: gen-dim - (R;Random Frac) - (do R;Monad - [factor (|> R;nat (:: @ map (|>. (n.% +1000) (n.max +1)))) - measure (|> R;frac (R;filter (f.> 0.0)))] + (r;Random Frac) + (do r;Monad + [factor (|> r;nat (:: @ map (|>. (n.% +1000) (n.max +1)))) + measure (|> r;frac (r;filter (f.> 0.0)))] (wrap (f.* (|> factor nat-to-int int-to-frac) measure)))) (def: gen-complex - (R;Random &;Complex) - (do R;Monad + (r;Random &;Complex) + (do r;Monad [real gen-dim imaginary gen-dim] (wrap (&;complex real imaginary)))) @@ -180,7 +180,7 @@ (context: "Complex roots" [sample gen-complex - degree (|> R;nat (:: @ map (|>. (n.max +1) (n.% +5))))] + degree (|> r;nat (:: @ map (|>. (n.max +1) (n.% +5))))] (test "Can calculate the N roots for any complex number." (|> sample (&;nth-roots degree) diff --git a/stdlib/test/test/lux/data/number/ratio.lux b/stdlib/test/test/lux/data/number/ratio.lux index a2eb4f53d..20090fc8c 100644 --- a/stdlib/test/test/lux/data/number/ratio.lux +++ b/stdlib/test/test/lux/data/number/ratio.lux @@ -9,20 +9,20 @@ ["&" number/ratio "&/" Number] (coll [list "List/" Fold Functor]) [product]) - ["R" math/random]) + ["r" math/random]) lux/test) (def: gen-part - (R;Random Nat) - (|> R;nat (:: R;Monad map (|>. (n.% +1000) (n.max +1))))) + (r;Random Nat) + (|> r;nat (:: r;Monad map (|>. (n.% +1000) (n.max +1))))) (def: gen-ratio - (R;Random &;Ratio) - (do R;Monad + (r;Random &;Ratio) + (do r;Monad [numerator gen-part denominator (|> gen-part - (R;filter (|>. (n.= +0) not)) - (R;filter (. not (n.= numerator))))] + (r;filter (|>. (n.= +0) not)) + (r;filter (. not (n.= numerator))))] (wrap (&;ratio numerator denominator)))) (context: "Normalization" diff --git a/stdlib/test/test/lux/data/result.lux b/stdlib/test/test/lux/data/result.lux deleted file mode 100644 index efd1009c8..000000000 --- a/stdlib/test/test/lux/data/result.lux +++ /dev/null @@ -1,56 +0,0 @@ -(;module: - lux - (lux [io] - (control ["M" monad #+ do Monad] - pipe) - (data text/format - ["&" result])) - lux/test) - -(context: "Results" - (let [(^open "&/") &;Monad] - ($_ seq - (test "Functor correctly handles both cases." - (and (|> (: (&;Result Int) (#&;Success 10)) - (&/map i.inc) - (case> (#&;Success 11) true _ false)) - - (|> (: (&;Result Int) (#&;Error "YOLO")) - (&/map i.inc) - (case> (#&;Error "YOLO") true _ false)) - )) - - (test "Applicative correctly handles both cases." - (and (|> (&/wrap 20) - (case> (#&;Success 20) true _ false)) - (|> (&/apply (&/wrap i.inc) (&/wrap 10)) - (case> (#&;Success 11) true _ false)) - (|> (&/apply (&/wrap i.inc) (#&;Error "YOLO")) - (case> (#&;Error "YOLO") true _ false)))) - - (test "Monad correctly handles both cases." - (and (|> (do &;Monad - [f (wrap i.+) - a (wrap 10) - b (wrap 20)] - (wrap (f a b))) - (case> (#&;Success 30) true _ false)) - (|> (do &;Monad - [f (wrap i.+) - a (#&;Error "YOLO") - b (wrap 20)] - (wrap (f a b))) - (case> (#&;Error "YOLO") true _ false)) - )) - ))) - -(context: "Monad transformer" - (let [lift (&;lift io;Monad) - (^open "io/") io;Monad] - (test "Can add result functionality to any monad." - (|> (io;run (do (&;ResultT io;Monad) - [a (lift (io/wrap 123)) - b (wrap 456)] - (wrap (i.+ a b)))) - (case> (#&;Success 579) true - _ false))))) diff --git a/stdlib/test/test/lux/data/text/lexer.lux b/stdlib/test/test/lux/data/text/lexer.lux index 37f915e6c..39c171442 100644 --- a/stdlib/test/test/lux/data/text/lexer.lux +++ b/stdlib/test/test/lux/data/text/lexer.lux @@ -4,8 +4,8 @@ pipe ["p" parser]) [io] - (data ["R" result] - [text "T/" Eq] + (data ["E" error] + [text "text/" Eq] text/format ["&" text/lexer] (coll [list])) @@ -14,40 +14,40 @@ ## [Utils] (def: (should-fail input) - (All [a] (-> (R;Result a) Bool)) + (All [a] (-> (E;Error a) Bool)) (case input (#;Left _) true _ false)) (def: (should-passT test input) - (-> Text (R;Result Text) Bool) + (-> Text (E;Error Text) Bool) (case input (#;Right output) - (T/= test output) + (text/= test output) _ false)) (def: (should-passL test input) - (-> (List Text) (R;Result (List Text)) Bool) - (let [(^open "L/") (list;Eq text;Eq)] + (-> (List Text) (E;Error (List Text)) Bool) + (let [(^open "list/") (list;Eq text;Eq)] (case input (#;Right output) - (L/= test output) + (list/= test output) _ false))) (def: (should-passE test input) - (-> (Either Text Text) (R;Result (Either Text Text)) Bool) + (-> (Either Text Text) (E;Error (Either Text Text)) Bool) (case input (#;Right output) (case [test output] [(#;Left test) (#;Left output)] - (T/= test output) + (text/= test output) [(#;Right test) (#;Right output)] - (T/= test output) + (text/= test output) _ false) @@ -73,7 +73,7 @@ [size (|> r;nat (:: @ map (|>. (n.% +100) (n.max +10)))) sample (r;text size) non-sample (|> (r;text size) - (r;filter (|>. (T/= sample) not)))] + (r;filter (|>. (text/= sample) not)))] ($_ seq (test "Can find literal text fragments." (and (|> (&;run sample diff --git a/stdlib/test/test/lux/host.js.lux b/stdlib/test/test/lux/host.js.lux index 93e90bbfe..c7d65343a 100644 --- a/stdlib/test/test/lux/host.js.lux +++ b/stdlib/test/test/lux/host.js.lux @@ -4,7 +4,7 @@ (control ["M" monad #+ do Monad]) (data text/format) ["&" host] - ["R" math/random]) + ["r" math/random]) lux/test) (context: "JavaScript operations" diff --git a/stdlib/test/test/lux/macro/code.lux b/stdlib/test/test/lux/macro/code.lux index ff21fd0c9..64bdf5f1c 100644 --- a/stdlib/test/test/lux/macro/code.lux +++ b/stdlib/test/test/lux/macro/code.lux @@ -5,7 +5,7 @@ (data [text "T/" Eq] text/format [number]) - ["R" math/random] + ["r" math/random] (macro ["&" code])) lux/test) diff --git a/stdlib/test/test/lux/macro/syntax.lux b/stdlib/test/test/lux/macro/syntax.lux index e988a0103..b159bf999 100644 --- a/stdlib/test/test/lux/macro/syntax.lux +++ b/stdlib/test/test/lux/macro/syntax.lux @@ -9,8 +9,8 @@ [number] [bool] [ident] - ["E" result]) - ["R" math/random] + ["E" error]) + ["r" math/random] [macro] (macro [code] ["s" syntax #+ syntax: Syntax])) @@ -45,7 +45,7 @@ false)) (def: (fails? input) - (All [a] (-> (E;Result a) Bool)) + (All [a] (-> (E;Error a) Bool)) (case input (#;Left _) true diff --git a/stdlib/test/test/lux/math/logic/continuous.lux b/stdlib/test/test/lux/math/logic/continuous.lux index 4b2af88f3..1c6ed01a4 100644 --- a/stdlib/test/test/lux/math/logic/continuous.lux +++ b/stdlib/test/test/lux/math/logic/continuous.lux @@ -2,13 +2,13 @@ lux (lux [io] (control [monad #+ do Monad]) - ["R" math/random] + ["r" math/random] ["&" math/logic/continuous]) lux/test) (context: "Operations" - [left R;deg - right R;deg] + [left r;deg + right r;deg] ($_ seq (test "AND is the minimum." (let [result (&;~and left right)] diff --git a/stdlib/test/test/lux/math/logic/fuzzy.lux b/stdlib/test/test/lux/math/logic/fuzzy.lux index 5f10696c1..41a8f090a 100644 --- a/stdlib/test/test/lux/math/logic/fuzzy.lux +++ b/stdlib/test/test/lux/math/logic/fuzzy.lux @@ -7,14 +7,14 @@ [bool "B/" Eq] [number] text/format) - ["R" math/random] + ["r" math/random] (math/logic ["&" fuzzy] continuous)) lux/test) (do-template [ ] [(context: (format "[" "] " "Triangles") - [values (R;set +3 ) + [values (r;set +3 ) #let [[x y z] (case (set;to-list values) (^ (list x y z)) [x y z] @@ -48,13 +48,13 @@ ( top sample)))) ))] - ["Frac" number;Hash R;frac &;f.triangle f.< f.<= f.> f.>=] - ["Deg" number;Hash R;deg &;d.triangle d.< d.<= d.> d.>=] + ["Frac" number;Hash r;frac &;f.triangle f.< f.<= f.> f.>=] + ["Deg" number;Hash r;deg &;d.triangle d.< d.<= d.> d.>=] ) (do-template [ ] [(context: (format "[" "] " "Trapezoids") - [values (R;set +4 ) + [values (r;set +4 ) #let [[w x y z] (case (set;to-list values) (^ (list w x y z)) [w x y z] @@ -94,29 +94,29 @@ ( top sample)))) ))] - ["Frac" number;Hash R;frac &;f.trapezoid f.< f.<= f.> f.>=] - ["Deg" number;Hash R;deg &;d.trapezoid d.< d.<= d.> d.>=] + ["Frac" number;Hash r;frac &;f.trapezoid f.< f.<= f.> f.>=] + ["Deg" number;Hash r;deg &;d.trapezoid d.< d.<= d.> d.>=] ) (context: "Gaussian" - [deviation (|> R;frac (R;filter (f.> 0.0))) - center R;frac + [deviation (|> r;frac (r;filter (f.> 0.0))) + center r;frac #let [gaussian (&;gaussian deviation center)]] (test "The center value will always have maximum membership." (d.= ~true (&;membership center gaussian)))) (def: gen-triangle - (R;Random (&;Fuzzy Frac)) - (do R;Monad - [x R;frac - y R;frac - z R;frac] + (r;Random (&;Fuzzy Frac)) + (do r;Monad + [x r;frac + y r;frac + z r;frac] (wrap (&;f.triangle x y z)))) (context: "Combinators" [left gen-triangle right gen-triangle - sample R;frac] + sample r;frac] ($_ seq (test "Union membership as as high as membership in any of its members." (let [combined (&;union left right) @@ -147,7 +147,7 @@ (context: "From predicates and sets" [#let [set-10 (set;from-list number;Hash (list;n.range +0 +10))] - sample (|> R;nat (:: @ map (n.% +20)))] + sample (|> r;nat (:: @ map (n.% +20)))] ($_ seq (test "Values that satisfy a predicate have membership = 1. Values that don't have membership = 0." @@ -162,8 +162,8 @@ (context: "Thresholds" [fuzzy gen-triangle - sample R;frac - threshold R;deg + sample r;frac + threshold r;deg #let [vip-fuzzy (&;cut threshold fuzzy) member? (&;to-predicate threshold fuzzy)]] ($_ seq diff --git a/stdlib/test/test/lux/time/date.lux b/stdlib/test/test/lux/time/date.lux index a73001026..baac8d22c 100644 --- a/stdlib/test/test/lux/time/date.lux +++ b/stdlib/test/test/lux/time/date.lux @@ -3,7 +3,7 @@ (lux [io] (control [monad #+ do Monad] [pipe]) - (data ["R" result]) + (data ["E" error]) (math ["r" random "r/" Monad]) (time ["@;" instant] ["@" date])) @@ -118,8 +118,8 @@ (|> sample @/encode @/decode - (pipe;case> (#R;Success decoded) + (pipe;case> (#E;Success decoded) (@/= sample decoded) - (#R;Error error) + (#E;Error error) false)))) diff --git a/stdlib/test/test/lux/time/duration.lux b/stdlib/test/test/lux/time/duration.lux index 4a674420e..be0637ab7 100644 --- a/stdlib/test/test/lux/time/duration.lux +++ b/stdlib/test/test/lux/time/duration.lux @@ -2,7 +2,7 @@ lux (lux [io] (control [monad #+ do Monad]) - (data ["R" result]) + (data ["E" error]) (math ["r" random]) (time ["@" duration])) lux/test) @@ -66,7 +66,7 @@ #let [(^open "@/") @;Eq (^open "@/") @;Codec]] (test "Can encode/decode durations." - (R;default false - (do R;Monad + (E;default false + (do E;Monad [decoded (|> sample @/encode @/decode)] (wrap (@/= sample decoded)))))) diff --git a/stdlib/test/test/lux/time/instant.lux b/stdlib/test/test/lux/time/instant.lux index c686de5b7..df59f0743 100644 --- a/stdlib/test/test/lux/time/instant.lux +++ b/stdlib/test/test/lux/time/instant.lux @@ -5,7 +5,7 @@ pipe) (data [text] text/format - ["R" result] + ["E" error] [number "Int/" Number]) (math ["r" random]) (time ["@" instant] @@ -75,8 +75,8 @@ (|> sample @/encode @/decode - (case> (#R;Success decoded) + (case> (#E;Success decoded) (@/= sample decoded) - (#R;Error error) + (#E;Error error) false)))) diff --git a/stdlib/test/test/lux/type.lux b/stdlib/test/test/lux/type.lux index 8c149e3f4..617921e33 100644 --- a/stdlib/test/test/lux/type.lux +++ b/stdlib/test/test/lux/type.lux @@ -8,39 +8,39 @@ [number] [maybe] (coll [list])) - ["R" math/random] + ["r" math/random] ["&" type]) lux/test) ## [Utils] (def: gen-name - (R;Random Text) - (do R;Monad - [size (|> R;nat (:: @ map (n.% +10)))] - (R;text size))) + (r;Random Text) + (do r;Monad + [size (|> r;nat (:: @ map (n.% +10)))] + (r;text size))) (def: gen-ident - (R;Random Ident) - (R;seq gen-name gen-name)) + (r;Random Ident) + (r;seq gen-name gen-name)) (def: gen-type - (R;Random Type) - (let [(^open "R/") R;Monad] - (R;rec (function [gen-type] - ($_ R;alt - (R;seq gen-name (R/wrap (list))) + (r;Random Type) + (let [(^open "R/") r;Monad] + (r;rec (function [gen-type] + ($_ r;alt + (r;seq gen-name (R/wrap (list))) (R/wrap []) (R/wrap []) - (R;seq gen-type gen-type) - (R;seq gen-type gen-type) - (R;seq gen-type gen-type) - R;nat - R;nat - R;nat - (R;seq (R/wrap (list)) gen-type) - (R;seq (R/wrap (list)) gen-type) - (R;seq gen-type gen-type) - (R;seq gen-ident gen-type) + (r;seq gen-type gen-type) + (r;seq gen-type gen-type) + (r;seq gen-type gen-type) + r;nat + r;nat + r;nat + (r;seq (R/wrap (list)) gen-type) + (r;seq (R/wrap (list)) gen-type) + (r;seq gen-type gen-type) + (r;seq gen-ident gen-type) ))))) ## [Tests] @@ -79,9 +79,9 @@ (&;un-name aliased))))))) (context: "Type construction [structs]" - [size (|> R;nat (:: @ map (n.% +3))) + [size (|> r;nat (:: @ map (n.% +3))) members (|> gen-type - (R;filter (function [type] + (r;filter (function [type] (case type (^or (#;Sum _) (#;Product _)) false @@ -108,10 +108,10 @@ ))) (context: "Type construction [parameterized]" - [size (|> R;nat (:: @ map (n.% +3))) + [size (|> r;nat (:: @ map (n.% +3))) members (M;seq @ (list;repeat size gen-type)) extra (|> gen-type - (R;filter (function [type] + (r;filter (function [type] (case type (^or (#;Function _) (#;Apply _)) false @@ -132,9 +132,9 @@ )) (context: "Type construction [higher order]" - [size (|> R;nat (:: @ map (n.% +3))) + [size (|> r;nat (:: @ map (n.% +3))) extra (|> gen-type - (R;filter (function [type] + (r;filter (function [type] (case type (^or (#;UnivQ _) (#;ExQ _)) false diff --git a/stdlib/test/test/lux/type/auto.lux b/stdlib/test/test/lux/type/auto.lux index f12d97c75..55e374c50 100644 --- a/stdlib/test/test/lux/type/auto.lux +++ b/stdlib/test/test/lux/type/auto.lux @@ -10,14 +10,14 @@ [bool "B/" Eq] maybe (coll [list])) - ["R" math/random] + ["r" math/random] [type] type/auto) lux/test) (context: "Automatic structure selection" - [x R;nat - y R;nat] + [x r;nat + y r;nat] ($_ seq (test "Can automatically select first-order structures." (let [(^open "L/") (list;Eq number;Eq)] diff --git a/stdlib/test/test/lux/world/blob.lux b/stdlib/test/test/lux/world/blob.lux index 23dcd889c..5a616f3e4 100644 --- a/stdlib/test/test/lux/world/blob.lux +++ b/stdlib/test/test/lux/world/blob.lux @@ -4,19 +4,19 @@ (control [monad #+ do] [pipe]) (data [bit] - ["R" result] + ["E" error] (coll [list])) (world ["@" blob]) ["r" math/random]) lux/test) (def: (succeed result) - (-> (R;Result Bool) Bool) + (-> (E;Error Bool) Bool) (case result - (#R;Error _) + (#E;Error _) false - (#R;Success output) + (#E;Success output) output)) (def: #export (blob size) @@ -28,7 +28,7 @@ (if (n.< size idx) (do @ [byte r;nat] - (exec (R;assume (@;write-8 idx byte blob)) + (exec (E;assume (@;write-8 idx byte blob)) (recur (n.inc idx)))) (wrap blob)))))) @@ -52,39 +52,39 @@ value-32 (n.% (bit;shift-left +32 +1) value) value-64 value slice-size (|> to (n.- from) n.inc) - random-slice (R;assume (@;slice from to random-blob))]] + random-slice (E;assume (@;slice from to random-blob))]] ($_ seq (test "Has equality." (and (:: @;Eq = clean-blob clean-blob) (:: @;Eq = - (R;assume (@;slice from to clean-blob)) - (R;assume (@;slice from to clean-blob))))) + (E;assume (@;slice from to clean-blob)) + (E;assume (@;slice from to clean-blob))))) (test "Can get size of blob." (n.= blob-size size)) (test "Can read/write 8-bit values." (succeed - (do R;Monad + (do E;Monad [_ (@;write-8 idx value-8 clean-blob) output-8 (@;read-8 idx clean-blob)] (wrap (n.= value-8 output-8))))) (test "Can read/write 16-bit values." (or (n.>= size (n.+ +1 idx)) (succeed - (do R;Monad + (do E;Monad [_ (@;write-16 idx value-16 clean-blob) output-16 (@;read-16 idx clean-blob)] (wrap (n.= value-16 output-16)))))) (test "Can read/write 32-bit values." (or (n.>= size (n.+ +3 idx)) (succeed - (do R;Monad + (do E;Monad [_ (@;write-32 idx value-32 clean-blob) output-32 (@;read-32 idx clean-blob)] (wrap (n.= value-32 output-32)))))) (test "Can read/write 64-bit values." (or (n.>= size (n.+ +7 idx)) (succeed - (do R;Monad + (do E;Monad [_ (@;write-64 idx value-64 clean-blob) output-64 (@;read-64 idx clean-blob)] (wrap (n.= value-64 output-64)))))) @@ -94,7 +94,7 @@ (let [loop-recur recur] (if (n.< slice-size idx) (and (succeed - (do R;Monad + (do E;Monad [reference (@;read-8 (n.+ from idx) random-blob) sample (@;read-8 idx random-slice)] (wrap (n.= reference sample)))) @@ -103,5 +103,5 @@ (test "Slicing the whole blob does not change anything." (:: @;Eq = random-blob - (R;assume (@;slice +0 (n.dec blob-size) random-blob)))) + (E;assume (@;slice +0 (n.dec blob-size) random-blob)))) )) diff --git a/stdlib/test/test/lux/world/file.lux b/stdlib/test/test/lux/world/file.lux index 3e653d0b1..32fa33d7d 100644 --- a/stdlib/test/test/lux/world/file.lux +++ b/stdlib/test/test/lux/world/file.lux @@ -4,7 +4,7 @@ (control [monad #+ do]) (concurrency ["P" promise] ["T" task]) - (data ["R" result] + (data ["E" error] [text] text/format [number]) @@ -41,7 +41,7 @@ (wrap (and (not pre) post deleted? (not remains?))))] (test "Can create/delete files." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file (format "temp_file_" (%n (n.+ +1 code)))] result (do T;Monad @@ -50,7 +50,7 @@ _ (@;delete file)] (wrap (:: blob;Eq = dataL output)))] (test "Can write/read files." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file (format "temp_file_" (%n (n.+ +2 code)))] result (do T;Monad @@ -59,7 +59,7 @@ _ (@;delete file)] (wrap (n.= file-size read-size)))] (test "Can read file size." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file (format "temp_file_" (%n (n.+ +3 code)))] result (do T;Monad @@ -69,10 +69,10 @@ read-size (@;size file) _ (@;delete file)] (wrap (and (n.= (n.* +2 file-size) read-size) - (:: blob;Eq = dataL (R;assume (blob;slice +0 (n.dec file-size) output))) - (:: blob;Eq = dataR (R;assume (blob;slice file-size (n.dec read-size) output))))))] + (:: blob;Eq = dataL (E;assume (blob;slice +0 (n.dec file-size) output))) + (:: blob;Eq = dataR (E;assume (blob;slice file-size (n.dec read-size) output))))))] (test "Can append to files." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [dir (format "temp_dir_" (%n (n.+ +4 code)))] result (do T;Monad @@ -84,7 +84,7 @@ (wrap (and (not pre) post deleted? (not remains?))))] (test "Can create/delete directories." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file (format "temp_file_" (%n (n.+ +5 code))) dir (format "temp_dir_" (%n (n.+ +5 code)))] @@ -100,7 +100,7 @@ (wrap (and file-is-file (not file-is-directory) (not directory-is-file) directory-is-directory)))] (test "Can differentiate files from directories." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file (format "temp_file_" (%n (n.+ +6 code))) dir (format "temp_dir_" (%n (n.+ +6 code)))] @@ -115,7 +115,7 @@ deleted-file deleted-dir)))] (test "Can create files inside of directories." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file (format "temp_file_" (%n (n.+ +7 code))) dir (format "temp_dir_" (%n (n.+ +7 code)))] @@ -133,7 +133,7 @@ _ false)))] (test "Can list files inside a directory." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file (format "temp_file_" (%n (n.+ +8 code)))] result (do T;Monad @@ -144,7 +144,7 @@ (wrap (and was-modified? (:: i;Eq = last-modified time-read))))] (test "Can change the time of last modification." - (R;default false result))) + (E;default false result))) (do P;Monad [#let [file0 (format "temp_file_" (%n (n.+ +9 code)) "0") file1 (format "temp_file_" (%n (n.+ +9 code)) "1")] @@ -158,5 +158,5 @@ (wrap (and pre moved? (not post) confirmed? deleted?)))] (test "Can move a file from one path to another." - (R;default false result))) + (E;default false result))) )) diff --git a/stdlib/test/test/lux/world/net/tcp.lux b/stdlib/test/test/lux/world/net/tcp.lux index 4c975b4dd..cf390ef09 100644 --- a/stdlib/test/test/lux/world/net/tcp.lux +++ b/stdlib/test/test/lux/world/net/tcp.lux @@ -6,7 +6,7 @@ (concurrency ["P" promise] ["T" task] [frp]) - (data ["R" result] + (data ["E" error] [text] text/format) (world [blob] @@ -66,5 +66,5 @@ (wrap (and from-worked? to-worked?)))] (test "Can communicate between client and server." - (R;default false result))) + (E;default false result))) )) diff --git a/stdlib/test/test/lux/world/net/udp.lux b/stdlib/test/test/lux/world/net/udp.lux index 8af67bcd5..6bd43351e 100644 --- a/stdlib/test/test/lux/world/net/udp.lux +++ b/stdlib/test/test/lux/world/net/udp.lux @@ -6,7 +6,7 @@ (concurrency ["P" promise] ["T" task] [frp]) - (data ["R" result] + (data ["E" error] [text] text/format) (world [blob] @@ -66,5 +66,5 @@ (wrap (and from-worked? to-worked?)))] (test "Can communicate between client and server." - (R;default false result))) + (E;default false result))) )) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index e5cf4df6f..085275e62 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -28,7 +28,7 @@ ["_;" parser]) (data ["_;" bit] ["_;" bool] - ["_;" result] + ["_;" error] ["_;" ident] ["_;" identity] ["_;" maybe] -- cgit v1.2.3