diff options
author | Eduardo Julian | 2018-07-28 14:55:30 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-28 14:55:30 -0400 |
commit | 15e71e57b688f5079fe606b2fee5e3efd2a5d5a7 (patch) | |
tree | b59e411ebc82a4fb4fdfe66efcc2817fc83c6188 /stdlib/source | |
parent | dff8878c13610ae8d1207aaabefbecc88cd3911f (diff) |
Added "+" sign to positive Int.
Diffstat (limited to '')
27 files changed, 522 insertions, 499 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index a30c03a78..dd5a42064 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1029,7 +1029,7 @@ (#Cons [(tag$ ["lux" "doc"]) (text$ "## Throws away any code given to it. ## Great for commenting-out code, while retaining syntax high-lighting and formatting in your text editor. - (comment 1 2 3 4)")] + (comment +1 +2 +3 +4)")] #Nil) (return #Nil)) @@ -1338,7 +1338,7 @@ (macro:' #export (list xs) (#Cons [(tag$ ["lux" "doc"]) (text$ "## List-construction macro. - (list 1 2 3)")] + (list +1 +2 +3)")] #Nil) (return (#Cons (list/fold (function'' [head tail] (form$ (#Cons (tag$ ["lux" "Cons"]) @@ -1352,7 +1352,7 @@ (#Cons [(tag$ ["lux" "doc"]) (text$ "## List-construction macro, with the last element being a tail-list. ## In other words, this macro prepends elements to another list. - (list& 1 2 3 (list 4 5 6))")] + (list& +1 +2 +3 (list +4 +5 +6))")] #Nil) ({(#Cons last init) (return (list (list/fold (function'' [head tail] @@ -2257,7 +2257,7 @@ (-> Int Int) (i/+ <diff>))] - [inc 1] + [inc +1] [dec -1])")]) ({(#Cons [[_ (#Tuple bindings)] (#Cons [[_ (#Tuple templates)] data])]) ({[(#Some bindings') (#Some data')] @@ -2364,7 +2364,7 @@ (list [(tag$ ["lux" "doc"]) (text$ "Nat(ural) division.")]) (-> Nat Nat Nat) - (if ("lux int <" ("lux coerce" Int param) 0) + (if ("lux int <" ("lux coerce" Int param) +0) (if (n/< param subject) |0 |1) @@ -2469,11 +2469,11 @@ (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) division.")]) (-> Rev Rev Rev) - (if ("lux i64 =" 0 param) + (if ("lux i64 =" +0 param) ("lux io error" "Cannot divide Rev by zero!") (let' [[trailing-zeroes remaining] (without-trailing-zeroes |0 ("lux coerce" Nat param)) [trailing-zeroes denominator] ("lux check" (#Product Nat Nat) - (if ("lux i64 =" 0 trailing-zeroes) + (if ("lux i64 =" +0 trailing-zeroes) [|1 ("lux i64 logical-right-shift" |1 remaining)] [trailing-zeroes remaining])) shift ("lux i64 -" trailing-zeroes |64) @@ -2560,7 +2560,7 @@ (let' [loop ("lux check" (-> Nat Text Text) (function' recur [input output] (if (n/= |0 input) - (text/compose "+" output) + (text/compose "|" output) (recur (n// |10 input) (text/compose (|> input (n/% |10) digit-to-text) output)))))] @@ -2570,27 +2570,27 @@ (def:''' (int/abs value) #Nil (-> Int Int) - (if (i/< 0 value) + (if (i/< +0 value) (i/* -1 value) value)) (def:''' (int/encode value) #Nil (-> Int Text) - (if (i/= 0 value) + (if (i/= +0 value) "0" - (let' [sign (if (i/> 0 value) + (let' [sign (if (i/> +0 value) "" "-")] (("lux check" (-> Int Text Text) (function' recur [input output] - (if (i/= 0 input) + (if (i/= +0 input) (text/compose sign output) - (recur (i// 10 input) - (text/compose (|> input (i/% 10) ("lux coerce" Nat) digit-to-text) + (recur (i// +10 input) + (text/compose (|> input (i/% +10) ("lux coerce" Nat) digit-to-text) output))))) - (|> value (i// 10) int/abs) - (|> value (i/% 10) int/abs ("lux coerce" Nat) digit-to-text))))) + (|> value (i// +10) int/abs) + (|> value (i/% +10) int/abs ("lux coerce" Nat) digit-to-text))))) (def:''' (frac/encode x) #Nil @@ -2836,7 +2836,7 @@ (macro:' #export (: tokens) (list [(tag$ ["lux" "doc"]) (text$ "## The type-annotation macro. - (: (List Int) (list 1 2 3))")]) + (: (List Int) (list +1 +2 +3))")]) ({(#Cons type (#Cons value #Nil)) (return (list (` ("lux check" (type (~ type)) (~ value))))) @@ -2847,7 +2847,7 @@ (macro:' #export (:coerce tokens) (list [(tag$ ["lux" "doc"]) (text$ "## The type-coercion macro. - (:coerce Dinosaur (list 1 2 3))")]) + (:coerce Dinosaur (list +1 +2 +3))")]) ({(#Cons type (#Cons value #Nil)) (return (list (` ("lux coerce" (type (~ type)) (~ value))))) @@ -3117,7 +3117,7 @@ (list [(tag$ ["lux" "doc"]) (text$ "## The pattern-matching macro. ## Allows the usage of macros within the patterns to provide custom syntax. - (case (: (List Int) (list 1 2 3)) + (case (: (List Int) (list +1 +2 +3)) (#Cons x (#Cons y (#Cons z #Nil))) (#Some ($_ i/* x y z)) @@ -3136,7 +3136,7 @@ (list [(tag$ ["lux" "doc"]) (text$ "## Macro-expanding patterns. ## It's a special macro meant to be used with 'case'. - (case (: (List Int) (list 1 2 3)) + (case (: (List Int) (list +1 +2 +3)) (^ (list x y z)) (#Some ($_ i/* x y z)) @@ -3353,7 +3353,7 @@ (def: branching-exponent Int - 5)")]) + +5)")]) (let [[export? tokens'] (export^ tokens) parts (: (Maybe [Code (List Code) (Maybe Code) Code (List [Code Code])]) (case tokens' @@ -3610,9 +3610,9 @@ (macro: (default tokens state) {#.doc "## Allows you to provide a default value that will be used ## if a (Maybe x) value turns out to be #.None. - (default 20 (#.Some 10)) => 10 + (default +20 (#.Some +10)) => +10 - (default 20 #.None) => 20"} + (default +20 #.None) => +20"} (case tokens (^ (list else maybe)) (let [g!temp (: Code [dummy-cursor (#Identifier ["" ""])]) @@ -4872,7 +4872,7 @@ (:: Codec<Text,Int> encode) ## Also allows using that value as a function. - (:: Codec<Text,Int> encode 123)"} + (:: Codec<Text,Int> encode +123)"} (case tokens (^ (list struct [_ (#Identifier member)])) (return (list (` (let [(^open ".") (~ struct)] (~ (identifier$ member)))))) @@ -5199,7 +5199,7 @@ (def: (repeat n x) (All [a] (-> Int a (List a))) - (if (i/> 0 n) + (if (i/> +0 n) (#Cons x (repeat (i/+ -1 n) x)) #Nil)) @@ -5289,9 +5289,9 @@ ## For Example: (doc \"Allows arbitrary looping, using the \\\"recur\\\" form to re-start the loop. Can be used in monadic code to create monadic loops.\" - (loop [count 0 + (loop [count +0 x init] - (if (< 10 count) + (if (< +10 count) (recur (inc count) (f x)) x)))"} (return (list (` [(~ cursor-code) @@ -5354,17 +5354,17 @@ (macro: #export (loop tokens) {#.doc (doc "Allows arbitrary looping, using the \"recur\" form to re-start the loop." "Can be used in monadic code to create monadic loops." - (loop [count 0 + (loop [count +0 x init] - (if (< 10 count) + (if (< +10 count) (recur (inc count) (f x)) x)) "Loops can also be given custom names." (loop my-loop - [count 0 + [count +0 x init] - (if (< 10 count) + (if (< +10 count) (my-loop (inc count) (f x)) x)))} (let [?params (case tokens @@ -5497,14 +5497,14 @@ [(bit #1) "#1" [_ (#.Bit #1)]] [(bit #0) "#0" [_ (#.Bit #0)]] - [(int 123) "123" [_ (#.Int 123)]] - [(frac 123.0) "123.0" [_ (#.Frac 123.0)]] + [(int +123) "+123" [_ (#.Int +123)]] + [(frac +123.0) "+123.0" [_ (#.Frac +123.0)]] [(text "\n") "\"\\n\"" [_ (#.Text "\n")]] [(tag ["yolo" "lol"]) "#yolo.lol" [_ (#.Tag ["yolo" "lol"])]] [(identifier ["yolo" "lol"]) "yolo.lol" [_ (#.Identifier ["yolo" "lol"])]] - [(form (list (bit #1) (int 123))) "(#1 123)" (^ [_ (#.Form (list [_ (#.Bit #1)] [_ (#.Int 123)]))])] - [(tuple (list (bit #1) (int 123))) "[#1 123]" (^ [_ (#.Tuple (list [_ (#.Bit #1)] [_ (#.Int 123)]))])] - [(record (list [(bit #1) (int 123)])) "{#1 123}" (^ [_ (#.Record (list [[_ (#.Bit #1)] [_ (#.Int 123)]]))])] + [(form (list (bit #1) (int +123))) "(#1 +123)" (^ [_ (#.Form (list [_ (#.Bit #1)] [_ (#.Int +123)]))])] + [(tuple (list (bit #1) (int +123))) "[#1 +123]" (^ [_ (#.Tuple (list [_ (#.Bit #1)] [_ (#.Int +123)]))])] + [(record (list [(bit #1) (int +123)])) "{#1 +123}" (^ [_ (#.Record (list [[_ (#.Bit #1)] [_ (#.Int +123)]]))])] [(local-tag "lol") "#lol" [_ (#.Tag ["" "lol"])]] [(local-identifier "lol") "lol" [_ (#.Identifier ["" "lol"])]] )] @@ -5716,7 +5716,7 @@ (not (<even> n)))] [Nat n/even? n/odd? n/% n/= |0 |2] - [Int i/even? i/odd? i/% i/= 0 2]) + [Int i/even? i/odd? i/% i/= +0 +2]) (def: (get-scope-type-vars state) (Meta (List Nat)) @@ -5765,11 +5765,11 @@ (def: #export (is? reference sample) {#.doc (doc "Tests whether the 2 values are identical (not just \"equal\")." "This one should succeed:" - (let [value 5] + (let [value +5] (is? value value)) "This one should fail:" - (is? 5 (i/+ 2 3)))} + (is? +5 (i/+ +2 +3)))} (All [a] (-> a a Bit)) ("lux is" reference sample)) @@ -5807,7 +5807,7 @@ (macro: #export (:assume tokens) {#.doc (doc "Coerces the given expression to the type of whatever is expected." - (: Dinosaur (:assume (list 1 2 3))))} + (: Dinosaur (:assume (list +1 +2 +3))))} (case tokens (^ (list expr)) (do Monad<Meta> @@ -5833,7 +5833,7 @@ (macro: #export (:of tokens) {#.doc (doc "Generates the type corresponding to a given definition or variable." - (let [my-num (: Int 123)] + (let [my-num (: Int +123)] (:of my-num)) "==" Int)} @@ -6152,8 +6152,8 @@ (def: #export (i/mod param subject) (All [m] (-> Int Int Int)) (let [raw (i/% param subject)] - (if (i/< 0 raw) - (let [shift (if (i/< 0 param) i/- i/+)] + (if (i/< +0 raw) + (let [shift (if (i/< +0 param) i/- i/+)] (|> raw (shift param))) raw))) @@ -6177,11 +6177,11 @@ (def: #export (frac-to-rev input) (-> Frac Rev) - (let [abs (if (f/< 0.0 input) + (let [abs (if (f/< +0.0 input) (f/* -1.0 input) input)] (|> abs - (f/% 1.0) + (f/% +1.0) (f/* rev-denominator) frac-to-int ("lux i64 left-shift" |11)))) diff --git a/stdlib/source/lux/compiler/default/phase/analysis/structure.lux b/stdlib/source/lux/compiler/default/phase/analysis/structure.lux index 26a91dff6..29203290a 100644 --- a/stdlib/source/lux/compiler/default/phase/analysis/structure.lux +++ b/stdlib/source/lux/compiler/default/phase/analysis/structure.lux @@ -181,7 +181,7 @@ ## the tuple represents the expectations of the user. ## If the type is for a 3-tuple, but a 5-tuple is provided, it ## is assumed that the user intended the following layout: - ## [0, 1, [2, 3, 4]] + ## [+0, +1, [+2, +3, +4]] ## but that, for whatever reason, it was written in a flat ## way. [tailT tailC] diff --git a/stdlib/source/lux/compiler/default/phase/translation/scheme/extension/common.jvm.lux b/stdlib/source/lux/compiler/default/phase/translation/scheme/extension/common.jvm.lux index 10a893f09..b1dce6688 100644 --- a/stdlib/source/lux/compiler/default/phase/translation/scheme/extension/common.jvm.lux +++ b/stdlib/source/lux/compiler/default/phase/translation/scheme/extension/common.jvm.lux @@ -91,17 +91,17 @@ (def: (bit::left-shift [subjectO paramO]) Binary - (_.arithmetic-shift/2 (_.remainder/2 (_.int 64) paramO) + (_.arithmetic-shift/2 (_.remainder/2 (_.int +64) paramO) subjectO)) (def: (bit::arithmetic-right-shift [subjectO paramO]) Binary - (_.arithmetic-shift/2 (|> paramO (_.remainder/2 (_.int 64)) (_.*/2 (_.int -1))) + (_.arithmetic-shift/2 (|> paramO (_.remainder/2 (_.int +64)) (_.*/2 (_.int -1))) subjectO)) (def: (bit::logical-right-shift [subjectO paramO]) Binary - (runtime.bit//logical-right-shift (_.remainder/2 (_.int 64) paramO) subjectO)) + (runtime.bit//logical-right-shift (_.remainder/2 (_.int +64) paramO) subjectO)) (def: bundle::bit Bundle @@ -209,7 +209,7 @@ (bundle.install "%" (binary int::%)) (bundle.install "=" (binary int::=)) (bundle.install "<" (binary int::<)) - (bundle.install "to-frac" (unary (|>> (_.//2 (_.float 1.0))))) + (bundle.install "to-frac" (unary (|>> (_.//2 (_.float +1.0))))) (bundle.install "char" (unary int::char))))) (def: bundle::frac @@ -302,7 +302,7 @@ (def: (atom::read atom) Unary - (_.vector-ref/2 atom (_.int 0))) + (_.vector-ref/2 atom (_.int +0))) (def: (atom::compare-and-swap [atomO oldO newO]) Trinary @@ -332,7 +332,7 @@ ## [[Processes]] (def: (process::parallelism-level []) Nullary - (_.int 1)) + (_.int +1)) (def: bundle::process Bundle diff --git a/stdlib/source/lux/compiler/default/phase/translation/scheme/function.jvm.lux b/stdlib/source/lux/compiler/default/phase/translation/scheme/function.jvm.lux index 437c92520..bf65a7606 100644 --- a/stdlib/source/lux/compiler/default/phase/translation/scheme/function.jvm.lux +++ b/stdlib/source/lux/compiler/default/phase/translation/scheme/function.jvm.lux @@ -77,7 +77,7 @@ (_.apply/2 (_.global "apply") (_.global "values") @curried)])) bodyO)) (_.if (|> @num-args (_.>/2 arityO)) - (let [arity-args (runtime.slice (_.int 0) arityO @curried) + (let [arity-args (runtime.slice (_.int +0) arityO @curried) output-func-args (runtime.slice arityO (|> @num-args (_.-/2 arityO)) @curried)] diff --git a/stdlib/source/lux/compiler/default/phase/translation/scheme/runtime.jvm.lux b/stdlib/source/lux/compiler/default/phase/translation/scheme/runtime.jvm.lux index a2c9e31da..d72312693 100644 --- a/stdlib/source/lux/compiler/default/phase/translation/scheme/runtime.jvm.lux +++ b/stdlib/source/lux/compiler/default/phase/translation/scheme/runtime.jvm.lux @@ -114,14 +114,14 @@ (runtime: (slice offset length list) (<| (_.if (_.null?/1 list) list) - (_.if (|> offset (_.>/2 (_.int 0))) - (slice (|> offset (_.-/2 (_.int 1))) + (_.if (|> offset (_.>/2 (_.int +0))) + (slice (|> offset (_.-/2 (_.int +1))) length (_.cdr/1 list))) - (_.if (|> length (_.>/2 (_.int 0))) + (_.if (|> length (_.>/2 (_.int +0))) (_.cons/2 (_.car/1 list) (slice offset - (|> length (_.-/2 (_.int 1))) + (|> length (_.-/2 (_.int +1))) (_.cdr/1 list)))) _.nil)) @@ -157,7 +157,7 @@ (def: minimum-index-length (-> Expression Computation) - (|>> (_.+/2 (_.int 1)))) + (|>> (_.+/2 (_.int +1)))) (def: product-element (-> Expression Expression Computation) @@ -165,7 +165,7 @@ (def: (product-tail product) (-> Expression Computation) - (_.vector-ref/2 product (|> (_.length/1 product) (_.-/2 (_.int 1))))) + (_.vector-ref/2 product (|> (_.length/1 product) (_.-/2 (_.int +1))))) (def: (updated-index min-length product) (-> Expression Expression Computation) @@ -202,7 +202,7 @@ (_.begin (list (_.define @slice [(list) #.None] (_.make-vector/1 (|> @product_length (_.-/2 index)))) - (_.vector-copy!/5 @slice (_.int 0) product index @product_length) + (_.vector-copy!/5 @slice (_.int +0) product index @product_length) @slice))))))) (runtime: (sum//get sum last? wanted-tag) @@ -235,11 +235,11 @@ @@sum//get))) (runtime: (bit//logical-right-shift shift input) - (_.if (_.=/2 (_.int 0) shift) + (_.if (_.=/2 (_.int +0) shift) input (|> input (_.arithmetic-shift/2 (_.*/2 (_.int -1) shift)) - (_.bit-and/2 (_.int (hex "7FFFFFFFFFFFFFFF")))))) + (_.bit-and/2 (_.int (hex "+7FFFFFFFFFFFFFFF")))))) (def: runtime//bit Computation @@ -286,10 +286,10 @@ (runtime: (atom//compare-and-swap atom old new) (with-vars [@temp] - (_.let (list [@temp (_.vector-ref/2 atom (_.int 0))]) + (_.let (list [@temp (_.vector-ref/2 atom (_.int +0))]) (_.if (_.eq?/2 old @temp) (_.begin - (list (_.vector-set!/3 atom (_.int 0) new) + (list (_.vector-set!/3 atom (_.int +0) new) (_.bool #1))) (_.bool #0))))) @@ -300,7 +300,7 @@ (runtime: (box//write value box) (_.begin (list - (_.vector-set!/3 box (_.int 0) value) + (_.vector-set!/3 box (_.int +0) value) ..unit))) (def: runtime//box @@ -309,7 +309,7 @@ (runtime: (io//current-time _) (|> (_.apply/* (_.global "current-second") (list)) - (_.*/2 (_.int 1_000)) + (_.*/2 (_.int +1_000)) _.exact/1)) (def: runtime//io @@ -334,7 +334,7 @@ (_.set! process//incoming (_.cons/2 process process//incoming)))] (_.begin (list - (_.if (_.=/2 (_.int 0) milli-seconds) + (_.if (_.=/2 (_.int +0) milli-seconds) (process//future procedure) (with-vars [@start @process @now @ignored] (_.let (list [@start (io//current-time ..unit)]) diff --git a/stdlib/source/lux/compiler/default/syntax.lux b/stdlib/source/lux/compiler/default/syntax.lux index b5e9acb51..f88cedc9b 100644 --- a/stdlib/source/lux/compiler/default/syntax.lux +++ b/stdlib/source/lux/compiler/default/syntax.lux @@ -317,9 +317,9 @@ _ (l.this? "/") denominator frac-ratio-fragment _ (p.assert "Denominator cannot be 0." - (not (f/= 0.0 denominator)))] + (not (f/= +0.0 denominator)))] (wrap (|> numerator - (f/* (if signed? -1.0 1.0)) + (f/* (if signed? -1.0 +1.0)) (f// denominator)))))] (wrap [(update@ #.column (n/+ (text.size chunk)) where) [where (#.Frac value)]]))) diff --git a/stdlib/source/lux/control/comonad.lux b/stdlib/source/lux/control/comonad.lux index ef262762f..7efe24942 100644 --- a/stdlib/source/lux/control/comonad.lux +++ b/stdlib/source/lux/control/comonad.lux @@ -32,7 +32,7 @@ {#.doc (doc "A co-monadic parallel to the \"do\" macro." (let [square (function (_ n) (i/* n n))] (be CoMonad<Stream> - [inputs (iterate inc 2)] + [inputs (iterate inc +2)] (square (head inputs)))))} (case tokens (#.Cons comonad (#.Cons [_ (#.Tuple bindings)] (#.Cons body #.Nil))) diff --git a/stdlib/source/lux/control/contract.lux b/stdlib/source/lux/control/contract.lux index 72aefd174..065829f44 100644 --- a/stdlib/source/lux/control/contract.lux +++ b/stdlib/source/lux/control/contract.lux @@ -19,8 +19,8 @@ {#.doc (doc "Pre-conditions." "Given a test and an expression to run, only runs the expression if the test passes." "Otherwise, an error is raised." - (pre (i/= 4 (i/+ 2 2)) - (foo 123 456 789)))} + (pre (i/= +4 (i/+ +2 +2)) + (foo +123 +456 +789)))} (wrap (list (` (exec (assert! (~ (code.text (format "Pre-condition failed: " (%code test)))) (~ test)) (~ expr)))))) @@ -31,7 +31,7 @@ "If the predicate returns #1, returns the value of the expression." "Otherwise, an error is raised." (post i/even? - (i/+ 2 2)))} + (i/+ +2 +2)))} (with-gensyms [g!output] (wrap (list (` (let [(~ g!output) (~ expr)] (exec (assert! (~ (code.text (format "Post-condition failed: " (%code test)))) diff --git a/stdlib/source/lux/control/pipe.lux b/stdlib/source/lux/control/pipe.lux index 716304479..a9a97b0c9 100644 --- a/stdlib/source/lux/control/pipe.lux +++ b/stdlib/source/lux/control/pipe.lux @@ -18,10 +18,10 @@ (syntax: #export (new> {tokens (p.at-least |2 s.any)}) {#.doc (doc "Ignores the piped argument, and begins a new pipe." - (|> 20 - (i/* 3) - (i/+ 4) - (new> 0 inc)))} + (|> +20 + (i/* +3) + (i/+ +4) + (new> +0 inc)))} (case (list.reverse tokens) (^ (list& _ r-body)) (wrap (list (` (|> (~+ (list.reverse r-body)))))) @@ -31,7 +31,7 @@ (syntax: #export (let> binding body prev) {#.doc (doc "Gives a name to the piped-argument, within the given expression." - (|> 5 + (|> +5 (let> X (i/+ X X))))} (wrap (list (` (let [(~ binding) (~ prev)] (~ body)))))) @@ -48,9 +48,9 @@ {branches (p.some (p.and body^ body^))}) {#.doc (doc "Branching for pipes." "Both the tests and the bodies are piped-code, and must be given inside a tuple." - (|> 5 - (cond> [i/even?] [(i/* 2)] - [i/odd?] [(i/* 3)] + (|> +5 + (cond> [i/even?] [(i/* +2)] + [i/odd?] [(i/* +3)] [(new> -1)])))} (with-gensyms [g!temp] (wrap (list (` (with-expansions @@ -71,8 +71,8 @@ prev) {#.doc (doc "Loops for pipes." "Both the testing and calculating steps are pipes and must be given inside tuples." - (|> 1 - (loop> [(i/< 10)] + (|> +1 + (loop> [(i/< +10)] [inc])))} (with-gensyms [g!temp] (wrap (list (` (loop [(~ g!temp) (~ prev)] @@ -85,10 +85,10 @@ prev) {#.doc (doc "Monadic pipes." "Each steps in the monadic computation is a pipe and must be given inside a tuple." - (|> 5 + (|> +5 (do> Monad<Identity> - [(i/* 3)] - [(i/+ 4)] + [(i/* +3)] + [(i/+ +4)] [inc])))} (with-gensyms [g!temp] (case (list.reverse steps) @@ -108,9 +108,9 @@ prev) {#.doc (doc "Non-updating pipes." "Will generate piped computations, but their results will not be used in the larger scope." - (|> 5 + (|> +5 (exec> [.nat %n log!]) - (i/* 10)))} + (i/* +10)))} (with-gensyms [g!temp] (wrap (list (` (let [(~ g!temp) (~ prev)] (exec (|> (~ g!temp) (~+ body)) @@ -120,11 +120,11 @@ prev) {#.doc (doc "Parallel branching for pipes." "Allows to run multiple pipelines for a value and gives you a tuple of the outputs." - (|> 5 - (tuple> [(i/* 10)] - [dec (i// 2)] + (|> +5 + (tuple> [(i/* +10)] + [dec (i// +2)] [Int/encode])) - "Will become: [50 2 \"5\"]")} + "Will become: [+50 +2 \"+5\"]")} (with-gensyms [g!temp] (wrap (list (` (let [(~ g!temp) (~ prev)] [(~+ (list/map (function (_ body) (` (|> (~ g!temp) (~+ body)))) @@ -134,17 +134,17 @@ prev) {#.doc (doc "Pattern-matching for pipes." "The bodies of each branch are NOT pipes; just regular values." - (|> 5 - (case> 0 "zero" - 1 "one" - 2 "two" - 3 "three" - 4 "four" - 5 "five" - 6 "six" - 7 "seven" - 8 "eight" - 9 "nine" + (|> +5 + (case> +0 "zero" + +1 "one" + +2 "two" + +3 "three" + +4 "four" + +5 "five" + +6 "six" + +7 "seven" + +8 "eight" + +9 "nine" _ "???")))} (wrap (list (` (case (~ prev) (~+ (list/join (list/map (function (_ [pattern body]) (list pattern body)) diff --git a/stdlib/source/lux/data/collection/row.lux b/stdlib/source/lux/data/collection/row.lux index ddedad6c5..c9e2c6786 100644 --- a/stdlib/source/lux/data/collection/row.lux +++ b/stdlib/source/lux/data/collection/row.lux @@ -343,7 +343,7 @@ ## [Syntax] (syntax: #export (row {elems (p.some s.any)}) {#.doc (doc "Row literals." - (row 10 20 30 40))} + (row +10 +20 +30 +40))} (wrap (list (` (from-list (list (~+ elems))))))) ## [Structures] diff --git a/stdlib/source/lux/data/collection/sequence.lux b/stdlib/source/lux/data/collection/sequence.lux index 95d60b555..ed06547c2 100644 --- a/stdlib/source/lux/data/collection/sequence.lux +++ b/stdlib/source/lux/data/collection/sequence.lux @@ -138,7 +138,7 @@ {branches (p.some s.any)}) {#.doc (doc "Allows destructuring of sequences in pattern-matching expressions." "Caveat emptor: Only use it for destructuring, and not for testing values within the sequences." - (let [(^sequence& x y z _tail) (some-sequence-func 1 2 3)] + (let [(^sequence& x y z _tail) (some-sequence-func +1 +2 +3)] (func x y z)))} (with-gensyms [g!sequence] (let [body+ (` (let [(~+ (list/join (list/map (function (_ pattern) diff --git a/stdlib/source/lux/data/collection/tree/rose.lux b/stdlib/source/lux/data/collection/tree/rose.lux index 62b65422a..fc25f414f 100644 --- a/stdlib/source/lux/data/collection/tree/rose.lux +++ b/stdlib/source/lux/data/collection/tree/rose.lux @@ -49,9 +49,9 @@ (syntax: #export (tree {root tree^}) {#.doc (doc "Tree literals." - (tree Int [10 {20 {} - 30 {} - 40 {}}]))} + (tree Int [+10 {+20 {} + +30 {} + +40 {}}]))} (wrap (list (` (~ (loop [[value children] root] (` {#value (~ value) #children (list (~+ (list/map recur children)))}))))))) diff --git a/stdlib/source/lux/data/color.lux b/stdlib/source/lux/data/color.lux index c708e8775..2eb8bd35f 100644 --- a/stdlib/source/lux/data/color.lux +++ b/stdlib/source/lux/data/color.lux @@ -53,62 +53,62 @@ blue (scale-down blue) max ($_ f/max red green blue) min ($_ f/min red green blue) - luminance (|> (f/+ max min) (f// 2.0))] + luminance (|> (f/+ max min) (f// +2.0))] (if (f/= max min) ## Achromatic - [0.0 0.0 luminance] + [+0.0 +0.0 luminance] ## Chromatic (let [diff (|> max (f/- min)) saturation (|> diff - (f// (if (f/> 0.5 luminance) - (|> 2.0 (f/- max) (f/- min)) + (f// (if (f/> +0.5 luminance) + (|> +2.0 (f/- max) (f/- min)) (|> max (f/+ min))))) hue' (cond (f/= red max) (|> green (f/- blue) (f// diff) - (f/+ (if (f/< blue green) 6.0 0.0))) + (f/+ (if (f/< blue green) +6.0 +0.0))) (f/= green max) (|> blue (f/- red) (f// diff) - (f/+ 2.0)) + (f/+ +2.0)) ## (f/= blue max) (|> red (f/- green) (f// diff) - (f/+ 4.0)))] - [(|> hue' (f// 6.0)) + (f/+ +4.0)))] + [(|> hue' (f// +6.0)) saturation luminance])))) (def: (hue-to-rgb p q t) (-> Frac Frac Frac Frac) - (let [t (cond (f/< 0.0 t) (f/+ 1.0 t) - (f/> 1.0 t) (f/- 1.0 t) + (let [t (cond (f/< +0.0 t) (f/+ +1.0 t) + (f/> +1.0 t) (f/- +1.0 t) ## else t) - f2/3 (f// 3.0 2.0)] - (cond (f/< (f// 6.0 1.0) t) - (|> q (f/- p) (f/* 6.0) (f/* t) (f/+ p)) + f2/3 (f// +3.0 +2.0)] + (cond (f/< (f// +6.0 +1.0) t) + (|> q (f/- p) (f/* +6.0) (f/* t) (f/+ p)) - (f/< (f// 2.0 1.0) t) + (f/< (f// +2.0 +1.0) t) q (f/< f2/3 t) - (|> q (f/- p) (f/* (|> f2/3 (f/- t))) (f/* 6.0) (f/+ p)) + (|> q (f/- p) (f/* (|> f2/3 (f/- t))) (f/* +6.0) (f/+ p)) ## else p))) (def: #export (from-hsl [hue saturation luminance]) (-> [Frac Frac Frac] Color) - (if (f/= 0.0 saturation) + (if (f/= +0.0 saturation) ## Achromatic (let [intensity (scale-up luminance)] (color [intensity intensity intensity])) ## Chromatic - (let [q (if (f/< 0.5 luminance) - (|> saturation (f/+ 1.0) (f/* luminance)) + (let [q (if (f/< +0.5 luminance) + (|> saturation (f/+ +1.0) (f/* luminance)) (|> luminance (f/+ saturation) (f/- (f/* saturation luminance)))) - p (|> luminance (f/* 2.0) (f/- q)) - third (|> 1.0 (f// 3.0))] + p (|> luminance (f/* +2.0) (f/- q)) + third (|> +1.0 (f// +3.0))] (color [(scale-up (|> hue (f/+ third) (hue-to-rgb p q))) (scale-up (|> hue (hue-to-rgb p q))) (scale-up (|> hue (f/- third) (hue-to-rgb p q)))])))) @@ -123,38 +123,38 @@ min ($_ f/min red green blue) brightness max diff (|> max (f/- min)) - saturation (if (f/= 0.0 max) - 0.0 + saturation (if (f/= +0.0 max) + +0.0 (|> diff (f// max)))] (if (f/= max min) ## Achromatic - [0.0 saturation brightness] + [+0.0 saturation brightness] ## Chromatic (let [hue (cond (f/= red max) (|> green (f/- blue) (f// diff) - (f/+ (if (f/< blue green) 6.0 0.0))) + (f/+ (if (f/< blue green) +6.0 +0.0))) (f/= green max) (|> blue (f/- red) (f// diff) - (f/+ 2.0)) + (f/+ +2.0)) ## (f/= blue max) (|> red (f/- green) (f// diff) - (f/+ 4.0)))] - [(|> hue (f// 6.0)) + (f/+ +4.0)))] + [(|> hue (f// +6.0)) saturation brightness])))) (def: #export (from-hsb [hue saturation brightness]) (-> [Frac Frac Frac] Color) - (let [hue (|> hue (f/* 6.0)) + (let [hue (|> hue (f/* +6.0)) i (math.floor hue) f (|> hue (f/- i)) - p (|> 1.0 (f/- saturation) (f/* brightness)) - q (|> 1.0 (f/- (f/* f saturation)) (f/* brightness)) - t (|> 1.0 (f/- (|> 1.0 (f/- f) (f/* saturation))) (f/* brightness)) + p (|> +1.0 (f/- saturation) (f/* brightness)) + q (|> +1.0 (f/- (f/* f saturation)) (f/* brightness)) + t (|> +1.0 (f/- (|> +1.0 (f/- f) (f/* saturation))) (f/* brightness)) v brightness - mod (|> i (f/% 6.0) frac-to-int .nat) + mod (|> i (f/% +6.0) frac-to-int .nat) red (case mod |0 v |1 q |2 p |3 p |4 t |5 v _ (undefined)) green (case mod |0 t |1 v |2 v |3 q |4 p |5 p _ (undefined)) blue (case mod |0 p |1 p |2 t |3 v |4 v |5 q _ (undefined))] @@ -168,34 +168,34 @@ red (scale-down red) green (scale-down green) blue (scale-down blue) - key (|> 1.0 (f/- ($_ f/max red green blue))) - f (if (f/< 1.0 key) - (|> 1.0 (f// (|> 1.0 (f/- key)))) - 0.0) - cyan (|> 1.0 (f/- red) (f/- key) (f/* f)) - magenta (|> 1.0 (f/- green) (f/- key) (f/* f)) - yellow (|> 1.0 (f/- blue) (f/- key) (f/* f))] + key (|> +1.0 (f/- ($_ f/max red green blue))) + f (if (f/< +1.0 key) + (|> +1.0 (f// (|> +1.0 (f/- key)))) + +0.0) + cyan (|> +1.0 (f/- red) (f/- key) (f/* f)) + magenta (|> +1.0 (f/- green) (f/- key) (f/* f)) + yellow (|> +1.0 (f/- blue) (f/- key) (f/* f))] [cyan magenta yellow key])) (def: #export (from-cmyk [cyan magenta yellow key]) (-> [Frac Frac Frac Frac] Color) - (if (f/= 1.0 key) + (if (f/= +1.0 key) (color [|0 |0 |0]) - (let [red (|> (|> 1.0 (f/- cyan)) - (f/* (|> 1.0 (f/- key)))) - green (|> (|> 1.0 (f/- magenta)) - (f/* (|> 1.0 (f/- key)))) - blue (|> (|> 1.0 (f/- yellow)) - (f/* (|> 1.0 (f/- key))))] + (let [red (|> (|> +1.0 (f/- cyan)) + (f/* (|> +1.0 (f/- key)))) + green (|> (|> +1.0 (f/- magenta)) + (f/* (|> +1.0 (f/- key)))) + blue (|> (|> +1.0 (f/- yellow)) + (f/* (|> +1.0 (f/- key))))] (color [(scale-up red) (scale-up green) (scale-up blue)])))) (def: (normalize ratio) (-> Frac Frac) - (cond (f/> 1.0 ratio) - (f/% 1.0 ratio) + (cond (f/> +1.0 ratio) + (f/% +1.0 ratio) - (f/< 0.0 ratio) - (|> 1.0 (f/+ (f/% 1.0 ratio))) + (f/< +0.0 ratio) + (|> +1.0 (f/+ (f/% +1.0 ratio))) ## else ratio)) @@ -203,7 +203,7 @@ (def: #export (interpolate ratio end start) (-> Frac Color Color Color) (let [dS (normalize ratio) - dE (|> 1.0 (f/- dS)) + dE (|> +1.0 (f/- dS)) interpolate' (: (-> Nat Nat Nat) (function (_ end start) (|> (|> start .int int-to-frac (f/* dS)) @@ -242,8 +242,8 @@ (let [[hue saturation luminance] (to-hsl color)] (from-hsl [hue (|> saturation - (f/* (|> 1.0 (<op> (normalize ratio)))) - (f/min 1.0)) + (f/* (|> +1.0 (<op> (normalize ratio)))) + (f/min +1.0)) luminance])))] [saturate f/+] @@ -253,7 +253,7 @@ (def: #export (gray-scale color) (-> Color Color) (let [[_ _ luminance] (to-hsl color)] - (from-hsl [0.0 0.0 luminance]))) + (from-hsl [+0.0 +0.0 luminance]))) (do-template [<name> <1> <2>] [(def: #export (<name> color) @@ -263,9 +263,9 @@ (from-hsl [(|> hue (f/+ <1>) normalize) saturation luminance]) (from-hsl [(|> hue (f/+ <2>) normalize) saturation luminance])]))] - [triad (|> 1.0 (f// 3.0)) (|> 2.0 (f// 3.0))] - [clash (|> 1.0 (f// 4.0)) (|> 3.0 (f// 4.0))] - [split-complement (|> 1.0 (f// 5.0)) (|> 3.0 (f// 5.0))] + [triad (|> +1.0 (f// +3.0)) (|> +2.0 (f// +3.0))] + [clash (|> +1.0 (f// +4.0)) (|> +3.0 (f// +4.0))] + [split-complement (|> +1.0 (f// +5.0)) (|> +3.0 (f// +5.0))] ) (do-template [<name> <1> <2> <3>] @@ -277,8 +277,8 @@ (from-hsl [(|> hue (f/+ <2>) normalize) saturation luminance]) (from-hsl [(|> hue (f/+ <3>) normalize) saturation luminance])]))] - [square (|> 1.0 (f// 4.0)) (|> 2.0 (f// 4.0)) (|> 3.0 (f// 4.0))] - [tetradic (|> 2.0 (f// 12.0)) (|> 6.0 (f// 12.0)) (|> 8.0 (f// 12.0))] + [square (|> +1.0 (f// +4.0)) (|> +2.0 (f// +4.0)) (|> +3.0 (f// +4.0))] + [tetradic (|> +2.0 (f// +12.0)) (|> +6.0 (f// +12.0)) (|> +8.0 (f// +12.0))] ) (def: #export (analogous results slice color) @@ -298,7 +298,7 @@ (if (n/= |0 results) (list) (let [[hue saturation brightness] (to-hsb color) - slice (|> 1.0 (f// (|> results .int int-to-frac)))] + slice (|> +1.0 (f// (|> results .int int-to-frac)))] (|> (list.n/range |0 (dec results)) (list/map (|>> .int int-to-frac (f/* slice) diff --git a/stdlib/source/lux/data/error.lux b/stdlib/source/lux/data/error.lux index 8054736e9..17d88a5a0 100644 --- a/stdlib/source/lux/data/error.lux +++ b/stdlib/source/lux/data/error.lux @@ -86,10 +86,10 @@ (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!"))))} + (is? +10 + (default +20 (#Success +10))) + (is? +20 + (default +20 (#Error "KABOOM!"))))} (case tokens (^ (list else error)) (#Success [compiler (list (` (case (~ error) diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 02c05f5dd..549631f2a 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -55,7 +55,7 @@ (syntax: #export (json token) {#.doc (doc "A simple way to produce JSON literals." (json #1) - (json 123.456) + (json +123.456) (json "Some text") (json #null) (json ["this" "is" "an" "array"]) diff --git a/stdlib/source/lux/data/maybe.lux b/stdlib/source/lux/data/maybe.lux index d6b44e02d..57ff95727 100644 --- a/stdlib/source/lux/data/maybe.lux +++ b/stdlib/source/lux/data/maybe.lux @@ -84,9 +84,9 @@ (macro: #export (default tokens state) {#.doc "## Allows you to provide a default value that will be used ## if a (Maybe x) value turns out to be #.None. - (default 20 (#.Some 10)) => 10 + (default +20 (#.Some +10)) => +10 - (default 20 #.None) => 20"} + (default +20 #.None) => +20"} (case tokens (^ (list else maybe)) (let [g!temp (: Code [dummy-cursor (#.Identifier ["" ""])]) diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux index 9934af3de..573e422d6 100644 --- a/stdlib/source/lux/data/number.lux +++ b/stdlib/source/lux/data/number.lux @@ -10,7 +10,7 @@ interval [codec (#+ Codec)]] [data - ["e" error] + ["." error (#+ Error)] ["." maybe] ["." text]]] [/ @@ -74,8 +74,8 @@ <1>)) )] - [ Int Order<Int> i/+ i/- i/* i// i/% i/= i/< 0 1 -1] - [Frac Order<Frac> f/+ f/- f/* f// f/% f/= f/< 0.0 1.0 -1.0] + [ Int Order<Int> i/+ i/- i/* i// i/% i/= i/< +0 +1 -1] + [Frac Order<Frac> f/+ f/- f/* f// f/% f/= f/< +0.0 +1.0 -1.0] ) (structure: #export _ (Number Rev) @@ -108,7 +108,7 @@ (def: bottom <bottom>))] [ Nat Enum<Nat> (:coerce Nat -1) |0] - [ Int Enum<Int> 9_223_372_036_854_775_807 -9_223_372_036_854_775_808] + [ Int Enum<Int> +9_223_372_036_854_775_807 -9_223_372_036_854_775_808] [Frac Enum<Frac> ("lux frac max") ("lux frac min")] [ Rev Enum<Rev> (:coerce Rev -1) (:coerce Rev |0)] ) @@ -122,12 +122,12 @@ [ Mul@Monoid<Nat> Nat |1 n/*] [ Max@Monoid<Nat> Nat (:: Interval<Nat> bottom) n/max] [ Min@Monoid<Nat> Nat (:: Interval<Nat> top) n/min] - [ Add@Monoid<Int> Int 0 i/+] - [ Mul@Monoid<Int> Int 1 i/*] + [ Add@Monoid<Int> Int +0 i/+] + [ Mul@Monoid<Int> Int +1 i/*] [ Max@Monoid<Int> Int (:: Interval<Int> bottom) i/max] [ Min@Monoid<Int> Int (:: Interval<Int> top) i/min] - [Add@Monoid<Frac> Frac 0.0 f/+] - [Mul@Monoid<Frac> Frac 1.0 f/*] + [Add@Monoid<Frac> Frac +0.0 f/+] + [Mul@Monoid<Frac> Frac +1.0 f/*] [Max@Monoid<Frac> Frac (:: Interval<Frac> bottom) f/max] [Min@Monoid<Frac> Frac (:: Interval<Frac> top) f/min] [ Add@Monoid<Rev> Rev (:: Interval<Rev> bottom) r/+] @@ -140,10 +140,10 @@ [(def: #export <name> {#.doc <doc>} Frac - (f// 0.0 <numerator>))] + (f// +0.0 <numerator>))] - [not-a-number 0.0 "Not a number."] - [positive-infinity 1.0 "Positive infinity."] + [not-a-number +0.0 "Not a number."] + [positive-infinity +1.0 "Positive infinity."] [negative-infinity -1.0 "Negative infinity."] ) @@ -166,10 +166,10 @@ (def: (decode input) (case (<decoder> [input]) (#.Some value) - (#e.Success value) + (#error.Success value) #.None - (#e.Error <error>))))] + (#error.Error <error>))))] [Frac "lux frac encode" "lux frac decode" "Could not decode Frac"] ) @@ -314,16 +314,16 @@ (let [digit (maybe.assume (get-char repr idx))] (case (<to-value> digit) #.None - (#e.Error ("lux text concat" <error> repr)) + (#error.Error ("lux text concat" <error> repr)) (#.Some digit-value) (recur (inc idx) (|> output (n/* <base>) (n/+ digit-value))))) - (#e.Success output))) + (#error.Success output))) _ - (#e.Error ("lux text concat" <error> repr))) - (#e.Error ("lux text concat" <error> repr))))))] + (#error.Error ("lux text concat" <error> repr))) + (#error.Error ("lux text concat" <error> repr))))))] [Binary@Codec<Text,Nat> |2 binary-character binary-value "Invalid binary syntax for Nat: "] [Octal@Codec<Text,Nat> |8 octal-character octal-value "Invalid octal syntax for Nat: "] @@ -331,51 +331,69 @@ [Hex@Codec<Text,Nat> |16 hexadecimal-character hexadecimal-value "Invalid hexadecimal syntax for Nat: "] ) +(def: (int/sign!! value) + (-> Int Text) + (if (i/< +0 value) + "-" + "+")) + +(def: (int/sign?? representation) + (-> Text (Maybe Int)) + (case (get-char representation |0) + (^ (#.Some "-")) + (#.Some -1) + + (^ (#.Some "+")) + (#.Some +1) + + _ + #.None)) + +(def: (int-decode-loop input-size repr sign <base> <to-value> <error>) + (-> Nat Text Int Int (-> Text (Maybe Nat)) Text (Error Int)) + (loop [idx |1 + output +0] + (if (n/< input-size idx) + (let [digit (maybe.assume (get-char repr idx))] + (case (<to-value> digit) + #.None + (#error.Error <error>) + + (#.Some digit-value) + (recur (inc idx) + (|> output (i/* <base>) (i/+ (.int digit-value)))))) + (#error.Success (i/* sign output))))) + (do-template [<struct> <base> <to-character> <to-value> <error>] [(structure: #export <struct> (Codec Text Int) (def: (encode value) - (if (i/= 0 value) - "0" - (let [sign (if (i/< 0 value) - "-" - "")] - (loop [input (|> value (i// <base>) (:: Number<Int> abs)) - output (|> value (i/% <base>) (:: Number<Int> abs) .nat - <to-character> - maybe.assume)] - (if (i/= 0 input) - ("lux text concat" sign output) - (let [digit (maybe.assume (<to-character> (.nat (i/% <base> input))))] - (recur (i// <base> input) - ("lux text concat" digit output)))))))) + (if (i/= +0 value) + "+0" + (loop [input (|> value (i// <base>) (:: Number<Int> abs)) + output (|> value (i/% <base>) (:: Number<Int> abs) .nat + <to-character> + maybe.assume)] + (if (i/= +0 input) + ("lux text concat" (int/sign!! value) output) + (let [digit (maybe.assume (<to-character> (.nat (i/% <base> input))))] + (recur (i// <base> input) + ("lux text concat" digit output))))))) (def: (decode repr) (let [input-size ("lux text size" repr)] - (if (n/>= |1 input-size) - (let [sign (case (get-char repr |0) - (^ (#.Some "-")) - -1 - - _ - 1)] - (loop [idx (if (i/= -1 sign) |1 |0) - output 0] - (if (n/< input-size idx) - (let [digit (maybe.assume (get-char repr idx))] - (case (<to-value> digit) - #.None - (#e.Error <error>) - - (#.Some digit-value) - (recur (inc idx) - (|> output (i/* <base>) (i/+ (:coerce Int digit-value)))))) - (#e.Success (i/* sign output))))) - (#e.Error <error>)))))] - - [Binary@Codec<Text,Int> 2 binary-character binary-value "Invalid binary syntax for Int: "] - [Octal@Codec<Text,Int> 8 octal-character octal-value "Invalid octal syntax for Int: "] - [_ 10 decimal-character decimal-value "Invalid syntax for Int: "] - [Hex@Codec<Text,Int> 16 hexadecimal-character hexadecimal-value "Invalid hexadecimal syntax for Int: "] + (if (n/> |1 input-size) + (case (int/sign?? repr) + (#.Some sign) + (int-decode-loop input-size repr sign <base> <to-value> <error>) + + #.None + (#error.Error <error>)) + (#error.Error <error>)))))] + + [Binary@Codec<Text,Int> +2 binary-character binary-value "Invalid binary syntax for Int: "] + [Octal@Codec<Text,Int> +8 octal-character octal-value "Invalid octal syntax for Int: "] + [_ +10 decimal-character decimal-value "Invalid syntax for Int: "] + [Hex@Codec<Text,Int> +16 hexadecimal-character hexadecimal-value "Invalid hexadecimal syntax for Int: "] ) (def: (de-prefix input) @@ -403,12 +421,12 @@ (case ("lux text char" repr |0) (^multi (^ (#.Some (char "."))) [(:: <nat> decode ("lux text concat" "|" (de-prefix repr))) - (#e.Success output)]) - (#e.Success (:coerce Rev output)) + (#error.Success output)]) + (#error.Success (:coerce Rev output)) _ - (#e.Error ("lux text concat" <error> repr))) - (#e.Error ("lux text concat" <error> repr))))))] + (#error.Error ("lux text concat" <error> repr))) + (#error.Error ("lux text concat" <error> repr))))))] [Binary@Codec<Text,Rev> Binary@Codec<Text,Nat> |1 "Invalid binary syntax: "] [Octal@Codec<Text,Rev> Octal@Codec<Text,Nat> |3 "Invalid octal syntax: "] @@ -420,17 +438,17 @@ (def: (encode value) (let [whole (frac-to-int value) whole-part (:: <int> encode whole) - decimal (:: Number<Frac> abs (f/% 1.0 value)) - decimal-part (if (f/= 0.0 decimal) + decimal (:: Number<Frac> abs (f/% +1.0 value)) + decimal-part (if (f/= +0.0 decimal) ".0" (loop [dec-left decimal output ""] - (if (f/= 0.0 dec-left) + (if (f/= +0.0 dec-left) ("lux text concat" "." output) (let [shifted (f/* <base> dec-left) digit (|> shifted (f/% <base>) frac-to-int .nat (get-char <char-set>) maybe.assume)] - (recur (f/% 1.0 shifted) + (recur (f/% +1.0 shifted) ("lux text concat" output digit))))))] ("lux text concat" whole-part decimal-part))) @@ -441,34 +459,34 @@ decimal-part (maybe.assume ("lux text clip" repr (inc split-index) ("lux text size" repr)))] (case [(:: <int> decode whole-part) (:: <int> decode decimal-part)] - (^multi [(#e.Success whole) (#e.Success decimal)] - (i/>= 0 decimal)) - (let [sign (if (i/< 0 whole) + (^multi [(#error.Success whole) (#error.Success decimal)] + (i/>= +0 decimal)) + (let [sign (if (i/< +0 whole) -1.0 - 1.0) + +1.0) div-power (loop [muls-left ("lux text size" decimal-part) - output 1.0] + output +1.0] (if (n/= |0 muls-left) output (recur (dec muls-left) (f/* <base> output)))) adjusted-decimal (|> decimal int-to-frac (f// div-power)) dec-rev (case (:: Hex@Codec<Text,Rev> decode ("lux text concat" "." decimal-part)) - (#e.Success dec-rev) + (#error.Success dec-rev) dec-rev - (#e.Error error) + (#error.Error error) (error! error))] - (#e.Success (f/+ (int-to-frac whole) - (f/* sign adjusted-decimal)))) + (#error.Success (f/+ (int-to-frac whole) + (f/* sign adjusted-decimal)))) _ - (#e.Error ("lux text concat" <error> repr)))) + (#error.Error ("lux text concat" <error> repr)))) _ - (#e.Error ("lux text concat" <error> repr)))))] + (#error.Error ("lux text concat" <error> repr)))))] - [Binary@Codec<Text,Frac> Binary@Codec<Text,Int> 2.0 "01" "Invalid binary syntax: "] + [Binary@Codec<Text,Frac> Binary@Codec<Text,Int> +2.0 "01" "Invalid binary syntax: "] ) (def: (segment-digits chunk-size digits) @@ -627,7 +645,7 @@ -1.0 _ - 1.0)] + +1.0)] (case ("lux text index" repr "." |0) (#.Some split-index) (let [whole-part (maybe.assume ("lux text clip" repr (if (f/= -1.0 sign) |1 |0) split-index)) @@ -637,14 +655,14 @@ ("lux text concat" (<to> whole-part)) ("lux text concat" (if (f/= -1.0 sign) "-" "")))] (case (:: Binary@Codec<Text,Frac> decode as-binary) - (#e.Error _) - (#e.Error ("lux text concat" <error> repr)) + (#error.Error _) + (#error.Error ("lux text concat" <error> repr)) output output)) _ - (#e.Error ("lux text concat" <error> repr))))))] + (#error.Error ("lux text concat" <error> repr))))))] [Octal@Codec<Text,Frac> "Invalid octaladecimal syntax: " binary-to-octal octal-to-binary] [Hex@Codec<Text,Frac> "Invalid hexadecimal syntax: " binary-to-hex hex-to-binary] @@ -661,12 +679,12 @@ description [cursor (#.Text ($_ "lux text concat" encoding "\n" underscore))]] - (#e.Success [state (list (` (doc (~ description) - (~ example-1) - (~ example-2))))])) + (#error.Success [state (list (` (doc (~ description) + (~ example-1) + (~ example-2))))])) _ - (#e.Error "Wrong syntax for \"encoding-doc\"."))) + (#error.Error "Wrong syntax for \"encoding-doc\"."))) (def: (underscore-prefixed? number) (-> Text Bit) @@ -687,36 +705,36 @@ (case tokens (#.Cons [meta (#.Text repr')] #.Nil) (if (underscore-prefixed? repr') - (#e.Error <error>) + (#error.Error <error>) (let [repr (clean-underscores repr')] (case (:: <nat> decode repr) - (#e.Success value) - (#e.Success [state (list [meta (#.Nat value)])]) + (#error.Success value) + (#error.Success [state (list [meta (#.Nat value)])]) - (^multi (#e.Error _) - [(:: <int> decode repr) (#e.Success value)]) - (#e.Success [state (list [meta (#.Int value)])]) + (^multi (#error.Error _) + [(:: <int> decode repr) (#error.Success value)]) + (#error.Success [state (list [meta (#.Int value)])]) - (^multi (#e.Error _) - [(:: <rev> decode repr) (#e.Success value)]) - (#e.Success [state (list [meta (#.Rev value)])]) + (^multi (#error.Error _) + [(:: <rev> decode repr) (#error.Success value)]) + (#error.Success [state (list [meta (#.Rev value)])]) - (^multi (#e.Error _) - [(:: <frac> decode repr) (#e.Success value)]) - (#e.Success [state (list [meta (#.Frac value)])]) + (^multi (#error.Error _) + [(:: <frac> decode repr) (#error.Success value)]) + (#error.Success [state (list [meta (#.Frac value)])]) _ - (#e.Error <error>)))) + (#error.Error <error>)))) _ - (#e.Error <error>)))] + (#error.Error <error>)))] [bin Binary@Codec<Text,Nat> Binary@Codec<Text,Int> Binary@Codec<Text,Rev> Binary@Codec<Text,Frac> "Invalid binary syntax." - (encoding-doc "binary" (bin "11001001") (bin "11_00_10_01"))] + (encoding-doc "binary" (bin "+11001001") (bin "+11_00_10_01"))] [oct Octal@Codec<Text,Nat> Octal@Codec<Text,Int> Octal@Codec<Text,Rev> Octal@Codec<Text,Frac> "Invalid octal syntax." - (encoding-doc "octal" (oct "615243") (oct "615_243"))] + (encoding-doc "octal" (oct "+615243") (oct "+615_243"))] [hex Hex@Codec<Text,Nat> Hex@Codec<Text,Int> Hex@Codec<Text,Rev> Hex@Codec<Text,Frac> "Invalid hexadecimal syntax." (encoding-doc "hexadecimal" (hex "deadBEEF") (hex "dead_BEEF"))] @@ -755,7 +773,7 @@ (loop [idx idx carry |0 output output] - (if (i/>= 0 (:coerce Int idx)) + (if (i/>= +0 (:coerce Int idx)) (let [raw (|> (digits-get idx output) (n/* |5) (n/+ carry))] @@ -769,7 +787,7 @@ (loop [times power output (|> (make-digits []) (digits-put power |1))] - (if (i/>= 0 (:coerce Int times)) + (if (i/>= +0 (:coerce Int times)) (recur (dec times) (digits-times-5! power output)) output))) @@ -779,7 +797,7 @@ (loop [idx (dec i64.width) all-zeroes? #1 output ""] - (if (i/>= 0 (:coerce Int idx)) + (if (i/>= +0 (:coerce Int idx)) (let [digit (digits-get idx digits)] (if (and (n/= |0 digit) all-zeroes?) @@ -798,7 +816,7 @@ (loop [idx (dec i64.width) carry |0 output (make-digits [])] - (if (i/>= 0 (:coerce Int idx)) + (if (i/>= +0 (:coerce Int idx)) (let [raw ($_ n/+ carry (digits-get idx param) @@ -816,7 +834,7 @@ output (make-digits [])] (if (n/< length idx) (let [char (maybe.assume (get-char input idx))] - (case ("lux text index" "0123456789" char |0) + (case ("lux text index" "+0123456789" char |0) #.None #.None @@ -852,7 +870,7 @@ (-> Digits Digits Digits) (loop [idx (dec i64.width) output subject] - (if (i/>= 0 (.int idx)) + (if (i/>= +0 (.int idx)) (recur (dec idx) (digits-sub-once! idx (digits-get idx param) output)) output))) @@ -865,7 +883,7 @@ ".0" (loop [idx last-idx digits (make-digits [])] - (if (i/>= 0 (:coerce Int idx)) + (if (i/>= +0 (:coerce Int idx)) (if (i64.set? idx input) (let [digits' (digits-add (digits-power (n/- idx last-idx)) digits)] @@ -901,16 +919,16 @@ (recur (digits-sub! power digits) (inc idx) (i64.set (n/- idx (dec i64.width)) output)))) - (#e.Success (:coerce Rev output)))) + (#error.Success (:coerce Rev output)))) #.None - (#e.Error ("lux text concat" "Wrong syntax for Rev: " input))) - (#e.Error ("lux text concat" "Wrong syntax for Rev: " input)))) + (#error.Error ("lux text concat" "Wrong syntax for Rev: " input))) + (#error.Error ("lux text concat" "Wrong syntax for Rev: " input)))) )) (def: (log2 input) (-> Frac Frac) - (f// ("lux math log" 2.0) + (f// ("lux math log" +2.0) ("lux math log" input))) (def: double-bias Nat |1023) @@ -929,8 +947,8 @@ (f/= negative-infinity input) (hex "|FFF0000000000000") - (f/= 0.0 input) - (let [reciprocal (f// input 1.0)] + (f/= +0.0 input) + (let [reciprocal (f// input +1.0)] (if (f/= positive-infinity reciprocal) ## Positive zero (hex "|0000000000000000") @@ -944,9 +962,9 @@ exponent-mask (|> |1 (i64.left-shift exponent-size) dec) mantissa (|> input ## Normalize - (f// ("lux math pow" 2.0 exponent)) + (f// ("lux math pow" +2.0 exponent)) ## Make it int-equivalent - (f/* ("lux math pow" 2.0 52.0))) + (f/* ("lux math pow" +2.0 +52.0))) sign-bit (if (f/= -1.0 sign) |1 |0) exponent-bits (|> exponent frac-to-int .nat (n/+ double-bias) (i64.and exponent-mask)) mantissa-bits (|> mantissa frac-to-int .nat)] @@ -981,16 +999,16 @@ (and (n/= |0 E) (n/= |0 M)) (if (n/= |0 S) - 0.0 - (f/* -1.0 0.0)) + +0.0 + (f/* -1.0 +0.0)) ## else (let [normalized (|> M (i64.set mantissa-size) .int int-to-frac - (f// ("lux math pow" 2.0 52.0))) + (f// ("lux math pow" +2.0 +52.0))) power (|> E (n/- double-bias) .int int-to-frac - ("lux math pow" 2.0)) + ("lux math pow" +2.0)) shifted (f/* power normalized)] (if (n/= |0 S) diff --git a/stdlib/source/lux/data/number/complex.lux b/stdlib/source/lux/data/number/complex.lux index 41e074be6..fb0401582 100644 --- a/stdlib/source/lux/data/number/complex.lux +++ b/stdlib/source/lux/data/number/complex.lux @@ -27,14 +27,14 @@ "The imaginary part can be omitted if it's 0." (complex real))} (wrap (list (` {#..real (~ real) - #..imaginary (~ (maybe.default (' 0.0) + #..imaginary (~ (maybe.default (' +0.0) ?imaginary))})))) -(def: #export i Complex (complex 0.0 1.0)) +(def: #export i Complex (complex +0.0 +1.0)) -(def: #export one Complex (complex 1.0 0.0)) +(def: #export one Complex (complex +1.0 +0.0)) -(def: #export zero Complex (complex 0.0 0.0)) +(def: #export zero Complex (complex +0.0 +0.0)) (def: #export (not-a-number? complex) (or (number.not-a-number? (get@ #real complex)) @@ -158,8 +158,8 @@ (def: #export (tan subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject - r2 (f/* 2.0 real) - i2 (f/* 2.0 imaginary) + r2 (f/* +2.0 real) + i2 (f/* +2.0 imaginary) d (f/+ (math.cos r2) (math.cosh i2))] {#real (f// d (math.sin r2)) #imaginary (f// d (math.sinh i2))})) @@ -167,8 +167,8 @@ (def: #export (tanh subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject - r2 (f/* 2.0 real) - i2 (f/* 2.0 imaginary) + r2 (f/* +2.0 real) + i2 (f/* +2.0 imaginary) d (f/+ (math.cosh r2) (math.cos i2))] {#real (f// d (math.sinh r2)) #imaginary (f// d (math.sin i2))})) @@ -178,15 +178,15 @@ (let [(^slots [#real #imaginary]) subject] (complex (if (f/< (frac/abs imaginary) (frac/abs real)) - (if (f/= 0.0 imaginary) + (if (f/= +0.0 imaginary) (frac/abs real) (let [q (f// imaginary real)] - (f/* (math.pow 0.5 (f/+ 1.0 (f/* q q))) + (f/* (math.pow +0.5 (f/+ +1.0 (f/* q q))) (frac/abs imaginary)))) - (if (f/= 0.0 real) + (if (f/= +0.0 real) (frac/abs imaginary) (let [q (f// real imaginary)] - (f/* (math.pow 0.5 (f/+ 1.0 (f/* q q))) + (f/* (math.pow +0.5 (f/+ +1.0 (f/* q q))) (frac/abs real)))) )))) @@ -234,18 +234,18 @@ (def: #export (root2 (^@ input (^slots [#real #imaginary]))) (-> Complex Complex) - (let [t (|> input ..abs (get@ #real) (f/+ (frac/abs real)) (f// 2.0) (math.pow 0.5))] - (if (f/>= 0.0 real) + (let [t (|> input ..abs (get@ #real) (f/+ (frac/abs real)) (f// +2.0) (math.pow +0.5))] + (if (f/>= +0.0 real) {#real t - #imaginary (f// (f/* 2.0 t) + #imaginary (f// (f/* +2.0 t) imaginary)} - {#real (f// (f/* 2.0 t) + {#real (f// (f/* +2.0 t) (frac/abs imaginary)) - #imaginary (f/* t (copy-sign imaginary 1.0))}))) + #imaginary (f/* t (copy-sign imaginary +1.0))}))) (def: #export (root2-1z input) (-> Complex Complex) - (|> (complex 1.0) (- (* input input)) root2)) + (|> (complex +1.0) (- (* input input)) root2)) (def: #export (reciprocal (^slots [#real #imaginary])) (-> Complex Complex) @@ -253,12 +253,12 @@ (frac/abs real)) (let [q (f// imaginary real) scale (f// (|> real (f/* q) (f/+ imaginary)) - 1.0)] + +1.0)] {#real (f/* q scale) #imaginary (frac/negate scale)}) (let [q (f// real imaginary) scale (f// (|> imaginary (f/* q) (f/+ real)) - 1.0)] + +1.0)] {#real scale #imaginary (|> scale frac/negate (f/* q))}))) @@ -283,7 +283,7 @@ (+ i) (/ (- input i)) log - (* (/ (complex 2.0) i)))) + (* (/ (complex +2.0) i)))) (def: #export (argument (^slots [#real #imaginary])) (-> Complex Frac) @@ -294,9 +294,9 @@ (if (n/= |0 nth) (list) (let [r-nth (|> nth .int int-to-frac) - nth-root-of-abs (|> input abs (get@ #real) (math.pow (f// r-nth 1.0))) + nth-root-of-abs (|> input abs (get@ #real) (math.pow (f// r-nth +1.0))) nth-phi (|> input argument (f// r-nth)) - slice (|> math.pi (f/* 2.0) (f// r-nth))] + slice (|> math.pi (f/* +2.0) (f// r-nth))] (|> (list.n/range |0 (dec nth)) (list/map (function (_ nth') (let [inner (|> nth' .int int-to-frac diff --git a/stdlib/source/lux/data/text/regex.lux b/stdlib/source/lux/data/text/regex.lux index 3cb65dd14..658d51ae2 100644 --- a/stdlib/source/lux/data/text/regex.lux +++ b/stdlib/source/lux/data/text/regex.lux @@ -183,8 +183,7 @@ (def: number^ (l.Lexer Nat) (|> (l.many l.decimal) - (p.codec number.Codec<Text,Int>) - (parser/map .nat))) + (p.codec number.Codec<Text,Nat>))) (def: re-back-reference^ (l.Lexer Code) @@ -298,7 +297,7 @@ (' #let) (` [(~ g!total) (:: (~! text.Monoid<Text>) (~' compose) (~ g!total) (~ access))])) steps)]) ))) - [0 + [+0 (: (List Code) (list)) (: (List (List Code)) (list))] parts)]] diff --git a/stdlib/source/lux/host.js.lux b/stdlib/source/lux/host.js.lux index d074b1ff1..0302064b3 100644 --- a/stdlib/source/lux/host.js.lux +++ b/stdlib/source/lux/host.js.lux @@ -30,7 +30,7 @@ ## [Syntax] (syntax: #export (set! field-name field-value object) {#.doc (doc "A way to set fields from objects." - (set! "foo" 1234 some-object))} + (set! "foo" +1234 some-object))} (wrap (list (` ("js set-field" (~ object) (~ field-name) (~ field-value)))))) (syntax: #export (delete! field-name object) @@ -75,8 +75,8 @@ (syntax: #export (call! {shape (p.or ($_ p.and s.any (s.tuple (p.some s.any)) (p.maybe s.any)) ($_ p.and s.any s.text (s.tuple (p.some s.any)) (p.maybe s.any)))}) {#.doc (doc "A way to call JavaScript functions and methods." - (call! (ref "Math.ceil") [123.45]) - (call! (ref "Math") "ceil" [123.45]))} + (call! (ref "Math.ceil") [+123.45]) + (call! (ref "Math") "ceil" [+123.45]))} (case shape (#.Left [function args ?type]) (wrap (list (` (:coerce (~ (default (' ..Object) ?type)) diff --git a/stdlib/source/lux/math.lux b/stdlib/source/lux/math.lux index 124320ce9..63eedfc9a 100644 --- a/stdlib/source/lux/math.lux +++ b/stdlib/source/lux/math.lux @@ -19,9 +19,9 @@ Frac <value>)] - [e 2.7182818284590452354 "The base of the natural logarithm."] - [pi 3.14159265358979323846 "The ratio of a circle's circumference to its diameter."] - [tau 6.28318530717958647692 "The ratio of a circle's circumference to its radius."] + [e +2.7182818284590452354 "The base of the natural logarithm."] + [pi +3.14159265358979323846 "The ratio of a circle's circumference to its diameter."] + [tau +6.28318530717958647692 "The ratio of a circle's circumference to its radius."] ) (do-template [<name> <method>] @@ -48,8 +48,8 @@ (-> Frac Frac) (let [floored (floor input) diff (f/- floored input)] - (cond (f/> 0.5 diff) - (f/+ 1.0 floored) + (cond (f/> +0.5 diff) + (f/+ +1.0 floored) (f/< -0.5 diff) (f/+ -1.0 floored) @@ -63,22 +63,22 @@ (def: #export (atan2 param subject) (-> Frac Frac Frac) - (cond (f/> 0.0 param) + (cond (f/> +0.0 param) (atan (f// param subject)) - (f/< 0.0 param) - (if (f/>= 0.0 subject) + (f/< +0.0 param) + (if (f/>= +0.0 subject) (|> subject (f// param) atan (f/+ pi)) (|> subject (f// param) atan (f/- pi))) - ## (f/= 0.0 param) - (cond (f/> 0.0 subject) - (|> pi (f// 2.0)) + ## (f/= +0.0 param) + (cond (f/> +0.0 subject) + (|> pi (f// +2.0)) - (f/< 0.0 subject) + (f/< +0.0 subject) (|> pi (f// -2.0)) - ## (f/= 0.0 subject) + ## (f/= +0.0 subject) number.not-a-number))) (def: #export (log' base input) @@ -96,8 +96,8 @@ (def: #export (hypotenuse catA catB) (-> Frac Frac Frac) - (pow 0.5 (f/+ (pow 2.0 catA) - (pow 2.0 catB)))) + (pow +0.5 (f/+ (pow +2.0 catA) + (pow +2.0 catB)))) (do-template [<type> <mod> <gcd> <lcm> <zero> <*> </> <->] [(def: #export (<gcd> a b) @@ -119,7 +119,7 @@ ))] [Nat n/mod n/gcd n/lcm |0 n/* n// n/-] - [Int i/mod i/gcd i/lcm 0 i/* i// i/-] + [Int i/mod i/gcd i/lcm +0 i/* i// i/-] ) ## Hyperbolic functions @@ -127,11 +127,11 @@ (do-template [<name> <comp> <inverse>] [(def: #export (<name> x) (-> Frac Frac) - (|> (exp x) (<comp> (exp (f/* -1.0 x))) (f// 2.0))) + (|> (exp x) (<comp> (exp (f/* -1.0 x))) (f// +2.0))) (def: #export (<inverse> x) (-> Frac Frac) - (|> 2.0 (f// (|> (exp x) (<comp> (exp (f/* -1.0 x)))))))] + (|> +2.0 (f// (|> (exp x) (<comp> (exp (f/* -1.0 x)))))))] [sinh f/- csch] [cosh f/+ sech] @@ -154,7 +154,7 @@ (do-template [<name> <comp>] [(def: #export (<name> x) (-> Frac Frac) - (|> x (pow 2.0) (<comp> 1.0) (pow 0.5) (f/+ x) log))] + (|> x (pow +2.0) (<comp> +1.0) (pow +0.5) (f/+ x) log))] [asinh f/+] [acosh f/-] @@ -165,17 +165,17 @@ (-> Frac Frac) (let [x+ (|> <base> (f/+ <diff>)) x- (|> <base> (f/- <diff>))] - (|> x+ (f// x-) log (f// 2.0))))] + (|> x+ (f// x-) log (f// +2.0))))] - [atanh 1.0 x] - [acoth x 1.0] + [atanh +1.0 x] + [acoth x +1.0] ) (do-template [<name> <op>] [(def: #export (<name> x) (-> Frac Frac) - (let [x^2 (|> x (pow 2.0))] - (|> 1.0 (<op> x^2) (pow 0.5) (f/+ 1.0) (f// x) log)))] + (let [x^2 (|> x (pow +2.0))] + (|> +1.0 (<op> x^2) (pow +0.5) (f/+ +1.0) (f// x) log)))] [asech f/-] [acsch f/+] @@ -246,7 +246,7 @@ (syntax: #export (infix {expr infix^}) {#.doc (doc "Infix math syntax." - (infix [x i/* 10]) + (infix [x i/* +10]) (infix [[x i/+ y] i/* [x i/- y]]) (infix [sin [x i/+ y]]) (infix [[x n/< y] and [y n/< z]]) diff --git a/stdlib/source/lux/math/modular.lux b/stdlib/source/lux/math/modular.lux index 092b18944..ef0f36bb2 100644 --- a/stdlib/source/lux/math/modular.lux +++ b/stdlib/source/lux/math/modular.lux @@ -26,7 +26,7 @@ (def: #export (from-int value) (Ex [m] (-> Int (Error (Modulus m)))) - (if (i/= 0 value) + (if (i/= +0 value) (ex.throw zero-cannot-be-a-modulus []) (#e.Success (:abstraction value)))) @@ -52,7 +52,7 @@ (|> sample (i/- reference) (i/% (to-int modulus)) - (i/= 0))) + (i/= +0))) (syntax: #export (modulus {modulus s.int}) (case (from-int modulus) @@ -144,8 +144,8 @@ (def: (i/gcd+ a b) (-> Int Int [Int Int Int]) - (if (i/= 0 a) - [0 1 b] + (if (i/= +0 a) + [+0 +1 b] (let [[ak bk gcd] (i/gcd+ (i/% a b) a)] [(i/- (i/* ak (i// a b)) @@ -158,7 +158,7 @@ (let [[value modulus] (:representation modular) _modulus (to-int modulus) [vk mk gcd] (i/gcd+ value _modulus) - co-prime? (i/= 1 gcd)] + co-prime? (i/= +1 gcd)] (if co-prime? (#.Some (mod modulus vk)) #.None))) diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index f9ea42c2e..3230ca27e 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -126,23 +126,23 @@ (context: "Simple macros and constructs" ($_ seq (test "Can write easy loops for iterative programming." - (i/= 1000 - (loop [counter 0 - value 1] - (if (i/< 3 counter) - (recur (inc counter) (i/* 10 value)) + (i/= +1000 + (loop [counter +0 + value +1] + (if (i/< +3 counter) + (recur (inc counter) (i/* +10 value)) value)))) (test "Can create lists easily through macros." - (and (case (list 1 2 3) - (#.Cons 1 (#.Cons 2 (#.Cons 3 #.Nil))) + (and (case (list +1 +2 +3) + (#.Cons +1 (#.Cons +2 (#.Cons +3 #.Nil))) #1 _ #0) - (case (list& 1 2 3 (list 4 5 6)) - (#.Cons 1 (#.Cons 2 (#.Cons 3 (#.Cons 4 (#.Cons 5 (#.Cons 6 #.Nil)))))) + (case (list& +1 +2 +3 (list +4 +5 +6)) + (#.Cons +1 (#.Cons +2 (#.Cons +3 (#.Cons +4 (#.Cons +5 (#.Cons +6 #.Nil)))))) #1 _ @@ -217,8 +217,8 @@ (def: (success-message successes failures) (-> Nat Nat Text) (format "Test-suite finished." "\n" - (%i (.int successes)) " out of " (%i (.int (n/+ failures successes))) " tests passed." "\n" - (%i (.int failures)) " tests failed." "\n")) + (%n successes) " out of " (%n (n/+ failures successes)) " tests passed." "\n" + (%n failures) " tests failed." "\n")) (syntax: #export (run) {#.doc (doc "Runs all the tests defined on the current module, and in all imported modules." @@ -249,8 +249,8 @@ (exec (log! ((~! success-message) (~ g!total-successes) (~ g!total-failures))) ((~! promise.future) ((~! io.exit) (if (n/> |0 (~ g!total-failures)) - 1 - 0))))) + +1 + +0))))) []))))))))) (def: #export (seq left right) diff --git a/stdlib/source/lux/time/date.lux b/stdlib/source/lux/time/date.lux index d3306f826..688546698 100644 --- a/stdlib/source/lux/time/date.lux +++ b/stdlib/source/lux/time/date.lux @@ -223,7 +223,7 @@ ## Based on this: https://stackoverflow.com/a/42936293/6823464 (def: (pad value) (-> Int Text) - (if (i/< 10 value) + (if (i/< +10 value) (text/compose "0" (int/encode value)) (int/encode value))) @@ -237,11 +237,11 @@ (def: lex-year (l.Lexer Int) (do p.Monad<Parser> - [sign? (p.maybe (l.this "-")) + [sign (p.or (l.this "-") (l.this "+")) raw-year (p.codec number.Codec<Text,Int> (l.many l.decimal)) - #let [signum (case sign? - #.None 1 - (#.Some _) -1)]] + #let [signum (case sign + (#.Left _) -1 + (#.Right _) +1)]] (wrap (i/* signum raw-year)))) (def: lex-section @@ -250,9 +250,9 @@ (def: (leap-years year) (-> Int Int) - (|> (i// 4 year) - (i/- (i// 100 year)) - (i/+ (i// 400 year)))) + (|> (i// +4 year) + (i/- (i// +100 year)) + (i/+ (i// +400 year)))) (def: normal-months (Row Nat) @@ -267,13 +267,13 @@ (def: (divisible? factor input) (-> Int Int Bit) - (|> input (i/% factor) (i/= 0))) + (|> input (i/% factor) (i/= +0))) (def: (leap-year? year) (-> Int Bit) - (and (divisible? 4 year) - (or (not (divisible? 100 year)) - (divisible? 400 year)))) + (and (divisible? +4 year) + (or (not (divisible? +100 year)) + (divisible? +400 year)))) ## Based on: https://stackoverflow.com/a/3309340/6823464 (def: lex-date @@ -283,8 +283,8 @@ _ (l.this "-") utc-month lex-section _ (p.assert "Invalid month." - (and (i/>= 1 utc-month) - (i/<= 12 utc-month))) + (and (i/>= +1 utc-month) + (i/<= +12 utc-month))) #let [months (if (leap-year? utc-year) leap-year-months normal-months) @@ -294,22 +294,22 @@ _ (l.this "-") utc-day lex-section _ (p.assert "Invalid day." - (and (i/>= 1 utc-day) + (and (i/>= +1 utc-day) (i/<= (.int month-days) utc-day)))] (wrap {#year utc-year #month (case utc-month - 1 #January - 2 #February - 3 #March - 4 #April - 5 #May - 6 #June - 7 #July - 8 #August - 9 #September - 10 #October - 11 #November - 12 #December + +1 #January + +2 #February + +3 #March + +4 #April + +5 #May + +6 #June + +7 #July + +8 #August + +9 #September + +10 #October + +11 #November + +12 #December _ (undefined)) #day (.nat utc-day)}))) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 0588d7ba2..1abac1cc0 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -63,21 +63,21 @@ (do-template [<name> <op>] [(def: #export (<name> duration) (-> Duration Bit) - (<op> 0 (:representation duration)))] + (<op> +0 (:representation duration)))] [positive? i/>] [negative? i/<] [neutral? i/=]) ) -(def: #export empty Duration (from-millis 0)) -(def: #export milli Duration (from-millis 1)) -(def: #export second Duration (scale 1_000 milli)) -(def: #export minute Duration (scale 60 second)) -(def: #export hour Duration (scale 60 minute)) -(def: #export day Duration (scale 24 hour)) -(def: #export week Duration (scale 7 day)) -(def: #export normal-year Duration (scale 365 day)) +(def: #export empty Duration (from-millis +0)) +(def: #export milli Duration (from-millis +1)) +(def: #export second Duration (scale +1_000 milli)) +(def: #export minute Duration (scale +60 second)) +(def: #export hour Duration (scale +60 minute)) +(def: #export day Duration (scale +24 hour)) +(def: #export week Duration (scale +7 day)) +(def: #export normal-year Duration (scale +365 day)) (def: #export leap-year Duration (merge day normal-year)) (structure: #export _ (Monoid Duration) @@ -87,7 +87,7 @@ (def: (encode duration) (-> Duration Text) (if (:: Equivalence<Duration> = empty duration) - "0ms" + "+0ms" (let [signed? (negative? duration) [days time-left] [(query day duration) (frame day duration)] days (if signed? @@ -102,38 +102,44 @@ millis (to-millis time-left)] ($_ text/compose (if signed? "-" "") - (if (i/= 0 days) "" (text/compose (int/encode days) "D")) - (if (i/= 0 hours) "" (text/compose (int/encode hours) "h")) - (if (i/= 0 minutes) "" (text/compose (int/encode minutes) "m")) - (if (i/= 0 seconds) "" (text/compose (int/encode seconds) "s")) - (if (i/= 0 millis) "" (text/compose (int/encode millis) "ms")) + (if (i/= +0 days) "" (text/compose (int/encode days) "D")) + (if (i/= +0 hours) "" (text/compose (int/encode hours) "h")) + (if (i/= +0 minutes) "" (text/compose (int/encode minutes) "m")) + (if (i/= +0 seconds) "" (text/compose (int/encode seconds) "s")) + (if (i/= +0 millis) "" (text/compose (int/encode millis) "ms")) )))) (def: (lex-section suffix) (-> Text (l.Lexer Int)) (|> (p.codec number.Codec<Text,Int> (l.many l.decimal)) (p.before (p.and (l.this suffix) (p.not l.alpha))) - (p.default 0))) + (p.default +0))) (def: lex-duration (l.Lexer Duration) (do p.Monad<Parser> - [signed? (l.this? "-") - #let [sign (function (_ raw) (if signed? (i/* -1 raw) raw))] + [signed? (p.or (l.this? "-") (l.this? "+")) + #let [sign (function (_ raw) + (case signed? + (#.Left _) + (i/* -1 raw) + + (#.Right _) + raw))] utc-day (lex-section "D") utc-hour (lex-section "h") utc-minute (lex-section "m") _ (p.assert "Invalid minute." - (and (i/>= 0 utc-minute) - (i/<= 59 utc-minute))) + (and (i/>= +0 utc-minute) + (i/<= +59 utc-minute))) utc-second (lex-section "s") _ (p.assert "Invalid second." - (and (i/>= 0 utc-second) - (i/<= 59 utc-second))) + (and (i/>= +0 utc-second) + (i/<= +59 utc-second))) utc-millis (lex-section "ms") _ (p.assert "Invalid milli-seconds." - (and (i/>= 0 utc-millis) - (i/<= 999 utc-millis)))] + (and (i/>= +0 utc-millis) + (i/<= +999 utc-millis)))] (wrap (|> empty (merge (scale (sign utc-day) day)) (merge (scale (sign utc-hour) hour)) @@ -146,7 +152,7 @@ (l.run input lex-duration)) (structure: #export _ - {#.doc "For example: 15D21h14m51s827ms"} + {#.doc "For example: +15D21h14m51s827ms"} (Codec Text Duration) (def: encode encode) (def: decode decode)) diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index 427f4883e..2119608e9 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -77,20 +77,20 @@ (def: #export epoch {#.doc "The instant corresponding to 1970-01-01T00:00:00Z"} Instant - (from-millis 0)) + (from-millis +0)) ## Codec::encode (def: (divisible? factor input) (-> Int Int Bit) - (|> input (i/% factor) (i/= 0))) + (|> input (i/% factor) (i/= +0))) (def: (leap-year? year) (-> Int Bit) - (and (divisible? 4 year) - (or (not (divisible? 100 year)) - (divisible? 400 year)))) + (and (divisible? +4 year) + (or (not (divisible? +100 year)) + (divisible? +400 year)))) -(def: epoch-year Int 1970) +(def: epoch-year Int +1970) (def: (find-year now) (-> Instant [Int duration.Duration]) @@ -99,7 +99,7 @@ (let [year (if (leap-year? reference) duration.leap-year duration.normal-year)] - (if (i/= 0 (duration.query year time-left)) + (if (i/= +0 (duration.query year time-left)) [reference time-left] (if (duration/>= duration.empty time-left) (recur (inc reference) (duration.merge (duration.scale -1 year) time-left)) @@ -122,14 +122,14 @@ (if (duration/>= duration.empty time) (row/fold (function (_ month-days [current-month time-left]) (let [month-duration (duration.scale (.int month-days) duration.day)] - (if (i/= 0 (duration.query month-duration time-left)) + (if (i/= +0 (duration.query month-duration time-left)) [current-month time-left] [(inc current-month) (duration.merge (duration.scale -1 month-duration) time-left)]))) [|0 time] months) (row/fold (function (_ month-days [current-month time-left]) (let [month-duration (duration.scale (.int month-days) duration.day)] - (if (i/= 0 (duration.query month-duration time-left)) + (if (i/= +0 (duration.query month-duration time-left)) [current-month time-left] [(dec current-month) (duration.merge month-duration time-left)]))) [|11 time] @@ -137,7 +137,7 @@ (def: (pad value) (-> Int Text) - (if (i/< 10 value) + (if (i/< +10 value) (text/compose "0" (int/encode value)) (int/encode value))) @@ -149,48 +149,48 @@ (def: (encode-millis millis) (-> Int Text) - (cond (i/= 0 millis) "" - (i/< 10 millis) ($_ text/compose ".00" (int/encode millis)) - (i/< 100 millis) ($_ text/compose ".0" (int/encode millis)) - ## (i/< 1_000 millis) + (cond (i/= +0 millis) "" + (i/< +10 millis) ($_ text/compose ".00" (int/encode millis)) + (i/< +100 millis) ($_ text/compose ".0" (int/encode millis)) + ## (i/< +1_000 millis) ($_ text/compose "." (int/encode millis)))) (def: seconds-per-day Int (duration.query duration.second duration.day)) -(def: days-up-to-epoch Int 719468) +(def: days-up-to-epoch Int +719468) (def: (extract-date instant) (-> Instant [[Int Int Int] duration.Duration]) (let [offset (relative instant) seconds (duration.query duration.second offset) z (|> seconds (i// seconds-per-day) (i/+ days-up-to-epoch)) - era (i// 146097 - (if (i/>= 0 z) + era (i// +146097 + (if (i/>= +0 z) z - (i/- 146096 z))) - days-of-era (|> z (i/- (i/* 146097 era))) + (i/- +146096 z))) + days-of-era (|> z (i/- (i/* +146097 era))) years-of-era (|> days-of-era - (i/- (i// 1460 days-of-era)) - (i/+ (i// 36524 days-of-era)) - (i/- (i// 146096 days-of-era)) - (i// 365)) - year (|> years-of-era (i/+ (i/* 400 era))) + (i/- (i// +1460 days-of-era)) + (i/+ (i// +36524 days-of-era)) + (i/- (i// +146096 days-of-era)) + (i// +365)) + year (|> years-of-era (i/+ (i/* +400 era))) days-of-year (|> days-of-era - (i/- (|> (i/* 365 years-of-era) - (i/+ (i// 4 years-of-era)) - (i/- (i// 100 years-of-era))))) + (i/- (|> (i/* +365 years-of-era) + (i/+ (i// +4 years-of-era)) + (i/- (i// +100 years-of-era))))) day-time (duration.frame duration.day offset) days-of-year (if (duration/>= duration.empty day-time) days-of-year (dec days-of-year)) - mp (|> days-of-year (i/* 5) (i/+ 2) (i// 153)) + mp (|> days-of-year (i/* +5) (i/+ +2) (i// +153)) day (|> days-of-year - (i/- (|> mp (i/* 153) (i/+ 2) (i// 5))) - (i/+ 1)) + (i/- (|> mp (i/* +153) (i/+ +2) (i// +5))) + (i/+ +1)) month (|> mp - (i/+ (if (i/< 10 mp) - 3 + (i/+ (if (i/< +10 mp) + +3 -9))) - year (if (i/<= 2 month) + year (if (i/<= +2 month) (inc year) year)] [[year month day] @@ -218,11 +218,11 @@ (def: lex-year (l.Lexer Int) (do p.Monad<Parser> - [sign? (p.maybe (l.this "-")) + [sign (p.or (l.this "-") (l.this "+")) raw-year (p.codec number.Codec<Text,Int> (l.many l.decimal)) - #let [signum (case sign? - #.None 1 - (#.Some _) -1)]] + #let [signum (case sign + (#.Left _) -1 + (#.Right _) +1)]] (wrap (i/* signum raw-year)))) (def: lex-section @@ -234,13 +234,13 @@ (p.either (|> (l.at-most |3 l.decimal) (p.codec number.Codec<Text,Int>) (p.after (l.this "."))) - (:: p.Monad<Parser> wrap 0))) + (:: p.Monad<Parser> wrap +0))) (def: (leap-years year) (-> Int Int) - (|> (i// 4 year) - (i/- (i// 100 year)) - (i/+ (i// 400 year)))) + (|> (i// +4 year) + (i/- (i// +100 year)) + (i/+ (i// +400 year)))) ## Based on: https://stackoverflow.com/a/3309340/6823464 (def: lex-instant @@ -250,8 +250,8 @@ _ (l.this "-") utc-month lex-section _ (p.assert "Invalid month." - (and (i/>= 1 utc-month) - (i/<= 12 utc-month))) + (and (i/>= +1 utc-month) + (i/<= +12 utc-month))) #let [months (if (leap-year? utc-year) leap-year-months normal-months) @@ -261,29 +261,29 @@ _ (l.this "-") utc-day lex-section _ (p.assert "Invalid day." - (and (i/>= 1 utc-day) + (and (i/>= +1 utc-day) (i/<= (.int month-days) utc-day))) _ (l.this "T") utc-hour lex-section _ (p.assert "Invalid hour." - (and (i/>= 0 utc-hour) - (i/<= 23 utc-hour))) + (and (i/>= +0 utc-hour) + (i/<= +23 utc-hour))) _ (l.this ":") utc-minute lex-section _ (p.assert "Invalid minute." - (and (i/>= 0 utc-minute) - (i/<= 59 utc-minute))) + (and (i/>= +0 utc-minute) + (i/<= +59 utc-minute))) _ (l.this ":") utc-second lex-section _ (p.assert "Invalid second." - (and (i/>= 0 utc-second) - (i/<= 59 utc-second))) + (and (i/>= +0 utc-second) + (i/<= +59 utc-second))) utc-millis lex-millis _ (l.this "Z") #let [years-since-epoch (i/- epoch-year utc-year) previous-leap-days (i/- (leap-years epoch-year) (leap-years (dec utc-year))) - year-days-so-far (|> (i/* 365 years-since-epoch) + year-days-so-far (|> (i/* +365 years-since-epoch) (i/+ previous-leap-days)) month-days-so-far (|> months row.to-list @@ -320,18 +320,18 @@ (let [[[year month day] _] (extract-date instant)] {#date.year year #date.month (case (dec month) - 0 #date.January - 1 #date.February - 2 #date.March - 3 #date.April - 4 #date.May - 5 #date.June - 6 #date.July - 7 #date.August - 8 #date.September - 9 #date.October - 10 #date.November - 11 #date.December + +0 #date.January + +1 #date.February + +2 #date.March + +3 #date.April + +4 #date.May + +5 #date.June + +6 #date.July + +7 #date.August + +8 #date.September + +9 #date.October + +10 #date.November + +11 #date.December _ (undefined)) #date.day (.nat day)})) @@ -350,16 +350,16 @@ (dec days) days) ## 1970/01/01 was a Thursday - y1970m0d0 4] + y1970m0d0 +4] (case (|> y1970m0d0 - (i/+ days) (i/% 7) + (i/+ days) (i/% +7) ## This is done to turn negative days into positive days. - (i/+ 7) (i/% 7)) - 0 #date.Sunday - 1 #date.Monday - 2 #date.Tuesday - 3 #date.Wednesday - 4 #date.Thursday - 5 #date.Friday - 6 #date.Saturday + (i/+ +7) (i/% +7)) + +0 #date.Sunday + +1 #date.Monday + +2 #date.Tuesday + +3 #date.Wednesday + +4 #date.Thursday + +5 #date.Friday + +6 #date.Saturday _ (undefined)))) diff --git a/stdlib/source/lux/type/unit.lux b/stdlib/source/lux/type/unit.lux index df714a996..96584a989 100644 --- a/stdlib/source/lux/type/unit.lux +++ b/stdlib/source/lux/type/unit.lux @@ -85,10 +85,10 @@ (s.tuple (do p.Monad<Parser> [numerator s.int _ (p.assert (format "Numerator must be positive: " (%i numerator)) - (i/> 0 numerator)) + (i/> +0 numerator)) denominator s.int _ (p.assert (format "Denominator must be positive: " (%i denominator)) - (i/> 0 denominator))] + (i/> +0 denominator))] (wrap [(.nat numerator) (.nat denominator)])))) (syntax: #export (scale: @@ -150,13 +150,13 @@ (i// (.int denominator)) in))) -(scale: #export Kilo [1 1_000]) -(scale: #export Mega [1 1_000_000]) -(scale: #export Giga [1 1_000_000_000]) +(scale: #export Kilo [+1 +1_000]) +(scale: #export Mega [+1 +1_000_000]) +(scale: #export Giga [+1 +1_000_000_000]) -(scale: #export Milli [ 1_000 1]) -(scale: #export Micro [ 1_000_000 1]) -(scale: #export Nano [1_000_000_000 1]) +(scale: #export Milli [ +1_000 +1]) +(scale: #export Micro [ +1_000_000 +1]) +(scale: #export Nano [+1_000_000_000 +1]) (unit: #export Gram) (unit: #export Meter) |