diff options
author | Eduardo Julian | 2019-07-26 21:23:27 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-07-26 21:23:27 -0400 |
commit | a0889b2ee76c1ae7a9a5bbe2eec9f051b4f341e4 (patch) | |
tree | 08df3db7f8fffad6360a476d20db1d40b36c85cb /stdlib | |
parent | 78fd01f7e6688448bbd710336d4d7b1c35ae058a (diff) |
No more "n/"-prefixed functions.
Diffstat (limited to 'stdlib')
181 files changed, 1714 insertions, 1463 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 05a4ece62..9cc2254b2 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1049,17 +1049,7 @@ syntax} syntax)) -(def:'' #export (n/+ param subject) - (#.Cons (doc-meta "Nat(ural) addition.") #.Nil) - (#Function Nat (#Function Nat Nat)) - ("lux i64 +" subject param)) - -(def:'' #export (n/- param subject) - (#.Cons (doc-meta "Nat(ural) substraction.") #.Nil) - (#Function Nat (#Function Nat Nat)) - ("lux i64 -" param subject)) - -(def:'' #export (n/* param subject) +(def:'' (n/* param subject) (#.Cons (doc-meta "Nat(ural) multiplication.") #.Nil) (#Function Nat (#Function Nat Nat)) ("lux coerce" Nat @@ -1081,7 +1071,7 @@ pairs)) [_ (#Form (#Cons [_ (#Tag "lux" "Parameter")] (#Cons [_ (#Nat idx)] #Nil)))] - (form$ (#Cons (tag$ ["lux" "Parameter"]) (#Cons (nat$ (n/+ 2 idx)) #Nil))) + (form$ (#Cons (tag$ ["lux" "Parameter"]) (#Cons (nat$ ("lux i64 +" 2 idx)) #Nil))) [_ (#Form members)] (form$ (list@map update-parameters members)) @@ -1132,7 +1122,7 @@ #Nil (#UnivQ #Nil (#Function ($' List (#Parameter 1)) Nat)) - (list@fold (function'' [_ acc] (n/+ 1 acc)) 0 list)) + (list@fold (function'' [_ acc] ("lux i64 +" 1 acc)) 0 list)) (macro:' #export (All tokens) (#Cons [(tag$ ["lux" "doc"]) @@ -1168,7 +1158,7 @@ body' [#0 _] - (replace-syntax (#Cons [self-name (make-parameter (n/* 2 (n/- 1 (list@size names))))] + (replace-syntax (#Cons [self-name (make-parameter (n/* 2 ("lux i64 -" 1 (list@size names))))] #Nil) body')} [(text@= "" self-name) names]) @@ -1212,7 +1202,7 @@ body' [#0 _] - (replace-syntax (#Cons [self-name (make-parameter (n/* 2 (n/- 1 (list@size names))))] + (replace-syntax (#Cons [self-name (make-parameter (n/* 2 ("lux i64 -" 1 (list@size names))))] #Nil) body')} [(text@= "" self-name) names]) @@ -2117,12 +2107,6 @@ (-> (-> a Bit) ($' List a) Bit)) (list@fold (function' [_2 _1] (if _1 (p _2) #0)) #1 xs)) -(def:''' #export (n/= reference sample) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) equivalence.")]) - (-> Nat Nat Bit) - ("lux i64 =" reference sample)) - (def:''' (high-bits value) (list) (-> ($' I64 Any) I64) @@ -2138,9 +2122,8 @@ (-> ($' I64 Any) I64) ("lux i64 and" low-mask value)) -(def:''' #export (n/< reference sample) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) less-than.")]) +(def:''' (n/< reference sample) + (list) (-> Nat Nat Bit) (let' [referenceH (high-bits reference) sampleH (high-bits sample)] @@ -2152,28 +2135,13 @@ (low-bits sample)) #0)))) -(def:''' #export (n/<= reference sample) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) less-than-equal.")]) +(def:''' (n/<= reference sample) + (list) (-> Nat Nat Bit) (if (n/< reference sample) #1 ("lux i64 =" reference sample))) -(def:''' #export (n/> reference sample) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) greater-than.")]) - (-> Nat Nat Bit) - (n/< sample reference)) - -(def:''' #export (n/>= reference sample) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) greater-than-equal.")]) - (-> Nat Nat Bit) - (if (n/< sample reference) - #1 - ("lux i64 =" reference sample))) - (macro:' #export (template tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" @@ -2187,7 +2155,7 @@ (let' [apply ("lux check" (-> RepEnv ($' List Code)) (function' [env] (list@map (apply-template env) templates))) num-bindings (list@size bindings')] - (if (every? (n/= num-bindings) + (if (every? (function' [size] ("lux i64 =" num-bindings size)) (list@map list@size data')) (|> data' (join-map (compose apply (make-env bindings'))) @@ -2203,9 +2171,8 @@ (fail "Wrong syntax for template")} tokens)) -(def:''' #export (n// param subject) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) division.")]) +(def:''' (n// param subject) + (list) (-> Nat Nat Nat) (if ("lux i64 <" +0 ("lux coerce" Int param)) (if (n/< param subject) @@ -2223,37 +2190,20 @@ quotient ("lux i64 +" 1 quotient))))) -(def:''' #export (n//% param subject) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) [division remainder].")]) - (-> Nat Nat (#Product Nat Nat)) - (let' [div (n// param subject) - flat ("lux i64 *" - ("lux coerce" Int param) - ("lux coerce" Int div))] - [div ("lux i64 -" flat subject)])) - -(def:''' #export (n/% param subject) - (list [(tag$ ["lux" "doc"]) - (text$ "Nat(ural) remainder.")]) +(def:''' (n/% param subject) + (list) (-> Nat Nat Nat) (let' [flat ("lux i64 *" ("lux coerce" Int param) ("lux coerce" Int (n// param subject)))] ("lux i64 -" flat subject))) -(template [<name> <type> <test> <doc>] - [(def:''' #export (<name> left right) - (list [(tag$ ["lux" "doc"]) - (text$ <doc>)]) - (-> <type> <type> <type>) - (if (<test> right left) - left - right))] - - [n/min Nat n/< "Nat(ural) minimum."] - [n/max Nat n/> "Nat(ural) maximum."] - ) +(def:''' (n/min left right) + (list) + (-> Nat Nat Nat) + (if (n/< right left) + left + right)) (def:''' (bit@encode x) #Nil @@ -2279,7 +2229,7 @@ _ (let' [loop ("lux check" (-> Nat Text Text) (function' recur [input output] - (if (n/= 0 input) + (if ("lux i64 =" 0 input) output (recur (n// 10 input) (text@compose (|> input (n/% 10) digit-to-text) @@ -2320,7 +2270,7 @@ (def:''' (multiple? div n) #Nil (-> Nat Nat Bit) - (|> n (n/% div) (n/= 0))) + (|> n (n/% div) ("lux i64 =" 0))) (def:''' #export (not x) (list [(tag$ ["lux" "doc"]) @@ -2659,7 +2609,7 @@ #scope-type-vars scope-type-vars} (#Right {#info info #source source #current-module _ #modules modules #scopes scopes #type-context types #host host - #seed (n/+ 1 seed) #expected expected + #seed ("lux i64 +" 1 seed) #expected expected #cursor cursor #extensions extensions #scope-type-vars scope-type-vars} (local-identifier$ ($_ text@compose "__gensym__" prefix (nat@encode seed))))} @@ -3301,7 +3251,7 @@ (def: (last-index-of' part part-size since text) (-> Text Nat Nat Text (Maybe Nat)) - (case ("lux text index" (n/+ part-size since) part text) + (case ("lux text index" ("lux i64 +" part-size since) part text) #None (#Some since) @@ -3369,7 +3319,7 @@ (#Some idx) (list& ("lux text clip" 0 idx input) (text@split-all-with splitter - ("lux text clip" (n/+ 1 idx) ("lux text size" input) input))))) + ("lux text clip" ("lux i64 +" 1 idx) ("lux text size" input) input))))) (def: (nth idx xs) (All [a] @@ -3379,9 +3329,9 @@ #None (#Cons x xs') - (if (n/= 0 idx) + (if ("lux i64 =" 0 idx) (#Some x) - (nth (n/- 1 idx) xs') + (nth ("lux i64 -" 1 idx) xs') ))) (def: (beta-reduce env type) @@ -3896,8 +3846,8 @@ relatives (#Some found) - (if (n/= relatives found) - (count-relatives (n/+ 1 relatives) input) + (if ("lux i64 =" relatives found) + (count-relatives ("lux i64 +" 1 relatives) input) relatives))) (def: (list@take amount list) @@ -3907,7 +3857,7 @@ #Nil [_ (#Cons head tail)] - (#Cons head (list@take (n/- 1 amount) tail)))) + (#Cons head (list@take ("lux i64 -" 1 amount) tail)))) (def: (list@drop amount list) (All [a] (-> Nat (List a) (List a))) @@ -3916,7 +3866,7 @@ list [_ (#Cons _ tail)] - (list@drop (n/- 1 amount) tail))) + (list@drop ("lux i64 -" 1 amount) tail))) (def: (clean-module nested? relative-root module) (-> Bit Text Text (Meta Text)) @@ -3928,7 +3878,7 @@ relatives (let [parts (text@split-all-with ..module-separator relative-root) - jumps (n/- 1 relatives)] + jumps ("lux i64 -" 1 relatives)] (if (n/< (list@size parts) jumps) (let [prefix (|> parts list@reverse @@ -4173,7 +4123,7 @@ #Nil (#Cons [var bound] bindings') - (if (n/= idx var) + (if ("lux i64 =" idx var) bound (find-type-var idx bindings')))) @@ -4333,12 +4283,12 @@ (macro: #export (cond tokens) {#.doc (text$ ($_ "lux text concat" "## Branching structures with multiple test conditions." ..new-line - "(cond (n/even? num) ''even''" ..new-line - " (n/odd? num) ''odd''" + "(cond (even? num) ''even''" ..new-line + " (odd? num) ''odd''" __paragraph " ## else-branch" ..new-line " ''???'')"))} - (if (n/= 0 (n/% 2 (list@size tokens))) + (if ("lux i64 =" 0 (n/% 2 (list@size tokens))) (fail "cond requires an uneven number of arguments.") (case (list@reverse tokens) (^ (list& else branches')) @@ -4356,7 +4306,7 @@ (All [a] (-> Nat (List a) (List [Nat a]))) (case xs (#Cons x xs') - (#Cons [idx x] (enumerate' (n/+ 1 idx) xs')) + (#Cons [idx x] (enumerate' ("lux i64 +" 1 idx) xs')) #Nil #Nil)) @@ -4389,7 +4339,7 @@ (let [pattern (record$ (list@map (: (-> [Name [Nat Type]] [Code Code]) (function (_ [[r-prefix r-name] [r-idx r-type]]) [(tag$ [r-prefix r-name]) - (if (n/= idx r-idx) + (if ("lux i64 =" idx r-idx) g!output g!_)])) (zip2 tags (enumerate members))))] @@ -4423,7 +4373,7 @@ pattern (|> tags enumerate (list@map (function (_ [tag-idx tag]) - (if (n/= my-tag-index tag-idx) + (if ("lux i64 =" my-tag-index tag-idx) g!output g!_))) tuple$) @@ -4714,7 +4664,7 @@ output (record$ (list@map (: (-> [Name Nat Code] [Code Code]) (function (_ [r-slot-name r-idx r-var]) [(tag$ r-slot-name) - (if (n/= idx r-idx) + (if ("lux i64 =" idx r-idx) value r-var)])) pattern'))] @@ -4801,7 +4751,7 @@ output (record$ (list@map (: (-> [Name Nat Code] [Code Code]) (function (_ [r-slot-name r-idx r-var]) [(tag$ r-slot-name) - (if (n/= idx r-idx) + (if ("lux i64 =" idx r-idx) (` ((~ fun) (~ r-var))) r-var)])) pattern'))] @@ -4882,13 +4832,15 @@ (do maybe-monad [bindings' (monad@map maybe-monad get-short bindings) data' (monad@map maybe-monad tuple->list data)] - (if (every? (n/= (list@size bindings')) (list@map list@size data')) - (let [apply (: (-> RepEnv (List Code)) - (function (_ env) (list@map (apply-template env) templates)))] - (|> data' - (join-map (compose apply (make-env bindings'))) - wrap)) - #None))) + (let [num-bindings (list@size bindings')] + (if (every? (|>> ("lux i64 =" num-bindings)) + (list@map list@size data')) + (let [apply (: (-> RepEnv (List Code)) + (function (_ env) (list@map (apply-template env) templates)))] + (|> data' + (join-map (compose apply (make-env bindings'))) + wrap)) + #None)))) (#Some output) (return (list@compose output branches)) @@ -4964,10 +4916,10 @@ (def: (cursor-padding baseline [_ old-line old-column] [_ new-line new-column]) (-> Nat Cursor Cursor Text) - (if (n/= old-line new-line) - (text@join-with "" (repeat (.int (n/- old-column new-column)) " ")) - (let [extra-lines (text@join-with "" (repeat (.int (n/- old-line new-line)) ..new-line)) - space-padding (text@join-with "" (repeat (.int (n/- baseline new-column)) " "))] + (if ("lux i64 =" old-line new-line) + (text@join-with "" (repeat (.int ("lux i64 -" old-column new-column)) " ")) + (let [extra-lines (text@join-with "" (repeat (.int ("lux i64 -" old-line new-line)) ..new-line)) + space-padding (text@join-with "" (repeat (.int ("lux i64 -" baseline new-column)) " "))] (text@compose extra-lines space-padding)))) (def: (text@size x) @@ -4976,7 +4928,7 @@ (def: (update-cursor [file line column] code-text) (-> Cursor Text Cursor) - [file line (n/+ column (text@size code-text))]) + [file line ("lux i64 +" column (text@size code-text))]) (def: (delim-update-cursor [file line column]) (-> Cursor Cursor) @@ -5485,18 +5437,6 @@ _ (fail (..wrong-syntax-error ["lux" "name-of"])))) -(template [<type> <even> <odd> <%> <=> <0> <2>] - [(def: #export (<even> n) - (-> <type> Bit) - (<=> <0> (<%> <2> n))) - - (def: #export (<odd> n) - (-> <type> Bit) - (not (<even> n)))] - - [Nat n/even? n/odd? n/% n/= 0 2] - ) - (def: (get-scope-type-vars state) (Meta (List Nat)) (case state @@ -5514,7 +5454,7 @@ #None (#Cons x xs') - (if (n/= 0 idx) + (if ("lux i64 =" 0 idx) (#Some x) (list-at (dec idx) xs')))) @@ -5555,7 +5495,7 @@ (macro: #export (^@ tokens) {#.doc (doc "Allows you to simultaneously bind and de-structure a value." (def: (hash (^@ set [Hash<a> _])) - (list@fold (function (_ elem acc) (n/+ (:: Hash<a> hash elem) acc)) + (list@fold (function (_ elem acc) (+ (:: Hash<a> hash elem) acc)) 0 (to-list set))))} (case tokens @@ -5571,7 +5511,7 @@ (macro: #export (^|> tokens) {#.doc (doc "Pipes the value being pattern-matched against prior to binding it to a variable." (case input - (^|> value [inc (n/% 10) (n/max 1)]) + (^|> value [inc (% 10) (max 1)]) (foo value)))} (case tokens (^ (list& [_meta (#Form (list [_ (#Identifier ["" name])] [_ (#Tuple steps)]))] body branches)) @@ -5739,7 +5679,7 @@ (macro: #export (char tokens compiler) (case tokens (^multi (^ (list [_ (#Text input)])) - (n/= 1 ("lux text size" input))) + (|> input "lux text size" ("lux i64 =" 1))) (|> input ("lux text char" 0) nat$ list [compiler] #Right) diff --git a/stdlib/source/lux/abstract/comonad.lux b/stdlib/source/lux/abstract/comonad.lux index cc5aaad91..d7186bed4 100644 --- a/stdlib/source/lux/abstract/comonad.lux +++ b/stdlib/source/lux/abstract/comonad.lux @@ -1,6 +1,8 @@ (.module: [lux #* [data + [number + ["n" nat]] [collection ["." list ("#;." fold)]]]] [// @@ -32,7 +34,7 @@ (square (head inputs)))))} (case tokens (#.Cons comonad (#.Cons [_ (#.Tuple bindings)] (#.Cons body #.Nil))) - (if (|> bindings list.size (n/% 2) (n/= 0)) + (if (|> bindings list.size (n.% 2) (n.= 0)) (let [g!_ (: Code [_cursor (#.Identifier ["" " _ "])]) g!map (: Code [_cursor (#.Identifier ["" " map "])]) g!split (: Code [_cursor (#.Identifier ["" " split "])]) diff --git a/stdlib/source/lux/abstract/hash.lux b/stdlib/source/lux/abstract/hash.lux index 752227fb7..e2716335c 100644 --- a/stdlib/source/lux/abstract/hash.lux +++ b/stdlib/source/lux/abstract/hash.lux @@ -1,5 +1,5 @@ (.module: - lux + [lux #*] [// ["." equivalence (#+ Equivalence)]]) @@ -18,5 +18,7 @@ (equivalence.product (:: leftH &equivalence) (:: rightH &equivalence))) (def: (hash [leftV rightV]) - (n/* (:: leftH hash leftV) - (:: rightH hash rightV))))) + (:coerce Nat + ("lux i64 *" + (:coerce Int (:: leftH hash leftV)) + (:coerce Int (:: rightH hash rightV))))))) diff --git a/stdlib/source/lux/abstract/monad.lux b/stdlib/source/lux/abstract/monad.lux index a0ee9b5aa..2d086fcf3 100644 --- a/stdlib/source/lux/abstract/monad.lux +++ b/stdlib/source/lux/abstract/monad.lux @@ -60,7 +60,7 @@ (wrap (f3 z))))} (case tokens (#.Cons monad (#.Cons [_ (#.Tuple bindings)] (#.Cons body #.Nil))) - (if (|> bindings list@size (n/% 2) (n/= 0)) + (if (|> bindings list@size .int ("lux i64 %" +2) ("lux i64 =" +0)) (let [g!_ (: Code [_cursor (#.Identifier ["" " _ "])]) g!map (: Code [_cursor (#.Identifier ["" " map "])]) g!join (: Code [_cursor (#.Identifier ["" " join "])]) diff --git a/stdlib/source/lux/control/concatenative.lux b/stdlib/source/lux/control/concatenative.lux index ea81bdf76..a0152830d 100644 --- a/stdlib/source/lux/control/concatenative.lux +++ b/stdlib/source/lux/control/concatenative.lux @@ -1,6 +1,5 @@ (.module: - [lux (#- if loop when - n/+ n/- n/* n// n/% n/= n/< n/<= n/> n/>=) + [lux (#- if loop when) [abstract ["." monad]] [data @@ -10,6 +9,7 @@ [collection ["." list ("#;." fold functor)]] [number + ["n" nat] ["i" int] ["r" rev] ["f" frac]]] @@ -130,7 +130,7 @@ (~ type) (|>> (~+ (list;map prepare commands)))))))) -(syntax: #export (apply {arity (|> s.nat (p.filter (.n/> 0)))}) +(syntax: #export (apply {arity (|> s.nat (p.filter (n.> 0)))}) (with-gensyms [g! g!func g!stack g!output] (monad.do @ [g!inputs (|> (macro.gensym "input") (list.repeat arity) (monad.seq @))] @@ -207,16 +207,16 @@ (function (_ [[stack subject] param]) [stack (<func> param subject)]))] - [Nat Nat n/+ .n/+] - [Nat Nat n/- .n/-] - [Nat Nat n/* .n/*] - [Nat Nat n// .n//] - [Nat Nat n/% .n/%] - [Nat Bit n/= .n/=] - [Nat Bit n/< .n/<] - [Nat Bit n/<= .n/<=] - [Nat Bit n/> .n/>] - [Nat Bit n/>= .n/>=] + [Nat Nat n/+ n.+] + [Nat Nat n/- n.-] + [Nat Nat n/* n.*] + [Nat Nat n// n./] + [Nat Nat n/% n.%] + [Nat Bit n/= n.=] + [Nat Bit n/< n.<] + [Nat Bit n/<= n.<=] + [Nat Bit n/> n.>] + [Nat Bit n/>= n.>=] [Int Int i/+ i.+] [Int Int i/- i.-] diff --git a/stdlib/source/lux/control/concurrency/actor.lux b/stdlib/source/lux/control/concurrency/actor.lux index 6487801df..87bfabd4d 100644 --- a/stdlib/source/lux/control/concurrency/actor.lux +++ b/stdlib/source/lux/control/concurrency/actor.lux @@ -11,6 +11,8 @@ ["s" code (#+ Parser)]]] [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -327,7 +329,7 @@ (message: #export Counter (count! [increment Nat] state self Nat) - (let [state' (n/+ increment state)] + (let [state' (n.+ increment state)] (promise.resolved (#try.Success [state' state'])))) (message: #export (Stack a) diff --git a/stdlib/source/lux/control/concurrency/process.lux b/stdlib/source/lux/control/concurrency/process.lux index 7cb569ee9..d31edfb59 100644 --- a/stdlib/source/lux/control/concurrency/process.lux +++ b/stdlib/source/lux/control/concurrency/process.lux @@ -8,6 +8,8 @@ ["ex" exception (#+ exception:)] ["." io (#+ IO io)]] [data + [number + ["n" nat]] [collection ["." list]]]] [// @@ -142,8 +144,8 @@ [#let [now (.nat ("lux io current-time")) [ready pending] (list.partition (function (_ process) (|> (get@ #creation process) - (n/+ (get@ #delay process)) - (n/<= now))) + (n.+ (get@ #delay process)) + (n.<= now))) processes)] swapped? (atom.compare-and-swap processes pending runner)] (if swapped? diff --git a/stdlib/source/lux/control/concurrency/semaphore.lux b/stdlib/source/lux/control/concurrency/semaphore.lux index fab5d4498..ade45984e 100644 --- a/stdlib/source/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/lux/control/concurrency/semaphore.lux @@ -2,6 +2,9 @@ [lux #* [abstract [monad (#+ do)]] + [data + [number + ["n" nat]]] [control ["." io (#+ IO)]] [type @@ -100,7 +103,7 @@ (wrap output))) ) -(def: #export limit (refinement.refinement (n/> 0))) +(def: #export limit (refinement.refinement (n.> 0))) (`` (type: #export Limit (~~ (refinement.type limit)))) (abstract: #export Barrier @@ -121,7 +124,7 @@ (def: (un-block times turnstile) (-> Nat Semaphore (Promise Any)) (loop [step 0] - (if (n/< times step) + (if (n.< times step) (do promise.monad [_ (signal turnstile)] (recur (inc step))) @@ -134,7 +137,7 @@ [#let [limit (refinement.un-refine (get@ #limit barrier)) goal <goal> count (io.run (atom.update <update> (get@ #count barrier)))] - _ (if (n/= goal count) + _ (if (n.= goal count) (un-block limit (get@ <turnstile> barrier)) (wrap []))] (wait (get@ <turnstile> barrier))))] diff --git a/stdlib/source/lux/control/exception.lux b/stdlib/source/lux/control/exception.lux index aac879cb7..21bdc1040 100644 --- a/stdlib/source/lux/control/exception.lux +++ b/stdlib/source/lux/control/exception.lux @@ -10,7 +10,7 @@ ["." product] ["." text ("#@." monoid)] [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] [collection ["." list ("#@." functor fold)]]] ["." macro @@ -119,16 +119,16 @@ (-> (List [Text Text]) Text) (let [largest-header-size (|> entries (list@map (|>> product.left text.size)) - (list@fold n/max 0)) + (list@fold n.max 0)) on-new-line (|> " " - (list.repeat (n/+ (text.size header-separator) + (list.repeat (n.+ (text.size header-separator) largest-header-size)) (text.join-with "") (text@compose text.new-line))] (|> entries (list@map (function (_ [header message]) (let [padding (|> " " - (list.repeat (n/- (text.size header) + (list.repeat (n.- (text.size header) largest-header-size)) (text.join-with ""))] (|> message @@ -174,5 +174,5 @@ (-> (List a) Text))) (|>> list.enumerate (list@map (function (_ [index entry]) - ($_ text@compose (nat@encode index) ": " (%entry entry)))) + ($_ text@compose (n@encode index) ": " (%entry entry)))) (text.join-with text.new-line))) diff --git a/stdlib/source/lux/control/parser.lux b/stdlib/source/lux/control/parser.lux index 66799e067..6187a4d4f 100644 --- a/stdlib/source/lux/control/parser.lux +++ b/stdlib/source/lux/control/parser.lux @@ -8,9 +8,11 @@ [control ["." try (#+ Try)]] [data + ["." product] + [number + ["n" nat]] [collection - ["." list ("#@." functor monoid)]] - ["." product]]]) + ["." list ("#@." functor monoid)]]]]) (type: #export (Parser s a) {#.doc "A generic parser."} @@ -155,7 +157,7 @@ (def: #export (exactly n p) {#.doc "Parse exactly N times."} (All [s a] (-> Nat (Parser s a) (Parser s (List a)))) - (if (n/> 0 n) + (if (n.> 0 n) (do ..monad [x p xs (exactly (dec n) p)] @@ -173,7 +175,7 @@ (def: #export (at-most n p) {#.doc "Parse at most N times."} (All [s a] (-> Nat (Parser s a) (Parser s (List a)))) - (if (n/> 0 n) + (if (n.> 0 n) (function (_ input) (case (p input) (#try.Failure msg) @@ -192,7 +194,7 @@ (All [s a] (-> Nat Nat (Parser s a) (Parser s (List a)))) (do ..monad [min-xs (exactly from p) - max-xs (at-most (n/- from to) p)] + max-xs (at-most (n.- from to) p)] (wrap (:: list.monad join (list min-xs max-xs))))) (def: #export (sep-by sep p) diff --git a/stdlib/source/lux/control/parser/binary.lux b/stdlib/source/lux/control/parser/binary.lux index 2912e0a52..fed4370bf 100644 --- a/stdlib/source/lux/control/parser/binary.lux +++ b/stdlib/source/lux/control/parser/binary.lux @@ -9,6 +9,7 @@ [data ["." binary (#+ Binary)] [number + ["n" nat] ["." frac]] [text ["." encoding] @@ -35,7 +36,7 @@ (#try.Success [[end _] output]) (let [length (binary.size input)] - (if (n/= end length) + (if (n.= end length) (#try.Success output) (exception.throw ..binary-was-not-fully-read [length end]))))) @@ -52,7 +53,7 @@ (function (_ [offset binary]) (case (<read> offset binary) (#try.Success data) - (#try.Success [(n/+ <size> offset) binary] data) + (#try.Success [(n.+ <size> offset) binary] data) (#try.Failure error) (#try.Failure error))))] @@ -114,7 +115,7 @@ [size (//@map .nat <bits>)] (function (_ [offset binary]) (do try.monad - [#let [end (n/+ size offset)] + [#let [end (n.+ size offset)] output (binary.slice offset (.dec end) binary)] (wrap [[end binary] output])))))] @@ -150,7 +151,7 @@ valueP} {(Row v) row.empty})] - (if (n/< count index) + (if (n.< count index) (do //.monad [value valueP] (recur (.inc index) diff --git a/stdlib/source/lux/control/parser/synthesis.lux b/stdlib/source/lux/control/parser/synthesis.lux index 784f08698..1b0a38acd 100644 --- a/stdlib/source/lux/control/parser/synthesis.lux +++ b/stdlib/source/lux/control/parser/synthesis.lux @@ -10,8 +10,8 @@ ["." name] [number ["." i64] - ["." frac] - ["." nat]] + ["n" nat] + ["." frac]] ["." text ["%" format (#+ format)]]] [tool @@ -89,8 +89,8 @@ [i64 i64! /.i64 (I64 Any) i64.equivalence] [f64 f64! /.f64 Frac frac.equivalence] [text text! /.text Text text.equivalence] - [local local! /.variable/local Nat nat.equivalence] - [foreign foreign! /.variable/foreign Nat nat.equivalence] + [local local! /.variable/local Nat n.equivalence] + [foreign foreign! /.variable/foreign Nat n.equivalence] [constant constant! /.constant Name name.equivalence] ) @@ -111,7 +111,7 @@ (.function (_ input) (case input (^ (list& (/.function/abstraction [environment actual body]) tail)) - (if (n/= expected actual) + (if (n.= expected actual) (do try.monad [output (..run (list body) parser)] (#try.Success [tail [environment output]])) diff --git a/stdlib/source/lux/control/parser/text.lux b/stdlib/source/lux/control/parser/text.lux index 0e57f02f6..bec295f39 100644 --- a/stdlib/source/lux/control/parser/text.lux +++ b/stdlib/source/lux/control/parser/text.lux @@ -10,7 +10,7 @@ ["." maybe] ["/" text ("#@." monoid)] [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] [collection ["." list ("#@." fold)]]] [macro @@ -34,13 +34,13 @@ (exception: #export (unconsumed-input {offset Offset} {tape Text}) (exception.report - ["Offset" (nat@encode offset)] - ["Input size" (nat@encode (/.size tape))] + ["Offset" (n@encode offset)] + ["Input size" (n@encode (/.size tape))] ["Remaining input" (remaining offset tape)])) (exception: #export (expected-to-fail {offset Offset} {tape Text}) (exception.report - ["Offset" (nat@encode offset)] + ["Offset" (n@encode offset)] ["Input" (remaining offset tape)])) (exception: #export cannot-parse) @@ -53,7 +53,7 @@ (#try.Failure msg) (#try.Success [[end-offset _] output]) - (if (n/= end-offset (/.size input)) + (if (n.= end-offset (/.size input)) (#try.Success output) (exception.throw ..unconsumed-input [end-offset input])))) @@ -115,7 +115,7 @@ (function (_ [offset tape]) (case (/.index-of' reference offset tape) (#.Some where) - (if (n/= offset where) + (if (n.= offset where) (#try.Success [[("lux i64 +" (/.size reference) offset) tape] []]) (#try.Failure ($_ /@compose "Could not match: " (/.encode reference) " @ " (maybe.assume (/.clip' offset tape))))) @@ -128,7 +128,7 @@ (-> Text (Parser Bit)) (function (_ (^@ input [offset tape])) (case (/.index-of' reference offset tape) - (^multi (#.Some where) (n/= offset where)) + (^multi (#.Some where) (n.= offset where)) (#try.Success [[("lux i64 +" (/.size reference) offset) tape] #1]) @@ -139,7 +139,7 @@ {#.doc "Ensure the parser's input is empty."} (Parser Any) (function (_ (^@ input [offset tape])) - (if (n/= offset (/.size tape)) + (if (n.= offset (/.size tape)) (#try.Success [input []]) (exception.throw ..unconsumed-input input)))) @@ -147,7 +147,7 @@ {#.doc "Ask if the parser's input is empty."} (Parser Bit) (function (_ (^@ input [offset tape])) - (#try.Success [input (n/= offset (/.size tape))]))) + (#try.Success [input (n.= offset (/.size tape))]))) (def: #export peek {#.doc "Lex the next character (without consuming it from the input)."} @@ -173,8 +173,8 @@ [char any #let [char' (maybe.assume (/.nth 0 char))] _ (//.assert ($_ /@compose "Character is not within range: " (/.from-code bottom) "-" (/.from-code top)) - (.and (n/>= bottom char') - (n/<= top char')))] + (.and (n.>= bottom char') + (n.<= top char')))] (wrap char))) (template [<name> <bottom> <top> <desc>] diff --git a/stdlib/source/lux/control/parser/type.lux b/stdlib/source/lux/control/parser/type.lux index 6e42cad87..dc3f101f3 100644 --- a/stdlib/source/lux/control/parser/type.lux +++ b/stdlib/source/lux/control/parser/type.lux @@ -9,7 +9,7 @@ [data ["." name ("#@." codec)] [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] ["." text ("#@." monoid) ["%" format (#+ format)]] [collection @@ -60,7 +60,7 @@ (type: #export (Parser a) (//.Parser [Env (List Type)] a)) -(def: #export fresh Env (dictionary.new nat.hash)) +(def: #export fresh Env (dictionary.new n.hash)) (def: (run' env types poly) (All [a] (-> Env (List Type) (Parser a) (Try a))) @@ -127,7 +127,7 @@ (def: (label idx) (-> Nat Code) - (code.local-identifier ($_ text@compose "label" text.tab (nat@encode idx)))) + (code.local-identifier ($_ text@compose "label" text.tab (n@encode idx)))) (def: #export (with-extension type poly) (All [a] (-> Type (Parser a) (Parser [Code a]))) @@ -149,7 +149,7 @@ (do //.monad [headT any] (let [members (<flattener> (type.un-name headT))] - (if (n/> 1 (list.size members)) + (if (n.> 1 (list.size members)) (local members poly) (//.fail (exception.construct <exception> headT))))))] @@ -162,7 +162,7 @@ (do //.monad [headT any #let [[num-arg bodyT] (type.flatten-univ-q (type.un-name headT))]] - (if (n/= 0 num-arg) + (if (n.= 0 num-arg) (//.fail (exception.construct not-polymorphic headT)) (wrap [num-arg bodyT])))) @@ -177,19 +177,19 @@ [all-varsL env'] (loop [current-arg 0 env' env all-varsL (: (List Code) (list))] - (if (n/< num-args current-arg) - (if (n/= 0 current-arg) + (if (n.< num-args current-arg) + (if (n.= 0 current-arg) (let [varL (label (inc funcI))] (recur (inc current-arg) (|> env' (dictionary.put funcI [headT funcL]) (dictionary.put (inc funcI) [(#.Parameter (inc funcI)) varL])) (#.Cons varL all-varsL))) - (let [partialI (|> current-arg (n/* 2) (n/+ funcI)) + (let [partialI (|> current-arg (n.* 2) (n.+ funcI)) partial-varI (inc partialI) partial-varL (label partial-varI) partialC (` ((~ funcL) (~+ (|> (list.indices num-args) - (list@map (|>> (n/* 2) inc (n/+ funcI) label)) + (list@map (|>> (n.* 2) inc (n.+ funcI) label)) list.reverse))))] (recur (inc current-arg) (|> env' @@ -208,7 +208,7 @@ (do //.monad [headT any #let [[inputsT outputT] (type.flatten-function (type.un-name headT))]] - (if (n/> 0 (list.size inputsT)) + (if (n.> 0 (list.size inputsT)) (//.and (local inputsT in-poly) (local (list outputT) out-poly)) (//.fail (exception.construct not-function headT))))) @@ -218,7 +218,7 @@ (do //.monad [headT any #let [[funcT paramsT] (type.flatten-application (type.un-name headT))]] - (if (n/= 0 (list.size paramsT)) + (if (n.= 0 (list.size paramsT)) (//.fail (exception.construct not-application headT)) (local (#.Cons funcT paramsT) poly)))) @@ -238,10 +238,10 @@ (def: #export (adjusted-idx env idx) (-> Env Nat Nat) - (let [env-level (n// 2 (dictionary.size env)) - parameter-level (n// 2 idx) - parameter-idx (n/% 2 idx)] - (|> env-level dec (n/- parameter-level) (n/* 2) (n/+ parameter-idx)))) + (let [env-level (n./ 2 (dictionary.size env)) + parameter-level (n./ 2 idx) + parameter-idx (n.% 2 idx)] + (|> env-level dec (n.- parameter-level) (n.* 2) (n.+ parameter-idx)))) (def: #export parameter (Parser Code) @@ -267,7 +267,7 @@ headT any] (case headT (#.Parameter idx) - (if (n/= id (adjusted-idx env idx)) + (if (n.= id (adjusted-idx env idx)) (wrap []) (//.fail (exception.construct wrong-parameter [(#.Parameter id) headT]))) @@ -319,7 +319,7 @@ headT any] (case (type.un-name headT) (^multi (#.Apply (#.Named ["lux" "Nothing"] _) (#.Parameter funcT-idx)) - (n/= 0 (adjusted-idx env funcT-idx)) + (n.= 0 (adjusted-idx env funcT-idx)) [(dictionary.get 0 env) (#.Some [self-type self-call])]) (wrap self-call) diff --git a/stdlib/source/lux/control/pipe.lux b/stdlib/source/lux/control/pipe.lux index 0db424c1f..ed6b54311 100644 --- a/stdlib/source/lux/control/pipe.lux +++ b/stdlib/source/lux/control/pipe.lux @@ -8,6 +8,7 @@ ["s" code (#+ Parser)]]] [data [number + ["n" nat] ["i" int]] [collection ["." list ("#;." fold monad)]]] @@ -23,18 +24,18 @@ {body body^} prev) {#.doc (doc "Ignores the piped argument, and begins a new pipe." - (n/= 1 + (n.= 1 (|> 20 - (n/* 3) - (n/+ 4) + (n.* 3) + (n.+ 4) (new> 0 [inc]))))} (wrap (list (` (|> (~ start) (~+ body)))))) (syntax: #export (let> binding body prev) {#.doc (doc "Gives a name to the piped-argument, within the given expression." - (n/= 10 + (n.= 10 (|> 5 - (let> x (n/+ x x)))))} + (let> x (n.+ x x)))))} (wrap (list (` (let [(~ binding) (~ prev)] (~ body)))))) diff --git a/stdlib/source/lux/data/binary.lux b/stdlib/source/lux/data/binary.lux index 019cf6482..c6feeec45 100644 --- a/stdlib/source/lux/data/binary.lux +++ b/stdlib/source/lux/data/binary.lux @@ -11,7 +11,8 @@ [data ["." maybe] [number - ["." i64]] + ["." i64] + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -130,45 +131,45 @@ (def: #export (read/8 idx binary) (-> Nat Binary (Try I64)) - (if (n/< (..!size binary) idx) + (if (n.< (..!size binary) idx) (#try.Success (!read idx binary)) (exception.throw index-out-of-bounds [(..!size binary) idx]))) (def: #export (read/16 idx binary) (-> Nat Binary (Try I64)) - (if (n/< (..!size binary) (n/+ 1 idx)) + (if (n.< (..!size binary) (n.+ 1 idx)) (#try.Success ($_ i64.or (i64.left-shift 8 (!read idx binary)) - (!read (n/+ 1 idx) binary))) + (!read (n.+ 1 idx) binary))) (exception.throw index-out-of-bounds [(..!size binary) idx]))) (def: #export (read/32 idx binary) (-> Nat Binary (Try I64)) - (if (n/< (..!size binary) (n/+ 3 idx)) + (if (n.< (..!size binary) (n.+ 3 idx)) (#try.Success ($_ i64.or (i64.left-shift 24 (!read idx binary)) - (i64.left-shift 16 (!read (n/+ 1 idx) binary)) - (i64.left-shift 8 (!read (n/+ 2 idx) binary)) - (!read (n/+ 3 idx) binary))) + (i64.left-shift 16 (!read (n.+ 1 idx) binary)) + (i64.left-shift 8 (!read (n.+ 2 idx) binary)) + (!read (n.+ 3 idx) binary))) (exception.throw index-out-of-bounds [(..!size binary) idx]))) (def: #export (read/64 idx binary) (-> Nat Binary (Try I64)) - (if (n/< (..!size binary) (n/+ 7 idx)) + (if (n.< (..!size binary) (n.+ 7 idx)) (#try.Success ($_ i64.or (i64.left-shift 56 (!read idx binary)) - (i64.left-shift 48 (!read (n/+ 1 idx) binary)) - (i64.left-shift 40 (!read (n/+ 2 idx) binary)) - (i64.left-shift 32 (!read (n/+ 3 idx) binary)) - (i64.left-shift 24 (!read (n/+ 4 idx) binary)) - (i64.left-shift 16 (!read (n/+ 5 idx) binary)) - (i64.left-shift 8 (!read (n/+ 6 idx) binary)) - (!read (n/+ 7 idx) binary))) + (i64.left-shift 48 (!read (n.+ 1 idx) binary)) + (i64.left-shift 40 (!read (n.+ 2 idx) binary)) + (i64.left-shift 32 (!read (n.+ 3 idx) binary)) + (i64.left-shift 24 (!read (n.+ 4 idx) binary)) + (i64.left-shift 16 (!read (n.+ 5 idx) binary)) + (i64.left-shift 8 (!read (n.+ 6 idx) binary)) + (!read (n.+ 7 idx) binary))) (exception.throw index-out-of-bounds [(..!size binary) idx]))) (def: #export (write/8 idx value binary) (-> Nat (I64 Any) Binary (Try Binary)) - (if (n/< (..!size binary) idx) + (if (n.< (..!size binary) idx) (exec (|> binary (!write idx value)) (#try.Success binary)) @@ -176,36 +177,36 @@ (def: #export (write/16 idx value binary) (-> Nat (I64 Any) Binary (Try Binary)) - (if (n/< (..!size binary) (n/+ 1 idx)) + (if (n.< (..!size binary) (n.+ 1 idx)) (exec (|> binary (!write idx (i64.logic-right-shift 8 value)) - (!write (n/+ 1 idx) value)) + (!write (n.+ 1 idx) value)) (#try.Success binary)) (exception.throw index-out-of-bounds [(..!size binary) idx]))) (def: #export (write/32 idx value binary) (-> Nat (I64 Any) Binary (Try Binary)) - (if (n/< (..!size binary) (n/+ 3 idx)) + (if (n.< (..!size binary) (n.+ 3 idx)) (exec (|> binary (!write idx (i64.logic-right-shift 24 value)) - (!write (n/+ 1 idx) (i64.logic-right-shift 16 value)) - (!write (n/+ 2 idx) (i64.logic-right-shift 8 value)) - (!write (n/+ 3 idx) value)) + (!write (n.+ 1 idx) (i64.logic-right-shift 16 value)) + (!write (n.+ 2 idx) (i64.logic-right-shift 8 value)) + (!write (n.+ 3 idx) value)) (#try.Success binary)) (exception.throw index-out-of-bounds [(..!size binary) idx]))) (def: #export (write/64 idx value binary) (-> Nat (I64 Any) Binary (Try Binary)) - (if (n/< (..!size binary) (n/+ 7 idx)) + (if (n.< (..!size binary) (n.+ 7 idx)) (exec (|> binary (!write idx (i64.logic-right-shift 56 value)) - (!write (n/+ 1 idx) (i64.logic-right-shift 48 value)) - (!write (n/+ 2 idx) (i64.logic-right-shift 40 value)) - (!write (n/+ 3 idx) (i64.logic-right-shift 32 value)) - (!write (n/+ 4 idx) (i64.logic-right-shift 24 value)) - (!write (n/+ 5 idx) (i64.logic-right-shift 16 value)) - (!write (n/+ 6 idx) (i64.logic-right-shift 8 value)) - (!write (n/+ 7 idx) value)) + (!write (n.+ 1 idx) (i64.logic-right-shift 48 value)) + (!write (n.+ 2 idx) (i64.logic-right-shift 40 value)) + (!write (n.+ 3 idx) (i64.logic-right-shift 32 value)) + (!write (n.+ 4 idx) (i64.logic-right-shift 24 value)) + (!write (n.+ 5 idx) (i64.logic-right-shift 16 value)) + (!write (n.+ 6 idx) (i64.logic-right-shift 8 value)) + (!write (n.+ 7 idx) value)) (#try.Success binary)) (exception.throw index-out-of-bounds [(..!size binary) idx]))) @@ -217,11 +218,11 @@ (~~ (static @.jvm)) (java/util/Arrays::equals reference sample)} (let [limit (!size reference)] - (and (n/= limit + (and (n.= limit (!size sample)) (loop [idx 0] - (if (n/< limit idx) - (and (n/= (!read idx reference) + (if (n.< limit idx) + (and (n.= (!read idx reference) (!read idx sample)) (recur (inc idx))) true)))))))) @@ -251,13 +252,13 @@ <for-jvm>} ## Default - (let [source-input (n/- source-offset (!size source)) - target-output (n/- target-offset (!size target))] - (if (n/<= target-output source-input) + (let [source-input (n.- source-offset (!size source)) + target-output (n.- target-offset (!size target))] + (if (n.<= target-output source-input) (loop [idx 0] - (if (n/< source-input idx) - (exec (!write (n/+ target-offset idx) - (!read (n/+ source-offset idx) source) + (if (n.< source-input idx) + (exec (!write (n.+ target-offset idx) + (!read (n.+ source-offset idx) source) target) (recur (inc idx))) (#try.Success target))) @@ -266,9 +267,9 @@ (def: #export (slice from to binary) (-> Nat Nat Binary (Try Binary)) (let [size (..!size binary)] - (if (n/<= to from) - (if (and (n/< size from) - (n/< size to)) + (if (n.<= to from) + (if (and (n.< size from) + (n.< size to)) (with-expansions [<for-jvm> (as-is (#try.Success (java/util/Arrays::copyOfRange binary (.int from) (.int (inc to)))))] (`` (for {(~~ (static @.old)) <for-jvm> @@ -277,7 +278,7 @@ <for-jvm>} ## Default - (let [how-many (n/- from to)] + (let [how-many (n.- from to)] (..copy how-many from binary 0 (..create how-many)))))) (exception.throw slice-out-of-bounds [size from to])) (exception.throw inverted-slice [size from to])))) diff --git a/stdlib/source/lux/data/collection/array.lux b/stdlib/source/lux/data/collection/array.lux index 810256534..b71e2fb2d 100644 --- a/stdlib/source/lux/data/collection/array.lux +++ b/stdlib/source/lux/data/collection/array.lux @@ -10,6 +10,8 @@ [data ["." product] ["." maybe] + [number + ["n" nat]] [collection ["." list ("#@." fold)]]]]) @@ -65,7 +67,7 @@ (def: #export (read index array) (All [a] (-> Nat (Array a) (Maybe a))) - (if (n/< (size array) index) + (if (n.< (size array) index) (`` (for {(~~ (static @.old)) (let [value ("jvm aaload" array index)] (if ("jvm object null?" value) @@ -105,7 +107,7 @@ (def: #export (delete index array) (All [a] (-> Nat (Array a) (Array a))) - (if (n/< (size array) index) + (if (n.< (size array) index) (`` (for {(~~ (static @.old)) (write index (:assume ("jvm object null")) array) @@ -148,15 +150,15 @@ (All [a] (-> Nat Nat (Array a) Nat (Array a) (Array a))) - (if (n/= 0 length) + (if (n.= 0 length) dest-array (list@fold (function (_ offset target) - (case (read (n/+ offset src-start) src-array) + (case (read (n.+ offset src-start) src-array) #.None target (#.Some value) - (write (n/+ offset dest-start) value target))) + (write (n.+ offset dest-start) value target))) dest-array (list.indices length)))) @@ -176,7 +178,7 @@ (def: #export (vacant array) {#.doc "Finds out how many cells in an array are vacant."} (All [a] (-> (Array a) Nat)) - (n/- (occupied array) (size array))) + (n.- (occupied array) (size array))) (def: #export (filter! p xs) (All [a] @@ -198,7 +200,7 @@ (-> (-> a Bit) (Array a) (Maybe a))) (let [arr-size (size xs)] (loop [idx 0] - (if (n/< arr-size idx) + (if (n.< arr-size idx) (case (read idx xs) #.None (recur (inc idx)) @@ -215,7 +217,7 @@ (-> (-> Nat a Bit) (Array a) (Maybe [Nat a]))) (let [arr-size (size xs)] (loop [idx 0] - (if (n/< arr-size idx) + (if (n.< arr-size idx) (case (read idx xs) #.None (recur (inc idx)) @@ -252,7 +254,7 @@ (All [a] (-> (Array a) (List a))) (loop [idx (dec (size array)) output #.Nil] - (if (n/= underflow idx) + (if (n.= underflow idx) output (recur (dec idx) (case (read idx array) @@ -266,7 +268,7 @@ (All [a] (-> a (Array a) (List a))) (loop [idx (dec (size array)) output #.Nil] - (if (n/= underflow idx) + (if (n.= underflow idx) output (recur (dec idx) (#.Cons (maybe.default default (read idx array)) @@ -277,7 +279,7 @@ (def: (= xs ys) (let [sxs (size xs) sxy (size ys)] - (and (n/= sxy sxs) + (and (n.= sxy sxs) (list@fold (function (_ idx prev) (and prev (case [(read idx xs) (read idx ys)] @@ -298,14 +300,14 @@ (def: (compose xs ys) (let [sxs (size xs) sxy (size ys)] - (|> (new (n/+ sxy sxs)) + (|> (new (n.+ sxy sxs)) (copy sxs 0 xs 0) (copy sxy 0 ys sxs))))) (structure: #export functor (Functor Array) (def: (map f ma) (let [arr-size (size ma)] - (if (n/= 0 arr-size) + (if (n.= 0 arr-size) (new arr-size) (list@fold (function (_ idx mb) (case (read idx ma) @@ -323,7 +325,7 @@ (let [arr-size (size xs)] (loop [so-far init idx 0] - (if (n/< arr-size idx) + (if (n.< arr-size idx) (case (read idx xs) #.None (recur so-far (inc idx)) @@ -338,7 +340,7 @@ (-> (Predicate a) (Array a) Bit)) (let [size (..size array)] (loop [idx 0] - (if (n/< size idx) + (if (n.< size idx) (case (..read idx array) (#.Some value) (<op> (predicate value) diff --git a/stdlib/source/lux/data/collection/bits.lux b/stdlib/source/lux/data/collection/bits.lux index 4ffbe2bc8..2529275a3 100644 --- a/stdlib/source/lux/data/collection/bits.lux +++ b/stdlib/source/lux/data/collection/bits.lux @@ -7,7 +7,8 @@ [data ["." maybe] [number - ["." i64]] + ["." i64] + ["n" nat]] [collection ["." array (#+ Array) ("#@." fold)]]]]) @@ -27,43 +28,43 @@ (def: #export (size bits) (-> Bits Nat) (array@fold (function (_ chunk total) - (|> chunk i64.count (n/+ total))) + (|> chunk i64.count (n.+ total))) 0 bits)) (def: #export (capacity bits) (-> Bits Nat) - (|> bits array.size (n/* chunk-size))) + (|> bits array.size (n.* chunk-size))) (def: #export empty? (-> Bits Bit) - (|>> size (n/= 0))) + (|>> size (n.= 0))) (def: #export (get index bits) (-> Nat Bits Bit) - (let [[chunk-index bit-index] (n//% chunk-size index)] - (.and (n/< (array.size bits) chunk-index) + (let [[chunk-index bit-index] (n./% chunk-size index)] + (.and (n.< (array.size bits) chunk-index) (|> (array.read chunk-index bits) (maybe.default empty-chunk) (i64.set? bit-index))))) (def: (chunk idx bits) (-> Nat Bits Chunk) - (if (n/< (array.size bits) idx) + (if (n.< (array.size bits) idx) (|> bits (array.read idx) (maybe.default empty-chunk)) empty-chunk)) (template [<name> <op>] [(def: #export (<name> index input) (-> Nat Bits Bits) - (let [[chunk-index bit-index] (n//% chunk-size index)] - (loop [size|output (n/max (inc chunk-index) + (let [[chunk-index bit-index] (n./% chunk-size index)] + (loop [size|output (n.max (inc chunk-index) (array.size input)) output ..empty] (let [idx|output (dec size|output)] - (if (n/> 0 size|output) + (if (n.> 0 size|output) (case (|> (..chunk idx|output input) - (cond> [(new> (n/= chunk-index idx|output) [])] + (cond> [(new> (n.= chunk-index idx|output) [])] [(<op> bit-index)] ## else @@ -89,10 +90,10 @@ (def: #export (intersects? reference sample) (-> Bits Bits Bit) - (let [chunks (n/min (array.size reference) + (let [chunks (n.min (array.size reference) (array.size sample))] (loop [idx 0] - (if (n/< chunks idx) + (if (n.< chunks idx) (.or (|> (..chunk idx sample) (i64.and (..chunk idx reference)) ("lux i64 =" empty-chunk) @@ -115,7 +116,7 @@ (recur (dec size|output) output) chunk - (if (n/> 0 size|output) + (if (n.> 0 size|output) (|> (if (is? ..empty output) (: Bits (array.new size|output)) output) @@ -126,7 +127,7 @@ (template [<name> <op>] [(def: #export (<name> param subject) (-> Bits Bits Bits) - (case (n/max (array.size param) + (case (n.max (array.size param) (array.size subject)) 0 ..empty @@ -135,7 +136,7 @@ (loop [size|output size|output output ..empty] (let [idx (dec size|output)] - (if (n/> 0 size|output) + (if (n.> 0 size|output) (case (|> (..chunk idx subject) (<op> (..chunk idx param)) .nat) @@ -157,10 +158,10 @@ (structure: #export equivalence (Equivalence Bits) (def: (= reference sample) - (let [size (n/max (array.size reference) + (let [size (n.max (array.size reference) (array.size sample))] (loop [idx 0] - (if (n/< size idx) + (if (n.< size idx) (.and ("lux i64 =" (..chunk idx reference) (..chunk idx sample)) diff --git a/stdlib/source/lux/data/collection/dictionary.lux b/stdlib/source/lux/data/collection/dictionary.lux index bf5c64d43..195640d66 100644 --- a/stdlib/source/lux/data/collection/dictionary.lux +++ b/stdlib/source/lux/data/collection/dictionary.lux @@ -8,7 +8,8 @@ ["." maybe] ["." product] ["." number - ["." i64]] + ["." i64] + ["n" nat]] [collection ["." list ("#@." fold functor monoid)] ["." array (#+ Array) ("#@." functor fold)]]] @@ -100,13 +101,13 @@ ## which is 1/4 of the branching factor (or a left-shift 2). (def: demotion-threshold Nat - (i64.left-shift (n/- 2 branching-exponent) 1)) + (i64.left-shift (n.- 2 branching-exponent) 1)) ## The threshold on which #Base nodes are promoted to #Hierarchy nodes, ## which is 1/2 of the branching factor (or a left-shift 1). (def: promotion-threshold Nat - (i64.left-shift (n/- 1 branching-exponent) 1)) + (i64.left-shift (n.- 1 branching-exponent) 1)) ## The size of hierarchy-nodes, which is 2^(branching-exponent). (def: hierarchy-nodes-size @@ -126,7 +127,7 @@ (|> (array.new (inc old-size)) (array.copy idx 0 old-array 0) (array.write idx value) - (array.copy (n/- idx old-size) idx old-array (inc idx))))) + (array.copy (n.- idx old-size) idx old-array (inc idx))))) ## Creates a copy of an array with an index set to a particular value. (def: (update! idx value array) @@ -144,13 +145,13 @@ (let [new-size (dec (array.size array))] (|> (array.new new-size) (array.copy idx 0 array 0) - (array.copy (n/- idx new-size) (inc idx) array idx)))) + (array.copy (n.- idx new-size) (inc idx) array idx)))) ## Increases the level-shift by the branching-exponent, to explore ## levels further down the tree. (def: level-up (-> Level Level) - (n/+ branching-exponent)) + (n.+ branching-exponent)) (def: hierarchy-mask BitMap (dec hierarchy-nodes-size)) @@ -173,12 +174,12 @@ (def: (bit-position-is-set? bit bitmap) (-> BitPosition BitMap Bit) - (not (n/= clean-bitmap (i64.and bit bitmap)))) + (not (n.= clean-bitmap (i64.and bit bitmap)))) ## Figures out whether a bitmap only contains a single bit-position. (def: only-bit-position? (-> BitPosition BitMap Bit) - n/=) + n.=) (def: (set-bit-position bit bitmap) (-> BitPosition BitMap BitMap) @@ -223,7 +224,7 @@ (let [[bitmap base] node] (case (array.read idx h-array) #.None [insertion-idx node] - (#.Some sub-node) (if (n/= except-idx idx) + (#.Some sub-node) (if (n.= except-idx idx) [insertion-idx node] [(inc insertion-idx) [(set-bit-position (->bit-position idx) bitmap) @@ -316,7 +317,7 @@ ## Otherwise, I compare the hashes of the keys. (#Base bitmap (update! idx (#.Left (let [hash' (:: Hash<k> hash key')] - (if (n/= hash hash') + (if (n.= hash hash') ## If the hashes are ## the same, a new ## #Collisions node @@ -337,7 +338,7 @@ ## However, if the BitPosition has not been used yet, I check ## whether this #Base node is ready for a promotion. (let [base-count (bitmap-size bitmap)] - (if (n/>= promotion-threshold base-count) + (if (n.>= promotion-threshold base-count) ## If so, I promote it to a #Hierarchy node, and add the new ## KV-pair as a singleton node to it. (#Hierarchy (inc base-count) @@ -351,7 +352,7 @@ ## For #Collisions nodes, I compare the hashes. (#Collisions _hash _colls) - (if (n/= hash _hash) + (if (n.= hash _hash) ## If they're equal, that means the new KV contributes to the ## collisions. (case (collision-index Hash<k> key _colls) @@ -393,7 +394,7 @@ ## But if the sub-removal yielded an empty sub-node... (if (empty?' sub-node') ## Check if it's due time for a demotion. - (if (n/<= demotion-threshold h-size) + (if (n.<= demotion-threshold h-size) ## If so, perform it. (#Base (demote-hierarchy idx [h-size h-array])) ## Otherwise, just clear the space. @@ -455,7 +456,7 @@ ## But if so, then check the size of the collisions list. (#.Some idx) - (if (n/= 1 (array.size _colls)) + (if (n.= 1 (array.size _colls)) ## If there's only one left, then removing it leaves us with ## an empty node. empty @@ -500,10 +501,10 @@ (All [k v] (-> (Node k v) Nat)) (case node (#Hierarchy _size hierarchy) - (array@fold n/+ 0 (array@map size' hierarchy)) + (array@fold n.+ 0 (array@map size' hierarchy)) (#Base _ base) - (array@fold n/+ 0 (array@map (function (_ sub-node') + (array@fold n.+ 0 (array@map (function (_ sub-node') (case sub-node' (#.Left sub-node) (size' sub-node) (#.Right _) 1)) @@ -600,7 +601,7 @@ (def: #export empty? (All [k v] (-> (Dictionary k v) Bit)) - (|>> size (n/= 0))) + (|>> size (n.= 0))) (def: #export (entries dict) (All [k v] (-> (Dictionary k v) (List [k v]))) @@ -670,7 +671,7 @@ (All [k v] (-> (Equivalence v) (Equivalence (Dictionary k v)))) (def: (= test subject) - (and (n/= (size test) + (and (n.= (size test) (size subject)) (list.every? (function (_ k) (case [(get k test) (get k subject)] diff --git a/stdlib/source/lux/data/collection/dictionary/ordered.lux b/stdlib/source/lux/data/collection/dictionary/ordered.lux index ed090a5d7..32d1a7db1 100644 --- a/stdlib/source/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/lux/data/collection/dictionary/ordered.lux @@ -7,6 +7,8 @@ [data ["p" product] ["." maybe] + [number + ["n" nat]] [collection ["." list ("#@." monoid fold)]]] ["." macro @@ -122,8 +124,8 @@ (inc (<op> (recur (get@ #left node)) (recur (get@ #right node)))))))] - [size n/+] - [depth n/max] + [size n.+] + [depth n.max] ) (template [<name> <other-color> <self-color> <no-change>] diff --git a/stdlib/source/lux/data/collection/list.lux b/stdlib/source/lux/data/collection/list.lux index abf9d3fe8..1e00ee529 100644 --- a/stdlib/source/lux/data/collection/list.lux +++ b/stdlib/source/lux/data/collection/list.lux @@ -11,7 +11,9 @@ ["." monad (#+ do Monad)]] [data ["." bit] - ["." product]]]) + ["." product] + [number + ["n" nat]]]]) ## (type: (List a) ## #Nil @@ -73,7 +75,7 @@ [(def: #export (<name> n xs) (All [a] (-> Nat (List a) (List a))) - (if (n/> 0 n) + (if (n.> 0 n) (case xs #.Nil #.Nil @@ -106,7 +108,7 @@ (def: #export (split n xs) (All [a] (-> Nat (List a) [(List a) (List a)])) - (if (n/> 0 n) + (if (n.> 0 n) (case xs #.Nil [#.Nil #.Nil] @@ -150,7 +152,7 @@ {#.doc "A list of the value x, repeated n times."} (All [a] (-> Nat a (List a))) - (if (n/> 0 n) + (if (n.> 0 n) (#.Cons [x (repeat (dec n) x)]) #.Nil)) @@ -234,7 +236,7 @@ (def: #export (size list) (All [a] (-> (List a) Nat)) - (fold (function (_ _ acc) (n/+ 1 acc)) 0 list)) + (fold (function (_ _ acc) (n.+ 1 acc)) 0 list)) (template [<name> <init> <op>] [(def: #export (<name> predicate xs) @@ -266,7 +268,7 @@ #.None (#.Cons [x xs']) - (if (n/= 0 i) + (if (n.= 0 i) (#.Some x) (nth (dec i) xs')))) @@ -351,7 +353,7 @@ (list from)))] [i/range Int "lux i64 <"] - [n/range Nat n/<] + [n/range Nat n.<] ) (def: #export (empty? xs) @@ -385,7 +387,7 @@ (def: #export (indices size) {#.doc "Produces all the valid indices for a given size."} (All [a] (-> Nat (List Nat))) - (if (n/= 0 size) + (if (n.= 0 size) (list) (|> size dec (n/range 0)))) @@ -397,7 +399,7 @@ (-> Nat Text) (loop [input value output ""] - (let [digit (case (n/% 10 input) + (let [digit (case (n.% 10 input) 0 "0" 1 "1" 2 "2" @@ -410,8 +412,8 @@ 9 "9" _ (undefined)) output' ("lux text concat" digit output) - input' (n// 10 input)] - (if (n/= 0 input') + input' (n./ 10 input)] + (if (n.= 0 input') output' (recur input' output'))))) @@ -422,7 +424,7 @@ ((zip 3) xs ys zs))} (case tokens (^ (list [_ (#.Nat num-lists)])) - (if (n/> 0 num-lists) + (if (n.> 0 num-lists) (let [(^open ".") ..functor indices (..indices num-lists) type-vars (: (List Code) (map (|>> nat@encode identifier$) indices)) @@ -466,7 +468,7 @@ ((zip-with 2) + xs ys))} (case tokens (^ (list [_ (#.Nat num-lists)])) - (if (n/> 0 num-lists) + (if (n.> 0 num-lists) (let [(^open ".") ..functor indices (..indices num-lists) g!return-type (identifier$ "0return-type0") diff --git a/stdlib/source/lux/data/collection/queue.lux b/stdlib/source/lux/data/collection/queue.lux index 026190f2b..9bf4dcf81 100644 --- a/stdlib/source/lux/data/collection/queue.lux +++ b/stdlib/source/lux/data/collection/queue.lux @@ -4,6 +4,8 @@ [equivalence (#+ Equivalence)] [functor (#+ Functor)]] [data + [number + ["n" nat]] [collection ["." list ("#;." monoid functor)]]]]) @@ -33,7 +35,7 @@ (def: #export (size queue) (All [a] (-> (Queue a) Nat)) (let [(^slots [#front #rear]) queue] - (n/+ (list.size front) + (n.+ (list.size front) (list.size rear)))) (def: #export empty? diff --git a/stdlib/source/lux/data/collection/queue/priority.lux b/stdlib/source/lux/data/collection/queue/priority.lux index 34a87e51d..50f6f7de6 100644 --- a/stdlib/source/lux/data/collection/queue/priority.lux +++ b/stdlib/source/lux/data/collection/queue/priority.lux @@ -6,7 +6,7 @@ [data ["." maybe] [number - ["." nat ("#;." interval)]] + ["n" nat ("#@." interval)]] [collection [tree ["." finger (#+ Tree)]]]]]) @@ -16,8 +16,8 @@ (type: #export (Queue a) (Maybe (Tree Priority a))) -(def: #export max Priority nat;top) -(def: #export min Priority nat;bottom) +(def: #export max Priority n@top) +(def: #export min Priority n@bottom) (def: #export empty Queue @@ -27,7 +27,7 @@ (All [a] (-> (Queue a) (Maybe a))) (do maybe.monad [fingers queue] - (wrap (maybe.assume (finger.search (n/= (finger.tag fingers)) fingers))))) + (wrap (maybe.assume (finger.search (n.= (finger.tag fingers)) fingers))))) (def: #export (size queue) (All [a] (-> (Queue a) Nat)) @@ -42,7 +42,7 @@ 1 (#finger.Branch _ left right) - (n/+ (recur left) (recur right)))))) + (n.+ (recur left) (recur right)))))) (def: #export (member? Equivalence<a> queue member) (All [a] (-> (Equivalence a) (Queue a) a Bit)) @@ -68,12 +68,12 @@ node' (loop [node (get@ #finger.node fingers)] (case node (#finger.Leaf priority reference) - (if (n/= highest-priority priority) + (if (n.= highest-priority priority) #.None (#.Some node)) (#finger.Branch priority left right) - (if (n/= highest-priority (finger.tag (set@ #finger.node left fingers))) + (if (n.= highest-priority (finger.tag (set@ #finger.node left fingers))) (case (recur left) #.None (#.Some right) @@ -97,7 +97,7 @@ (def: #export (push priority value queue) (All [a] (-> Priority a (Queue a) (Queue a))) - (let [addition {#finger.monoid nat.maximum + (let [addition {#finger.monoid n.maximum #finger.node (#finger.Leaf priority value)}] (case queue #.None diff --git a/stdlib/source/lux/data/collection/row.lux b/stdlib/source/lux/data/collection/row.lux index 71bb5202a..d73f8bbf5 100644 --- a/stdlib/source/lux/data/collection/row.lux +++ b/stdlib/source/lux/data/collection/row.lux @@ -16,7 +16,8 @@ ["." maybe] ["." product] [number - ["." i64]] + ["." i64] + ["n" nat]] [collection ["." list ("#@." fold functor monoid)] ["." array (#+ Array) ("#@." functor fold)]]] @@ -48,8 +49,8 @@ (-> Level Level) (<op> branching-exponent))] - [level-up n/+] - [level-down n/-] + [level-up n.+] + [level-down n.-] ) (def: full-node-size @@ -70,7 +71,7 @@ (def: (tail-off row-size) (-> Nat Nat) - (if (n/< full-node-size row-size) + (if (n.< full-node-size row-size) 0 (|> (dec row-size) (i64.logic-right-shift branching-exponent) @@ -78,7 +79,7 @@ (def: (new-path level tail) (All [a] (-> Level (Base a) (Node a))) - (if (n/= 0 level) + (if (n.= 0 level) (#Base tail) (|> (new-hierarchy []) (array.write 0 (new-path (level-down level) tail)) @@ -93,7 +94,7 @@ (All [a] (-> Nat Level (Base a) (Hierarchy a) (Hierarchy a))) (let [sub-idx (branch-idx (i64.logic-right-shift level (dec size))) ## If we're currently on a bottom node - sub-node (if (n/= branching-exponent level) + sub-node (if (n.= branching-exponent level) ## Just add the tail to it (#Base tail) ## Otherwise, check whether there's a vacant spot @@ -127,7 +128,7 @@ (array.write sub-idx (#Hierarchy (put' (level-down level) idx val sub-node)))) (^multi (#.Some (#Base base)) - (n/= 0 (level-down level))) + (n.= 0 (level-down level))) (|> (array.clone hierarchy) (array.write sub-idx (|> (array.clone base) (array.write (branch-idx idx) val) @@ -138,11 +139,11 @@ (def: (pop-tail size level hierarchy) (All [a] (-> Nat Level (Hierarchy a) (Maybe (Hierarchy a)))) - (let [sub-idx (branch-idx (i64.logic-right-shift level (n/- 2 size)))] - (cond (n/= 0 sub-idx) + (let [sub-idx (branch-idx (i64.logic-right-shift level (n.- 2 size)))] + (cond (n.= 0 sub-idx) #.None - (n/> branching-exponent level) + (n.> branching-exponent level) (do maybe.monad [base|hierarchy (array.read sub-idx hierarchy) sub (case base|hierarchy @@ -195,7 +196,7 @@ (All [a] (-> a (Row a) (Row a))) ## Check if there is room in the tail. (let [row-size (get@ #size row)] - (if (|> row-size (n/- (tail-off row-size)) (n/< full-node-size)) + (if (|> row-size (n.- (tail-off row-size)) (n.< full-node-size)) ## If so, append to it. (|> row (update@ #size inc) @@ -203,7 +204,7 @@ ## Otherwise, push tail into the tree ## -------------------------------------------------------- ## Will the root experience an overflow with this addition? - (|> (if (n/> (i64.left-shift (get@ #level row) 1) + (|> (if (n.> (i64.left-shift (get@ #level row) 1) (i64.logic-right-shift branching-exponent row-size)) ## If so, a brand-new root must be established, that is ## 1-level taller. @@ -227,13 +228,13 @@ (def: (base-for idx row) (All [a] (-> Index (Row a) (Maybe (Base a)))) (let [row-size (get@ #size row)] - (if (and (n/>= 0 idx) - (n/< row-size idx)) - (if (n/>= (tail-off row-size) idx) + (if (and (n.>= 0 idx) + (n.< row-size idx)) + (if (n.>= (tail-off row-size) idx) (#.Some (get@ #tail row)) (loop [level (get@ #level row) hierarchy (get@ #root row)] - (case [(n/> branching-exponent level) + (case [(n.> branching-exponent level) (array.read (branch-idx (i64.logic-right-shift level idx)) hierarchy)] [#1 (#.Some (#Hierarchy sub))] (recur (level-down level) sub) @@ -257,9 +258,9 @@ (def: #export (put idx val row) (All [a] (-> Nat a (Row a) (Row a))) (let [row-size (get@ #size row)] - (if (and (n/>= 0 idx) - (n/< row-size idx)) - (if (n/>= (tail-off row-size) idx) + (if (and (n.>= 0 idx) + (n.< row-size idx)) + (if (n.>= (tail-off row-size) idx) (update@ #tail (`` (for {(~~ (static @.old)) (: (-> (Base ($ 0)) (Base ($ 0))) (|>> array.clone (array.write (branch-idx idx) val)))} @@ -288,7 +289,7 @@ empty row-size - (if (|> row-size (n/- (tail-off row-size)) (n/> 1)) + (if (|> row-size (n.- (tail-off row-size)) (n.> 1)) (let [old-tail (get@ #tail row) new-tail-size (dec (array.size old-tail))] (|> row @@ -297,12 +298,12 @@ (array.copy new-tail-size 0 old-tail 0))))) (maybe.assume (do maybe.monad - [new-tail (base-for (n/- 2 row-size) row) + [new-tail (base-for (n.- 2 row-size) row) #let [[level' root'] (let [init-level (get@ #level row)] (loop [level init-level root (maybe.default (new-hierarchy []) (pop-tail row-size init-level (get@ #root row)))] - (if (n/> branching-exponent level) + (if (n.> branching-exponent level) (case [(array.read 1 root) (array.read 0 root)] [#.None (#.Some (#Hierarchy sub-node))] (recur (level-down level) sub-node) @@ -335,7 +336,7 @@ (def: #export empty? (All [a] (-> (Row a) Bit)) - (|>> (get@ #size) (n/= 0))) + (|>> (get@ #size) (n.= 0))) (syntax: #export (row {elems (p.some s.any)}) {#.doc (doc "Row literals." @@ -356,7 +357,7 @@ (structure: #export (equivalence Equivalence<a>) (All [a] (-> (Equivalence a) (Equivalence (Row a)))) (def: (= v1 v2) - (and (n/= (get@ #size v1) (get@ #size v2)) + (and (n.= (get@ #size v1) (get@ #size v2)) (let [(^open "Node/.") (node-equivalence Equivalence<a>)] (and (Node/= (#Base (get@ #tail v1)) (#Base (get@ #tail v2))) diff --git a/stdlib/source/lux/data/collection/sequence.lux b/stdlib/source/lux/data/collection/sequence.lux index ef61dd427..98df00636 100644 --- a/stdlib/source/lux/data/collection/sequence.lux +++ b/stdlib/source/lux/data/collection/sequence.lux @@ -12,6 +12,8 @@ [syntax (#+ syntax:)]] [data ["." bit] + [number + ["n" nat]] [collection ["." list ("#;." monad)]]]]) @@ -65,7 +67,7 @@ (def: #export (nth idx s) (All [a] (-> Nat (Sequence a) a)) (let [[h t] (continuation.run s)] - (if (n/> 0 idx) + (if (n.> 0 idx) (nth (dec idx) t) h))) @@ -96,7 +98,7 @@ [(list) xs])))] [take-while drop-while split-while (-> a Bit) (pred x) pred] - [take drop split Nat (n/> 0 pred) (dec pred)] + [take drop split Nat (n.> 0 pred) (dec pred)] ) (def: #export (unfold step init) diff --git a/stdlib/source/lux/data/collection/set.lux b/stdlib/source/lux/data/collection/set.lux index 4c764b818..f8df4e479 100644 --- a/stdlib/source/lux/data/collection/set.lux +++ b/stdlib/source/lux/data/collection/set.lux @@ -6,6 +6,8 @@ [monoid (#+ Monoid)] ["." hash (#+ Hash)]] [data + [number + ["n" nat]] [collection ["//" dictionary (#+ Dictionary)] ["." list ("#@." fold)]]]]) @@ -59,7 +61,7 @@ (def: &equivalence ..equivalence) (def: (hash (^@ set [hash _])) - (list@fold (function (_ elem acc) (n/+ (:: hash hash elem) acc)) + (list@fold (function (_ elem acc) (n.+ (:: hash hash elem) acc)) 0 (..to-list set)))) @@ -72,7 +74,7 @@ (def: #export empty? (All [a] (-> (Set a) Bit)) - (|>> ..size (n/= 0))) + (|>> ..size (n.= 0))) (def: #export (from-list hash elements) (All [a] (-> (Hash a) (List a) (Set a))) diff --git a/stdlib/source/lux/data/collection/set/multi.lux b/stdlib/source/lux/data/collection/set/multi.lux index c11d4c558..4f3f02276 100644 --- a/stdlib/source/lux/data/collection/set/multi.lux +++ b/stdlib/source/lux/data/collection/set/multi.lux @@ -7,12 +7,14 @@ ["." function] [type (#+ :share) abstract]] - [//// - ["." maybe]] - [/// - ["." list ("#;." fold)] - ["." dictionary (#+ Dictionary)]] - ["." //]) + ["." // + [// + ["." list ("#;." fold)] + ["." dictionary (#+ Dictionary)] + [// + ["." maybe] + [number + ["n" nat]]]]]) (abstract: #export (Set a) {} @@ -25,11 +27,11 @@ (def: #export size (All [a] (-> (Set a) Nat)) - (|>> :representation dictionary.values (list;fold n/+ 0))) + (|>> :representation dictionary.values (list;fold n.+ 0))) (def: #export (add/* count elem set) (All [a] (-> Nat a (Set a) (Set a))) - (|> set :representation (dictionary.update~ elem 0 (n/+ count)) :abstraction)) + (|> set :representation (dictionary.update~ elem 0 (n.+ count)) :abstraction)) (def: #export add/1 (All [a] (-> a (Set a) (Set a))) @@ -43,8 +45,8 @@ {(Set a) set} {(-> (Dictionary a Nat) (Dictionary a Nat)) - (if (n/> count current) - (dictionary.update elem (n/- count)) + (if (n.> count current) + (dictionary.update elem (n.- count)) (dictionary.remove elem))})] (|> set :representation transform :abstraction)) @@ -74,7 +76,7 @@ (def: #export (union parameter subject) (All [a] (-> (Set a) (Set a) (Set a))) - (:abstraction (dictionary.merge-with n/+ (:representation parameter) (:representation subject)))) + (:abstraction (dictionary.merge-with n.+ (:representation parameter) (:representation subject)))) (def: #export (difference parameter subject) (All [a] (-> (Set a) (Set a) (Set a))) @@ -92,7 +94,7 @@ dictionary.entries (list;fold (function (_ [elem count] (^:representation output)) (:abstraction (if (dictionary.contains? elem output) - (dictionary.update elem (n/min count) output) + (dictionary.update elem (n.min count) output) output))) subject))) @@ -106,7 +108,7 @@ :representation (dictionary.get elem) (maybe.default 0) - (n/>= count)))))) + (n.>= count)))))) (def: #export (support set) (All [a] (-> (Set a) (//.Set a))) @@ -117,7 +119,7 @@ (structure: #export equivalence (All [a] (Equivalence (Set a))) (def: (= (^:representation reference) (^:representation sample)) - (and (n/= (dictionary.size reference) + (and (n.= (dictionary.size reference) (dictionary.size sample)) (|> reference dictionary.entries @@ -125,7 +127,7 @@ (|> sample (dictionary.get elem) (maybe.default 0) - (n/= count)))))))) + (n.= count)))))))) (structure: #export hash (All [a] (Hash (Set a))) (def: &equivalence ..equivalence) @@ -133,18 +135,18 @@ (def: (hash (^:representation set)) (let [[Hash<a> _] set] (list;fold (function (_ [elem count] acc) - (|> elem (:: Hash<a> hash) (n/* count) (n/+ acc))) + (|> elem (:: Hash<a> hash) (n.* count) (n.+ acc))) 0 (dictionary.entries set))))) ) (def: #export (member? set elem) (All [a] (-> (Set a) a Bit)) - (|> set (..multiplicity elem) (n/> 0))) + (|> set (..multiplicity elem) (n.> 0))) (def: #export empty? (All [a] (-> (Set a) Bit)) - (|>> ..size (n/= 0))) + (|>> ..size (n.= 0))) (def: #export (from-list Hash<a> subject) (All [a] (-> (Hash a) (List a) (Set a))) diff --git a/stdlib/source/lux/data/color.lux b/stdlib/source/lux/data/color.lux index 3a094b01c..11da105cf 100644 --- a/stdlib/source/lux/data/color.lux +++ b/stdlib/source/lux/data/color.lux @@ -4,6 +4,7 @@ [equivalence (#+ Equivalence)]] [data [number + ["n" nat] ["." int] ["." rev ("#;." interval)] ["f" frac]] @@ -50,9 +51,9 @@ (def: #export (from-rgb [red green blue]) (-> RGB Color) - (:abstraction {#red (n/% rgb red) - #green (n/% rgb green) - #blue (n/% rgb blue)})) + (:abstraction {#red (n.% rgb red) + #green (n.% rgb green) + #blue (n.% rgb blue)})) (def: #export to-rgb (-> Color RGB) @@ -62,9 +63,9 @@ (def: (= reference sample) (let [[rr rg rb] (:representation reference) [sr sg sb] (:representation sample)] - (and (n/= rr sr) - (n/= rg sg) - (n/= rb sb))))) + (and (n.= rr sr) + (n.= rg sg) + (n.= rb sb))))) ) (def: #export (to-hsl color) @@ -268,7 +269,7 @@ (def: #export (complement color) (-> Color Color) (let [[red green blue] (to-rgb color) - adjust (function (_ value) (|> top (n/- value)))] + adjust (function (_ value) (|> top (n.- value)))] (from-rgb {#red (adjust red) #green (adjust green) #blue (adjust blue)}))) @@ -332,7 +333,7 @@ (def: #export (analogous results slice color) (-> Nat Frac Color (List Color)) - (if (n/= 0 results) + (if (n.= 0 results) (list) (let [[hue saturation luminance] (to-hsl color) slice (normalize slice)] @@ -344,7 +345,7 @@ (def: #export (monochromatic results color) (-> Nat Color (List Color)) - (if (n/= 0 results) + (if (n.= 0 results) (list) (let [[hue saturation brightness] (to-hsb color) slice (|> +1.0 (f./ (|> results .int int.frac)))] diff --git a/stdlib/source/lux/data/format/binary.lux b/stdlib/source/lux/data/format/binary.lux index 58ea7eb05..03af219a7 100644 --- a/stdlib/source/lux/data/format/binary.lux +++ b/stdlib/source/lux/data/format/binary.lux @@ -17,6 +17,7 @@ ["." binary (#+ Binary)] [number ["." i64] + ["n" nat] ["." frac]] [text ["." encoding] @@ -27,7 +28,7 @@ (def: mask (-> Size (I64 Any)) - (|>> (n/* i64.bits-per-byte) i64.mask)) + (|>> (n.* i64.bits-per-byte) i64.mask)) (type: #export Mutation (-> [Offset Binary] [Offset Binary])) @@ -49,7 +50,7 @@ ..no-op) (def: (compose [sizeL mutL] [sizeR mutR]) - [(n/+ sizeL sizeR) + [(n.+ sizeL sizeR) (|>> mutL mutR)])) (type: #export (Writer a) @@ -65,7 +66,7 @@ (function (_ value) [<size> (function (_ [offset binary]) - [(n/+ <size> offset) + [(n.+ <size> offset) (|> binary (<write> offset value) try.assume)])]))] @@ -121,7 +122,7 @@ (function (_ value) [1 (function (_ [offset binary]) - [(n/+ 1 offset) + [(n.+ 1 offset) (|> binary (binary.write/8 offset (if value 1 0)) try.assume)])])) @@ -144,14 +145,14 @@ (let [mask (..mask <size>)] (function (_ value) (let [size (|> value binary.size (i64.and mask)) - size' (n/+ <size> size)] + size' (n.+ <size> size)] [size' (function (_ [offset binary]) - [(n/+ size' offset) + [(n.+ size' offset) (try.assume (do try.monad [_ (<write> offset size binary)] - (binary.copy size 0 value (n/+ <size> offset) binary)))])]))))] + (binary.copy size 0 value (n.+ <size> offset) binary)))])]))))] [binary/8 ..bits/8 /.size/8 binary.write/8] [binary/16 ..bits/16 /.size/16 binary.write/16] @@ -179,7 +180,7 @@ (let [original-count (row.size value) capped-count (i64.and (..mask <size>) original-count) - value (if (n/= original-count capped-count) + value (if (n.= original-count capped-count) value (|> value row.to-list (list.take capped-count) row.from-list)) (^open "specification@.") ..monoid @@ -189,12 +190,12 @@ (function (_ post pre) (specification@compose pre post)) specification@identity))] - [(n/+ <size> size) + [(n.+ <size> size) (function (_ [offset binary]) (try.assume (do try.monad [_ (<write> offset capped-count binary)] - (wrap (mutation [(n/+ <size> offset) binary])))))])))] + (wrap (mutation [(n.+ <size> offset) binary])))))])))] [row/8 /.size/8 binary.write/8] [row/16 /.size/16 binary.write/16] diff --git a/stdlib/source/lux/data/format/css/value.lux b/stdlib/source/lux/data/format/css/value.lux index 558bf2fcb..4b3f3b1ba 100644 --- a/stdlib/source/lux/data/format/css/value.lux +++ b/stdlib/source/lux/data/format/css/value.lux @@ -8,7 +8,7 @@ ["." product] ["." maybe] [number - ["." nat] + ["n" nat] ["i" int] ["r" rev] ["f" frac]] @@ -952,7 +952,7 @@ (def: #export (degree value) (-> Nat Angle) - (:abstraction (format (%.nat (n/% ..degree-limit value)) "deg"))) + (:abstraction (format (%.nat (n.% ..degree-limit value)) "deg"))) (template [<degree> <name>] [(def: #export <name> Angle (..degree <degree>))] @@ -989,7 +989,7 @@ (def: #export (%% value) (-> Nat Percentage) - (:abstraction (format (%.nat (n/% percentage-limit value)) "%"))) + (:abstraction (format (%.nat (n.% percentage-limit value)) "%"))) (def: #export slice-percent/1 (-> Percentage (Value Slice)) @@ -1008,7 +1008,7 @@ (~~ (template.splice <function>+))))] - [Nat (<| (:representation Value) ..px nat.frac) + [Nat (<| (:representation Value) ..px n.frac) [[blur "blur"]]] [Nat (<| ..angle ..degree) [[hue-rotate "hue-rotate"]]] diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index d847d801b..60d57abab 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -16,6 +16,7 @@ ["." maybe] ["." product] [number + ["n" nat] ["f" frac ("#@." decimal)]] ["." text ("#@." equivalence monoid)] [collection @@ -161,7 +162,7 @@ [#String text.equivalence]) [(#Array xs) (#Array ys)] - (and (n/= (row.size xs) (row.size ys)) + (and (n.= (row.size xs) (row.size ys)) (list@fold (function (_ idx prev) (and prev (maybe.default #0 @@ -173,7 +174,7 @@ (list.indices (row.size xs)))) [(#Object xs) (#Object ys)] - (and (n/= (dictionary.size xs) (dictionary.size ys)) + (and (n.= (dictionary.size xs) (dictionary.size ys)) (list@fold (function (_ [xk xv] prev) (and prev (case (dictionary.get xk ys) diff --git a/stdlib/source/lux/data/format/xml.lux b/stdlib/source/lux/data/format/xml.lux index c4524fdf9..9a3c0b6b4 100644 --- a/stdlib/source/lux/data/format/xml.lux +++ b/stdlib/source/lux/data/format/xml.lux @@ -12,6 +12,7 @@ ["." product] ["." name ("#@." equivalence codec)] [number + ["n" nat] ["." int]] ["." text ("#@." equivalence monoid)] [collection @@ -237,7 +238,7 @@ (#Node sample/tag sample/attrs sample/children)] (and (name@= reference/tag sample/tag) (:: (dictionary.equivalence text.equivalence) = reference/attrs sample/attrs) - (n/= (list.size reference/children) + (n.= (list.size reference/children) (list.size sample/children)) (|> (list.zip2 reference/children sample/children) (list.every? (product.uncurry =)))) diff --git a/stdlib/source/lux/data/name.lux b/stdlib/source/lux/data/name.lux index 557ecf1ec..88eb25c99 100644 --- a/stdlib/source/lux/data/name.lux +++ b/stdlib/source/lux/data/name.lux @@ -56,4 +56,4 @@ (def: &equivalence ..equivalence) (def: (hash [module name]) - (n/+ (text@hash module) (text@hash name)))) + ("lux i64 +" (text@hash module) (text@hash name)))) diff --git a/stdlib/source/lux/data/number/complex.lux b/stdlib/source/lux/data/number/complex.lux index ec4b27326..ede5bb980 100644 --- a/stdlib/source/lux/data/number/complex.lux +++ b/stdlib/source/lux/data/number/complex.lux @@ -11,6 +11,7 @@ [data ["." maybe] [number + ["n" nat] ["." int] ["f" frac]] ["." text ("#;." monoid)] @@ -278,7 +279,7 @@ (def: #export (roots nth input) (-> Nat Complex (List Complex)) - (if (n/= 0 nth) + (if (n.= 0 nth) (list) (let [r-nth (|> nth .int int.frac) nth-root-of-abs (|> input abs (get@ #real) (math.pow (f./ r-nth +1.0))) diff --git a/stdlib/source/lux/data/number/frac.lux b/stdlib/source/lux/data/number/frac.lux index 522f3c674..0cd8fe897 100644 --- a/stdlib/source/lux/data/number/frac.lux +++ b/stdlib/source/lux/data/number/frac.lux @@ -196,7 +196,7 @@ +1.0) div-power (loop [muls-left ("lux text size" decimal-part) output +1.0] - (if (n/= 0 muls-left) + (if (//nat.= 0 muls-left) output (recur (dec muls-left) (..* <base> output)))) @@ -227,9 +227,9 @@ _ (let [num-digits ("lux text size" digits)] - (if (n/<= chunk-size num-digits) + (if (//nat.<= chunk-size num-digits) (list digits) - (let [boundary (n/- chunk-size num-digits) + (let [boundary (//nat.- chunk-size num-digits) chunk ("lux text clip" boundary num-digits digits) remaining ("lux text clip" 0 boundary digits)] (list& chunk (segment-digits chunk-size remaining))))))) @@ -323,15 +323,15 @@ (template [<from> <from-translator> <to> <to-translator> <base-bits>] [(def: (<from> on-left? input) (-> Bit Text Text) - (let [max-num-chars (n// <base-bits> 64) + (let [max-num-chars (//nat./ <base-bits> 64) input-size ("lux text size" input) - zero-padding (let [num-digits-that-need-padding (n/% <base-bits> input-size)] - (if (n/= 0 num-digits-that-need-padding) + zero-padding (let [num-digits-that-need-padding (//nat.% <base-bits> input-size)] + (if (//nat.= 0 num-digits-that-need-padding) "" - (loop [zeroes-left (n/- num-digits-that-need-padding - <base-bits>) + (loop [zeroes-left (//nat.- num-digits-that-need-padding + <base-bits>) output ""] - (if (n/= 0 zeroes-left) + (if (//nat.= 0 zeroes-left) output (recur (dec zeroes-left) ("lux text concat" "0" output)))))) @@ -448,7 +448,7 @@ sign-bit (if (..= -1.0 (..signum input)) 1 0) - exponent-bits (|> exponent ..int .nat (n/+ double-bias) (//i64.and exponent-mask)) + exponent-bits (|> exponent ..int .nat (//nat.+ double-bias) (//i64.and exponent-mask)) mantissa-bits (|> mantissa ..int .nat)] ($_ //i64.or (//i64.left-shift 63 sign-bit) @@ -464,7 +464,7 @@ [mantissa mantissa-mask mantissa-size 0] [exponent exponent-mask exponent-size mantissa-size] - [sign sign-mask 1 (n/+ exponent-size mantissa-size)] + [sign sign-mask 1 (//nat.+ exponent-size mantissa-size)] ) (def: #export (from-bits input) @@ -472,15 +472,15 @@ (let [S (sign input) E (exponent input) M (mantissa input)] - (cond (n/= ..special-exponent-bits E) - (if (n/= 0 M) - (if (n/= 0 S) + (cond (//nat.= ..special-exponent-bits E) + (if (//nat.= 0 M) + (if (//nat.= 0 S) ..positive-infinity ..negative-infinity) ..not-a-number) - (and (n/= 0 E) (n/= 0 M)) - (if (n/= 0 S) + (and (//nat.= 0 E) (//nat.= 0 M)) + (if (//nat.= 0 S) +0.0 (..* -1.0 +0.0)) @@ -488,12 +488,12 @@ (let [normalized (|> M (//i64.set mantissa-size) .int //int.frac (../ (math.pow +52.0 +2.0))) - power (math.pow (|> E (n/- double-bias) + power (math.pow (|> E (//nat.- double-bias) .int //int.frac) +2.0) shifted (..* power normalized)] - (if (n/= 0 S) + (if (//nat.= 0 S) shifted (..* -1.0 shifted)))))) diff --git a/stdlib/source/lux/data/number/i64.lux b/stdlib/source/lux/data/number/i64.lux index 2b736b005..f8417cfb0 100644 --- a/stdlib/source/lux/data/number/i64.lux +++ b/stdlib/source/lux/data/number/i64.lux @@ -2,7 +2,10 @@ [lux (#- and or not) [abstract [equivalence (#+ Equivalence)] - [monoid (#+ Monoid)]]]) + [monoid (#+ Monoid)]] + [data + [number + ["n" nat]]]]) (def: #export bits-per-byte 8) @@ -10,7 +13,7 @@ (def: #export width Nat - (n/* bits-per-byte + (n.* bits-per-byte bytes-per-i64)) (template [<parameter-type> <name> <op> <doc>] @@ -37,21 +40,21 @@ (def: #export (mask bits) (-> Nat Mask) - (|> 1 .i64 (..left-shift (n/% ..width bits)) .dec)) + (|> 1 .i64 (..left-shift (n.% ..width bits)) .dec)) (def: #export sign Mask (|> 1 .i64 (..left-shift 63))) (def: (add-shift shift value) (-> Nat Nat Nat) - (|> value (logic-right-shift shift) (n/+ value))) + (|> value (logic-right-shift shift) (n.+ value))) (def: #export (count subject) {#.doc "Count the number of 1s in a bit-map."} (-> (I64 Any) Nat) - (let [count' (n/- (|> subject (logic-right-shift 1) (..and 6148914691236517205) i64) + (let [count' (n.- (|> subject (logic-right-shift 1) (..and 6148914691236517205) i64) (i64 subject))] (|> count' - (logic-right-shift 2) (..and 3689348814741910323) (n/+ (..and 3689348814741910323 count')) + (logic-right-shift 2) (..and 3689348814741910323) (n.+ (..and 3689348814741910323 count')) (add-shift 4) (..and 1085102592571150095) (add-shift 8) (add-shift 16) @@ -79,12 +82,12 @@ (def: #export (set? idx input) (-> Nat (I64 Any) Bit) - (|> input (:coerce I64) (..and (flag idx)) (n/= 0) .not)) + (|> input (:coerce I64) (..and (flag idx)) (n.= 0) .not)) (template [<name> <main> <comp>] [(def: #export (<name> distance input) (All [s] (-> Nat (I64 s) (I64 s))) - (let [backwards-distance (n/- (n/% width distance) width)] + (let [backwards-distance (n.- (n.% width distance) width)] (|> input (<comp> backwards-distance) (..or (<main> distance input)))))] @@ -124,10 +127,10 @@ (def: #export (sub width) (Ex [size] (-> Nat (Maybe (Sub size)))) - (if (.and (n/> 0 width) - (n/< ..width width)) + (if (.and (n.> 0 width) + (n.< ..width width)) (let [top (dec width) - shift (n/- width ..width) + shift (n.- width ..width) sign (: Mask (|> 1 .i64 (..left-shift top))) number (..mask (dec width))] (#.Some {#narrow (function (narrow value) diff --git a/stdlib/source/lux/data/number/int.lux b/stdlib/source/lux/data/number/int.lux index fa8dee78a..67f2c8177 100644 --- a/stdlib/source/lux/data/number/int.lux +++ b/stdlib/source/lux/data/number/int.lux @@ -13,8 +13,8 @@ [data [text (#+ Char)] ["." maybe]]] - [// - ["." nat]]) + ["." // #_ + ["#." nat]]) (def: #export (= reference sample) {#.doc "Int(eger) equivalence."} @@ -100,7 +100,7 @@ (def: #export even? (-> Int Bit) - (|>> (..% +2) (..= +0))) + (|>> (..% +2) ("lux i64 =" +0))) (def: #export odd? (-> Int Bit) @@ -178,7 +178,7 @@ (-> Nat Text Int Int (-> Char (Maybe Nat)) Text (Try Int)) (loop [idx 1 output +0] - (if (n/< input-size idx) + (if (//nat.< input-size idx) (case (<to-value> ("lux text char" idx repr)) #.None (#try.Failure <error>) @@ -205,7 +205,7 @@ (def: (decode repr) (let [input-size ("lux text size" repr)] - (if (n/> 1 input-size) + (if (//nat.> 1 input-size) (case (sign?? repr) (#.Some sign) (int-decode-loop input-size repr sign <base> <to-value> <error>) @@ -214,10 +214,10 @@ (#try.Failure <error>)) (#try.Failure <error>)))))] - [binary +2 nat.binary-character nat.binary-value "Invalid binary syntax for Int: "] - [octal +8 nat.octal-character nat.octal-value "Invalid octal syntax for Int: "] - [decimal +10 nat.decimal-character nat.decimal-value "Invalid syntax for Int: "] - [hex +16 nat.hexadecimal-character nat.hexadecimal-value "Invalid hexadecimal syntax for Int: "] + [binary +2 //nat.binary-character //nat.binary-value "Invalid binary syntax for Int: "] + [octal +8 //nat.octal-character //nat.octal-value "Invalid octal syntax for Int: "] + [decimal +10 //nat.decimal-character //nat.decimal-value "Invalid syntax for Int: "] + [hex +16 //nat.hexadecimal-character //nat.hexadecimal-value "Invalid hexadecimal syntax for Int: "] ) (structure: #export hash (Hash Int) diff --git a/stdlib/source/lux/data/number/nat.lux b/stdlib/source/lux/data/number/nat.lux index b86826fdd..4066d7b2f 100644 --- a/stdlib/source/lux/data/number/nat.lux +++ b/stdlib/source/lux/data/number/nat.lux @@ -12,29 +12,147 @@ ["." function] ["." try (#+ Try)]] [data - ["." maybe] - ["." text (#+ Char)]]]) + ["." maybe]]]) -(def: #export + (-> Nat Nat Nat) n/+) +(template [<extension> <output> <name> <documentation>] + [(def: #export (<name> parameter subject) + {#.doc <documentation>} + (-> Nat Nat <output>) + (<extension> parameter subject))] -(def: #export - (-> Nat Nat Nat) n/-) + ["lux i64 =" Bit = "Nat(ural) equivalence."] + ["lux i64 +" Nat + "Nat(ural) addition."] + ["lux i64 -" Nat - "Nat(ural) substraction."] + ) + +(def: high + (-> (I64 Any) I64) + (|>> ("lux i64 logical-right-shift" 32))) + +(def: low + (-> (I64 Any) I64) + (let [mask (|> 1 ("lux i64 left-shift" 32) ("lux i64 -" 1))] + (|>> ("lux i64 and" mask)))) + +(def: #export (< reference sample) + {#.doc "Nat(ural) less-than."} + (-> Nat Nat Bit) + (let [referenceH (..high reference) + sampleH (..high sample)] + (if ("lux i64 <" referenceH sampleH) + #1 + (if ("lux i64 =" referenceH sampleH) + ("lux i64 <" + (..low reference) + (..low sample)) + #0)))) + +(def: #export (<= reference sample) + {#.doc "Nat(ural) less-than-equal."} + (-> Nat Nat Bit) + (if (..< reference sample) + #1 + ("lux i64 =" reference sample))) -(def: #export * (-> Nat Nat Nat) n/*) +(def: #export (> reference sample) + {#.doc "Nat(ural) greater-than."} + (-> Nat Nat Bit) + (..< sample reference)) -(def: #export / (-> Nat Nat Nat) n//) +(def: #export (>= reference sample) + {#.doc "Nat(ural) greater-than-equal."} + (-> Nat Nat Bit) + (if (..< sample reference) + #1 + ("lux i64 =" reference sample))) + +(template [<name> <test> <doc>] + [(def: #export (<name> left right) + {#.doc <doc>} + (-> Nat Nat Nat) + (if (<test> right left) + left + right))] + + [min ..< "Nat(ural) minimum."] + [max ..> "Nat(ural) maximum."] + ) + +(def: #export (* parameter subject) + {#.doc "Nat(ural) multiplication."} + (-> Nat Nat Nat) + ("lux coerce" Nat + ("lux i64 *" + ("lux coerce" Int parameter) + ("lux coerce" Int subject)))) -(def: #export % (-> Nat Nat Nat) n/%) +(def: #export (/ parameter subject) + {#.doc "Nat(ural) division."} + (-> Nat Nat Nat) + (if ("lux i64 <" +0 ("lux coerce" Int parameter)) + (if (..< parameter subject) + 0 + 1) + (let [quotient (|> subject + ("lux i64 logical-right-shift" 1) + ("lux i64 /" ("lux coerce" Int parameter)) + ("lux i64 left-shift" 1)) + flat ("lux i64 *" + ("lux coerce" Int parameter) + ("lux coerce" Int quotient)) + remainder ("lux i64 -" flat subject)] + (if (..< parameter remainder) + quotient + ("lux i64 +" 1 quotient))))) -(def: #export (/% param subject) +(def: #export (/% parameter subject) + {#.doc "Nat(ural) [division remainder]."} (-> Nat Nat [Nat Nat]) - [(../ param subject) - (..% param subject)]) + (let [div (../ parameter subject) + flat ("lux i64 *" + ("lux coerce" Int parameter) + ("lux coerce" Int div))] + [div ("lux i64 -" flat subject)])) + +(def: #export (% parameter subject) + {#.doc "Nat(ural) remainder."} + (-> Nat Nat Nat) + (let [flat ("lux i64 *" + ("lux coerce" Int parameter) + ("lux coerce" Int (../ parameter subject)))] + ("lux i64 -" flat subject))) -(def: #export (mod param subject) +(def: #export (mod parameter subject) (-> Nat Nat Nat) - (let [exact (|> subject (../ param) (..* param))] + (let [exact (|> subject (../ parameter) (..* parameter))] (|> subject (..- exact)))) +(def: #export (gcd a b) + {#.doc "Greatest Common Divisor."} + (-> Nat Nat Nat) + (case b + 0 a + _ (gcd b (..mod b a)))) + +(def: #export (lcm a b) + {#.doc "Least Common Multiple."} + (-> Nat Nat Nat) + (case [a b] + (^or [_ 0] [0 _]) + 0 + + _ + (|> a (../ (..gcd a b)) (..* b)) + )) + +(def: #export even? + (-> Nat Bit) + (|>> (..% 2) ("lux i64 =" 0))) + +(def: #export odd? + (-> Nat Bit) + (|>> ..even? not)) + (def: #export frac (-> Nat Frac) (|>> .int "lux i64 f64")) @@ -42,13 +160,13 @@ (structure: #export equivalence (Equivalence Nat) - (def: = n/=)) + (def: = ..=)) (structure: #export order (Order Nat) (def: &equivalence ..equivalence) - (def: < n/<)) + (def: < ..<)) (structure: #export enum (Enum Nat) @@ -73,8 +191,8 @@ [addition ..+ 0] [multiplication ..* 1] - [minimum n/min (:: ..interval top)] - [maximum n/max (:: ..interval bottom)] + [minimum ..min (:: ..interval top)] + [maximum ..max (:: ..interval bottom)] ) (def: #export (binary-character value) @@ -85,7 +203,7 @@ _ #.None)) (def: #export (binary-value digit) - (-> Char (Maybe Nat)) + (-> Nat (Maybe Nat)) (case digit (^ (char "0")) (#.Some 0) (^ (char "1")) (#.Some 1) @@ -105,7 +223,7 @@ _ #.None)) (def: #export (octal-value digit) - (-> Char (Maybe Nat)) + (-> Nat (Maybe Nat)) (case digit (^ (char "0")) (#.Some 0) (^ (char "1")) (#.Some 1) @@ -133,7 +251,7 @@ _ #.None)) (def: #export (decimal-value digit) - (-> Char (Maybe Nat)) + (-> Nat (Maybe Nat)) (case digit (^ (char "0")) (#.Some 0) (^ (char "1")) (#.Some 1) @@ -169,7 +287,7 @@ _ #.None)) (def: #export (hexadecimal-value digit) - (-> Char (Maybe Nat)) + (-> Nat (Maybe Nat)) (case digit (^ (char "0")) (#.Some 0) (^ (char "1")) (#.Some 1) @@ -205,10 +323,10 @@ (def: (decode repr) (let [input-size ("lux text size" repr)] - (if (n/> 0 input-size) + (if (..> 0 input-size) (loop [idx 0 output 0] - (if (n/< input-size idx) + (if (..< input-size idx) (case (<to-value> ("lux text char" idx repr)) #.None (#try.Failure ("lux text concat" <error> repr)) diff --git a/stdlib/source/lux/data/number/ratio.lux b/stdlib/source/lux/data/number/ratio.lux index 09d81d20d..dcca35bf9 100644 --- a/stdlib/source/lux/data/number/ratio.lux +++ b/stdlib/source/lux/data/number/ratio.lux @@ -16,7 +16,7 @@ ["." product] ["." maybe] [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] ["." text ("#@." monoid)]] ["." math] ["." macro @@ -29,22 +29,22 @@ (def: (equalize parameter subject) (-> Ratio Ratio [Nat Nat]) - [(n/* (get@ #denominator subject) + [(n.* (get@ #denominator subject) (get@ #numerator parameter)) - (n/* (get@ #denominator parameter) + (n.* (get@ #denominator parameter) (get@ #numerator subject))]) (def: (normalize (^slots [#numerator #denominator])) (-> Ratio Ratio) - (let [common (math.n/gcd numerator denominator)] - {#numerator (n// common numerator) - #denominator (n// common denominator)})) + (let [common (n.gcd numerator denominator)] + {#numerator (n./ common numerator) + #denominator (n./ common denominator)})) (structure: #export equivalence (Equivalence Ratio) (def: (= parameter subject) - (and (n/= (get@ #numerator parameter) + (and (n.= (get@ #numerator parameter) (get@ #numerator subject)) - (n/= (get@ #denominator parameter) + (n.= (get@ #denominator parameter) (get@ #denominator subject))))) (structure: #export order (Order Ratio) @@ -52,28 +52,28 @@ (def: (< parameter subject) (let [[parameter' subject'] (..equalize parameter subject)] - (n/< parameter' subject'))) + (n.< parameter' subject'))) ) (def: #export (+ parameter subject) (-> Ratio Ratio Ratio) (let [[parameter' subject'] (..equalize parameter subject)] - (normalize [(n/+ parameter' subject') - (n/* (get@ #denominator parameter) + (normalize [(n.+ parameter' subject') + (n.* (get@ #denominator parameter) (get@ #denominator subject))]))) (def: #export (- parameter subject) (-> Ratio Ratio Ratio) (let [[parameter' subject'] (..equalize parameter subject)] - (normalize [(n/- parameter' subject') - (n/* (get@ #denominator parameter) + (normalize [(n.- parameter' subject') + (n.* (get@ #denominator parameter) (get@ #denominator subject))]))) (def: #export (* parameter subject) (-> Ratio Ratio Ratio) - (normalize [(n/* (get@ #numerator parameter) + (normalize [(n.* (get@ #numerator parameter) (get@ #numerator subject)) - (n/* (get@ #denominator parameter) + (n.* (get@ #denominator parameter) (get@ #denominator subject))])) (def: #export (/ parameter subject) @@ -84,8 +84,8 @@ (def: #export (% parameter subject) (-> Ratio Ratio Ratio) (let [[parameter' subject'] (..equalize parameter subject) - quot (n// parameter' subject')] - (..- (update@ #numerator (n/* quot) parameter) + quot (n./ parameter' subject')] + (..- (update@ #numerator (n.* quot) parameter) subject))) (def: #export (reciprocal (^slots [#numerator #denominator])) @@ -97,14 +97,14 @@ (structure: #export codec (Codec Text Ratio) (def: (encode (^slots [#numerator #denominator])) - ($_ text@compose (nat@encode numerator) ..separator (nat@encode denominator))) + ($_ text@compose (n@encode numerator) ..separator (n@encode denominator))) (def: (decode input) (case (text.split-with ..separator input) (#.Some [num denom]) (do try.monad - [numerator (nat@decode num) - denominator (nat@decode denom)] + [numerator (n@decode num) + denominator (n@decode denom)] (wrap (normalize {#numerator numerator #denominator denominator}))) diff --git a/stdlib/source/lux/data/number/rev.lux b/stdlib/source/lux/data/number/rev.lux index 0a9ed4b94..b12a6f314 100644 --- a/stdlib/source/lux/data/number/rev.lux +++ b/stdlib/source/lux/data/number/rev.lux @@ -28,14 +28,14 @@ (def: #export (< reference sample) {#.doc "Rev(olution) less-than."} (-> Rev Rev Bit) - (n/< ("lux coerce" Nat reference) - ("lux coerce" Nat sample))) + (//nat.< ("lux coerce" Nat reference) + ("lux coerce" Nat sample))) (def: #export (<= reference sample) {#.doc "Rev(olution) less-than-equal."} (-> Rev Rev Bit) - (if (n/< ("lux coerce" Nat reference) - ("lux coerce" Nat sample)) + (if (//nat.< ("lux coerce" Nat reference) + ("lux coerce" Nat sample)) #1 ("lux i64 =" reference sample))) @@ -134,7 +134,7 @@ {#.doc "Rev(olution) remainder."} (-> Rev Rev Rev) (|> (:coerce Nat subject) - (n/% (:coerce Nat param)) + (//nat.% (:coerce Nat param)) (:coerce Rev))) (def: #export (scale param subject) @@ -149,10 +149,10 @@ (-> Nat Rev) (:coerce Rev (let [[trailing-zeroes remaining] (without-trailing-zeroes 0 numerator)] - (n// remaining - ({0 (:coerce Nat -1) - _ ("lux i64 left-shift" (n/- trailing-zeroes 64) 1)} - trailing-zeroes))))) + (//nat./ remaining + ({0 (:coerce Nat -1) + _ ("lux i64 left-shift" (//nat.- trailing-zeroes 64) 1)} + trailing-zeroes))))) (def: #export (/% param subject) (-> Rev Rev [Rev Rev]) @@ -206,14 +206,14 @@ (structure: #export <struct> (Codec Text Rev) (def: (encode value) (let [raw-output (:: <codec> encode (:coerce Nat value)) - max-num-chars (n/+ (n// <char-bit-size> 64) - (case (n/% <char-bit-size> 64) - 0 0 - _ 1)) + max-num-chars (//nat.+ (//nat./ <char-bit-size> 64) + (case (//nat.% <char-bit-size> 64) + 0 0 + _ 1)) raw-size ("lux text size" raw-output) - zero-padding (loop [zeroes-left (n/- raw-size max-num-chars) + zero-padding (loop [zeroes-left (//nat.- raw-size max-num-chars) output ""] - (if (n/= 0 zeroes-left) + (if (//nat.= 0 zeroes-left) output (recur (dec zeroes-left) ("lux text concat" "0" output))))] @@ -223,7 +223,7 @@ (def: (decode repr) (let [repr-size ("lux text size" repr)] - (if (n/> 1 repr-size) + (if (//nat.> 1 repr-size) (case ("lux text char" 0 repr) (^ (char ".")) (case (:: <codec> decode (de-prefix repr)) @@ -277,11 +277,11 @@ output output] (if (//int.>= +0 (.int idx)) (let [raw (|> (digits-get idx output) - (n/* 5) - (n/+ carry))] + (//nat.* 5) + (//nat.+ carry))] (recur (dec idx) - (n// 10 raw) - (digits-put idx (n/% 10 raw) output))) + (//nat./ 10 raw) + (digits-put idx (//nat.% 10 raw) output))) output))) (def: (digits-power power) @@ -301,7 +301,7 @@ output ""] (if (//int.>= +0 (.int idx)) (let [digit (digits-get idx digits)] - (if (and (n/= 0 digit) + (if (and (//nat.= 0 digit) all-zeroes?) (recur (dec idx) #1 output) (recur (dec idx) @@ -319,22 +319,22 @@ carry 0 output (make-digits [])] (if (//int.>= +0 (.int idx)) - (let [raw ($_ n/+ + (let [raw ($_ //nat.+ carry (digits-get idx param) (digits-get idx subject))] (recur (dec idx) - (n// 10 raw) - (digits-put idx (n/% 10 raw) output))) + (//nat./ 10 raw) + (digits-put idx (//nat.% 10 raw) output))) output))) (def: (text-to-digits input) (-> Text (Maybe Digits)) (let [length ("lux text size" input)] - (if (n/<= //i64.width length) + (if (//nat.<= //i64.width length) (loop [idx 0 output (make-digits [])] - (if (n/< length idx) + (if (//nat.< length idx) (case ("lux text index" 0 ("lux text clip" idx (inc idx) input) "0123456789") #.None #.None @@ -348,21 +348,21 @@ (def: (digits-lt param subject) (-> Digits Digits Bit) (loop [idx 0] - (and (n/< //i64.width idx) + (and (//nat.< //i64.width idx) (let [pd (digits-get idx param) sd (digits-get idx subject)] - (if (n/= pd sd) + (if (//nat.= pd sd) (recur (inc idx)) - (n/< pd sd)))))) + (//nat.< pd sd)))))) (def: (digits-sub-once! idx param subject) (-> Nat Nat Digits Digits) (let [sd (digits-get idx subject)] - (if (n/>= param sd) - (digits-put idx (n/- param sd) subject) + (if (//nat.>= param sd) + (digits-put idx (//nat.- param sd) subject) (let [diff (|> sd - (n/+ 10) - (n/- param))] + (//nat.+ 10) + (//nat.- param))] (|> subject (digits-put idx diff) (digits-sub-once! (dec idx) 1)))))) @@ -388,7 +388,7 @@ digits (make-digits [])] (if (//int.>= +0 (.int idx)) (if (//i64.set? idx input) - (let [digits' (digits-add (digits-power (n/- idx last-idx)) + (let [digits' (digits-add (digits-power (//nat.- idx last-idx)) digits)] (recur (dec idx) digits')) @@ -404,22 +404,22 @@ _ #0) - within-limits? (n/<= (inc //i64.width) - ("lux text size" input))] + within-limits? (//nat.<= (inc //i64.width) + ("lux text size" input))] (if (and dotted? within-limits?) (case (text-to-digits (de-prefix input)) (#.Some digits) (loop [digits digits idx 0 output 0] - (if (n/< //i64.width idx) + (if (//nat.< //i64.width idx) (let [power (digits-power idx)] (if (digits-lt power digits) ## Skip power (recur digits (inc idx) output) (recur (digits-sub! power digits) (inc idx) - (//i64.set (n/- idx (dec //i64.width)) output)))) + (//i64.set (//nat.- idx (dec //i64.width)) output)))) (#try.Success (:coerce Rev output)))) #.None diff --git a/stdlib/source/lux/data/text.lux b/stdlib/source/lux/data/text.lux index 8a4b8a02a..dce88022b 100644 --- a/stdlib/source/lux/data/text.lux +++ b/stdlib/source/lux/data/text.lux @@ -11,7 +11,8 @@ [data ["." maybe] [number - ["." i64]] + ["." i64] + ["n" nat]] [collection ["." list ("#@." fold)]]]]) @@ -44,7 +45,7 @@ (def: #export (nth idx input) (-> Nat Text (Maybe Char)) - (if (n/< ("lux text size" input) idx) + (if (n.< ("lux text size" input) idx) (#.Some ("lux text char" idx input)) #.None)) @@ -96,8 +97,8 @@ (-> Text Text Bit) (case (last-index-of postfix x) (#.Some n) - (n/= (size x) - (n/+ (size postfix) n)) + (n.= (size x) + (n.+ (size postfix) n)) _ false)) @@ -113,15 +114,15 @@ (def: #export (clip from to input) (-> Nat Nat Text (Maybe Text)) - (if (and (n/<= to from) - (n/<= ("lux text size" input) to)) + (if (and (n.<= to from) + (n.<= ("lux text size" input) to)) (#.Some ("lux text clip" from to input)) #.None)) (def: #export (clip' from input) (-> Nat Text (Maybe Text)) (let [size ("lux text size" input)] - (if (n/<= size from) + (if (n.<= size from) (#.Some ("lux text clip" from size input)) #.None))) @@ -206,12 +207,12 @@ (let [length ("lux text size" input)] (loop [idx 0 hash 0] - (if (n/< length idx) + (if (n.< length idx) (recur (inc idx) (|> hash (i64.left-shift 5) - (n/- hash) - (n/+ ("lux text char" idx input)))) + (n.- hash) + (n.+ ("lux text char" idx input)))) hash))))))) (def: #export concat diff --git a/stdlib/source/lux/data/text/buffer.lux b/stdlib/source/lux/data/text/buffer.lux index 89aaebece..e14013a29 100644 --- a/stdlib/source/lux/data/text/buffer.lux +++ b/stdlib/source/lux/data/text/buffer.lux @@ -2,6 +2,8 @@ [lux #* [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -47,7 +49,7 @@ (exec (Appendable::append (:coerce CharSequence chunk) builder) builder)))] - (:abstraction [(n/+ (//.size chunk) capacity) + (:abstraction [(n.+ (//.size chunk) capacity) (|>> transform (append! chunk))]))} ## default (|> buffer :representation (row.add chunk) :abstraction))) @@ -58,7 +60,7 @@ (|> buffer :representation product.left)} ## default (row;fold (function (_ chunk total) - (n/+ (//.size chunk) total)) + (n.+ (//.size chunk) total)) 0 (:representation buffer)))) diff --git a/stdlib/source/lux/data/text/regex.lux b/stdlib/source/lux/data/text/regex.lux index addd07532..1063fdb71 100644 --- a/stdlib/source/lux/data/text/regex.lux +++ b/stdlib/source/lux/data/text/regex.lux @@ -11,7 +11,7 @@ ["." product] ["." maybe] [number (#+ hex) - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] [collection ["." list ("#@." fold monad)]]] ["." macro (#+ with-gensyms) @@ -186,14 +186,14 @@ (def: number^ (Parser Nat) (|> (l.many l.decimal) - (p.codec nat.decimal))) + (p.codec n.decimal))) (def: re-back-reference^ (Parser Code) (p.either (do p.monad [_ (l.this "\") id number^] - (wrap (` ((~! ..copy) (~ (code.identifier ["" (nat@encode id)])))))) + (wrap (` ((~! ..copy) (~ (code.identifier ["" (n@encode id)])))))) (do p.monad [_ (l.this "\k<") captured-name name-part^ @@ -290,8 +290,8 @@ [idx (code.identifier ["" _name])] #.None - [(inc idx) (code.identifier ["" (nat@encode idx)])]) - access (if (n/> 0 num-captures) + [(inc idx) (code.identifier ["" (n@encode idx)])]) + access (if (n.> 0 num-captures) (` ((~! product.left) (~ name!))) name!)] [idx! @@ -349,7 +349,7 @@ (def: (prep-alternative [num-captures alt]) (-> [Nat Code] Code) - (if (n/> 0 num-captures) + (if (n.> 0 num-captures) alt (` ((~! unflatten^) (~ alt))))) @@ -364,7 +364,7 @@ tail (p.some (p.after (l.this "|") sub^))] (if (list.empty? tail) (wrap head) - (wrap [(list@fold n/max (product.left head) (list@map product.left tail)) + (wrap [(list@fold n.max (product.left head) (list@map product.left tail)) (` ($_ ((~ (if capturing? (` (~! |||^)) (` (~! |||_^))))) diff --git a/stdlib/source/lux/data/text/unicode.lux b/stdlib/source/lux/data/text/unicode.lux index a6fd13ebc..cbead2be1 100644 --- a/stdlib/source/lux/data/text/unicode.lux +++ b/stdlib/source/lux/data/text/unicode.lux @@ -5,7 +5,7 @@ [monoid (#+ Monoid)]] [data [number (#+ hex) - ["." nat ("#;." interval)]] + ["n" nat ("#@." interval)]] [collection ["." list] [tree @@ -18,7 +18,7 @@ {} (Interval Char) - (def: empty (:abstraction (interval.between nat.enum nat;top nat;bottom))) + (def: empty (:abstraction (interval.between n.enum n@top n@bottom))) (structure: monoid (Monoid Segment) (def: identity ..empty) @@ -26,15 +26,15 @@ (let [left (:representation left) right (:representation right)] (:abstraction - (interval.between nat.enum - (n/min (:: left bottom) + (interval.between n.enum + (n.min (:: left bottom) (:: right bottom)) - (n/max (:: left top) + (n.max (:: left top) (:: right top))))))) (def: #export (segment start end) (-> Char Char Segment) - (:abstraction (interval.between nat.enum (n/min start end) (n/max start end)))) + (:abstraction (interval.between n.enum (n.min start end) (n.max start end)))) (template [<name> <slot>] [(def: #export <name> @@ -49,7 +49,7 @@ (-> Segment Nat) (let [start (get@ #interval.bottom (:representation segment)) end (get@ #interval.top (:representation segment))] - (|> end (n/- start) inc))) + (|> end (n.- start) inc))) (def: #export (within? segment char) (All [a] (-> Segment Char Bit)) @@ -208,8 +208,8 @@ (..singleton (:: ..monoid compose left right)) _ - (let [[sides extra] (n//% 2 (list.size segments)) - [left+ right+] (list.split (n/+ sides extra) segments)] + (let [[sides extra] (n./% 2 (list.size segments)) + [left+ right+] (list.split (n.+ sides extra) segments)] (finger.branch (set left+) (set right+))))) diff --git a/stdlib/source/lux/macro.lux b/stdlib/source/lux/macro.lux index c13a161ea..4843b1fc2 100644 --- a/stdlib/source/lux/macro.lux +++ b/stdlib/source/lux/macro.lux @@ -11,7 +11,7 @@ ["." name ("#@." codec equivalence)] ["." maybe] [number - ["." nat ("#@." decimal)] + ["n" nat] ["i" int]] ["." text ("#@." monoid equivalence)] [collection @@ -371,7 +371,7 @@ (#try.Success [(update@ #.seed inc compiler) (|> compiler (get@ #.seed) - (:: nat.decimal encode) + (:: n.decimal encode) ($_ text@compose "__gensym__" prefix) [""] code.identifier)]))) @@ -449,7 +449,7 @@ #.None (#.Cons [var bound] bindings') - (if (n/= idx var) + (if (n.= idx var) bound (find-type-var idx bindings')))) diff --git a/stdlib/source/lux/macro/poly.lux b/stdlib/source/lux/macro/poly.lux index 825849cce..536376f83 100644 --- a/stdlib/source/lux/macro/poly.lux +++ b/stdlib/source/lux/macro/poly.lux @@ -10,6 +10,8 @@ ["." product] ["." maybe] ["." text] + [number + ["n" nat]] [collection ["." list ("#@." fold functor)] ["." dictionary]]] @@ -93,13 +95,13 @@ (#.Parameter idx) (let [idx (<type>.adjusted-idx env idx)] - (if (n/= 0 idx) + (if (n.= 0 idx) (|> (dictionary.get idx env) maybe.assume product.left (to-code env)) (` (.$ (~ (code.nat (dec idx))))))) (#.Apply (#.Named ["lux" "Nothing"] _) (#.Parameter idx)) (let [idx (<type>.adjusted-idx env idx)] - (if (n/= 0 idx) + (if (n.= 0 idx) (|> (dictionary.get idx env) maybe.assume product.left (to-code env)) (undefined))) diff --git a/stdlib/source/lux/macro/poly/functor.lux b/stdlib/source/lux/macro/poly/functor.lux index e7a7c8b4a..5ccb65463 100644 --- a/stdlib/source/lux/macro/poly/functor.lux +++ b/stdlib/source/lux/macro/poly/functor.lux @@ -9,6 +9,8 @@ ["s" code (#+ Parser)]]] [data ["." product] + [number + ["n" nat]] ["." text ["%" format (#+ format)]] [collection @@ -32,7 +34,7 @@ #let [num-vars (list.size varsC)] #let [@Functor (: (-> Type Code) (function (_ unwrappedT) - (if (n/= 1 num-vars) + (if (n.= 1 num-vars) (` ((~! functor.Functor) (~ (poly.to-code *env* unwrappedT)))) (let [paramsC (|> num-vars dec list.indices (list;map (|>> %.nat code.local-identifier)))] (` (All [(~+ paramsC)] @@ -42,7 +44,7 @@ ($_ p.either ## Type-var (do p.monad - [#let [varI (|> num-vars (n/* 2) dec)] + [#let [varI (|> num-vars (n.* 2) dec)] _ (<type>.parameter! varI)] (wrap (` ((~ funcC) (~ valueC))))) ## Variants diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux index 44fd4b628..a621f0d20 100644 --- a/stdlib/source/lux/macro/poly/json.lux +++ b/stdlib/source/lux/macro/poly/json.lux @@ -18,7 +18,7 @@ ["." product] [number ["." i64] - ["." nat ("#@." decimal)] + ["n" nat ("#@." decimal)] ["." int] ["." frac ("#@." decimal)]] ["." text ("#@." equivalence) @@ -68,7 +68,7 @@ (do p.monad [high </>.number low </>.number]) - (wrap (n/+ (|> high frac.int .nat (i64.left-shift 32)) + (wrap (n.+ (|> high frac.int .nat (i64.left-shift 32)) (|> low frac.int .nat)))))) (structure: int-codec (codec.Codec JSON Int) @@ -175,7 +175,7 @@ #let [g!_ (code.local-identifier "_______") g!members (|> (list.size g!encoders) list.indices - (list@map (|>> nat@encode code.local-identifier)))]] + (list@map (|>> n@encode code.local-identifier)))]] (wrap (` (: (~ (@JSON//encode inputT)) (function ((~ g!_) [(~+ g!members)]) ((~! /.json) [(~+ (list@map (function (_ [g!member g!encode]) diff --git a/stdlib/source/lux/math.lux b/stdlib/source/lux/math.lux index e27e09f86..b030746a0 100644 --- a/stdlib/source/lux/math.lux +++ b/stdlib/source/lux/math.lux @@ -3,7 +3,7 @@ ["@" target] [data [number - ["." nat] + ["n" nat] ["i" int]]]]) (template [<name> <value> <doc>] @@ -138,9 +138,9 @@ (-> Nat Nat) (loop [acc 1 n n] - (if (n/<= 1 n) + (if (n.<= 1 n) acc - (recur (n/* n acc) (dec n))))) + (recur (n.* n acc) (dec n))))) (def: #export (hypotenuse catA catB) (-> Frac Frac Frac) @@ -148,28 +148,6 @@ (pow +2.0 catA) (pow +2.0 catB)))) -(template [<type> <mod> <gcd> <lcm> <zero> <*> </> <->] - [(def: #export (<gcd> a b) - {#.doc "Greatest Common Divisor."} - (-> <type> <type> <type>) - (case b - <zero> a - _ (<gcd> b (<mod> b a)))) - - (def: #export (<lcm> a b) - {#.doc "Least Common Multiple."} - (-> <type> <type> <type>) - (case [a b] - (^or [_ <zero>] [<zero> _]) - <zero> - - _ - (|> a (</> (<gcd> a b)) (<*> b)) - ))] - - [Nat nat.mod n/gcd n/lcm 0 n/* n// n/-] - ) - ## Hyperbolic functions ## https://en.wikipedia.org/wiki/Hyperbolic_function#Definitions (template [<name> <comp> <inverse>] diff --git a/stdlib/source/lux/math/infix.lux b/stdlib/source/lux/math/infix.lux index b31d77fd8..20d1e061a 100644 --- a/stdlib/source/lux/math/infix.lux +++ b/stdlib/source/lux/math/infix.lux @@ -8,6 +8,7 @@ [data ["." product] [number + ["n" nat] ["i" int]] [collection ["." list ("#;." fold)]]] @@ -82,9 +83,9 @@ (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]]) - (infix [#and x n/< y n/< z]) - (infix [(n/* 3 9) gcd 450]) + (infix [[x n.< y] and [y n.< z]]) + (infix [#and x n.< y n.< z]) + (infix [(n.* 3 9) gcd 450]) "The rules for infix syntax are simple." "If you want your binary function to work well with it." diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index bda49fab0..90e746ca4 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -10,6 +10,7 @@ ["." maybe] [number (#+ hex) ["." i64] + ["n" nat] ["i" int] ["r" ratio] ["c" complex] @@ -89,7 +90,7 @@ (Random Bit) (function (_ prng) (let [[prng output] (prng [])] - [prng (|> output (i64.and 1) (n/= 1))]))) + [prng (|> output (i64.and 1) (n.= 1))]))) (def: #export i64 (Random I64) @@ -130,7 +131,7 @@ start (unicode.start summary) size (unicode.size summary) in-range (: (-> Char Char) - (|>> (n/% size) (n/+ start)))] + (|>> (n.% size) (n.+ start)))] (|> nat (:: ..monad map in-range) (..filter (function (_ char) @@ -140,7 +141,7 @@ (def: #export (text char-gen size) (-> (Random Char) Nat (Random Text)) - (if (n/= 0 size) + (if (n.= 0 size) (:: ..monad wrap "") (do ..monad [x char-gen @@ -221,7 +222,7 @@ (template [<name> <type> <zero> <plus>] [(def: #export (<name> size value-gen) (All [a] (-> Nat (Random a) (Random (<type> a)))) - (if (n/> 0 size) + (if (n.> 0 size) (do ..monad [x value-gen xs (<name> (dec size) value-gen)] @@ -246,21 +247,21 @@ (def: #export (set Hash<a> size value-gen) (All [a] (-> (Hash a) Nat (Random a) (Random (Set a)))) - (if (n/> 0 size) + (if (n.> 0 size) (do ..monad [xs (set Hash<a> (dec size) value-gen)] (loop [_ []] (do @ [x value-gen #let [xs+ (set.add x xs)]] - (if (n/= size (set.size xs+)) + (if (n.= size (set.size xs+)) (wrap xs+) (recur []))))) (:: ..monad wrap (set.new Hash<a>)))) (def: #export (dictionary Hash<a> size key-gen value-gen) (All [k v] (-> (Hash k) Nat (Random k) (Random v) (Random (Dictionary k v)))) - (if (n/> 0 size) + (if (n.> 0 size) (do ..monad [kv (dictionary Hash<a> (dec size) key-gen value-gen)] (loop [_ []] @@ -268,7 +269,7 @@ [k key-gen v value-gen #let [kv+ (dictionary.put k v kv)]] - (if (n/= size (dictionary.size kv+)) + (if (n.= size (dictionary.size kv+)) (wrap kv+) (recur []))))) (:: ..monad wrap (dictionary.new Hash<a>)))) @@ -284,7 +285,7 @@ "For more information, please see: http://www.pcg-random.org/")} (-> [(I64 Any) (I64 Any)] PRNG) (function (_ _) - [(|> seed .nat (n/* ..pcg-32-magic) ("lux i64 +" increase) [increase] pcg-32) + [(|> seed .nat (n.* ..pcg-32-magic) ("lux i64 +" increase) [increase] pcg-32) (let [rot (|> seed .i64 (i64.logic-right-shift 59))] (|> seed (i64.logic-right-shift 18) diff --git a/stdlib/source/lux/target/jvm/attribute.lux b/stdlib/source/lux/target/jvm/attribute.lux index fef8598e8..236ecf608 100644 --- a/stdlib/source/lux/target/jvm/attribute.lux +++ b/stdlib/source/lux/target/jvm/attribute.lux @@ -9,6 +9,8 @@ ["." exception (#+ exception:)]] [data ["." product] + [number + ["n" nat]] [format [".F" binary (#+ Writer) ("#@." monoid)]]]] ["." // #_ @@ -43,7 +45,7 @@ (let [[nameS nameT] (//index.writer name) [lengthS lengthT] (//unsigned.u4-writer length) [infoS infoT] (writer info)] - [($_ n/+ nameS lengthS infoS) + [($_ n.+ nameS lengthS infoS) (|>> nameT lengthT infoT)]))) (with-expansions [<Code> (as-is (/code.Code Attribute))] @@ -64,7 +66,7 @@ (info-equivalence (/code.equivalence equivalence)))))) (def: fixed-attribute-length - ($_ n/+ + ($_ n.+ ## u2 attribute_name_index; //unsigned.u2-bytes ## u4 attribute_length; @@ -76,7 +78,7 @@ (case attribute (^template [<tag>] (<tag> [name length info]) - (|> length //unsigned.nat .nat (n/+ fixed-attribute-length))) + (|> length //unsigned.nat .nat (n.+ fixed-attribute-length))) ([#Constant] [#Code]))) (def: constant-name "ConstantValue") diff --git a/stdlib/source/lux/target/jvm/attribute/code.lux b/stdlib/source/lux/target/jvm/attribute/code.lux index 61c19ccfa..0bf1bec4e 100644 --- a/stdlib/source/lux/target/jvm/attribute/code.lux +++ b/stdlib/source/lux/target/jvm/attribute/code.lux @@ -5,6 +5,8 @@ ["." equivalence (#+ Equivalence)]] [data ["." binary (#+ Binary)] + [number + ["n" nat]] [format [".F" binary (#+ Writer) ("#@." monoid)]] [collection @@ -25,7 +27,7 @@ (def: #export (length length code) (All [Attribute] (-> (-> Attribute Nat) (Code Attribute) Nat)) - ($_ n/+ + ($_ n.+ ## u2 max_stack; ## u2 max_locals; ///resources.length @@ -39,14 +41,14 @@ (|> code (get@ #exception-table) row.size - (n/* /exception.length)) + (n.* /exception.length)) ## u2 attributes_count; ///unsigned.u2-bytes ## attribute_info attributes[attributes_count]; (|> code (get@ #attributes) (row@map length) - (row@fold n/+ 0)))) + (row@fold n.+ 0)))) (def: #export (equivalence attribute-equivalence) (All [attribute] diff --git a/stdlib/source/lux/target/jvm/attribute/code/exception.lux b/stdlib/source/lux/target/jvm/attribute/code/exception.lux index b291baf3e..17111c251 100644 --- a/stdlib/source/lux/target/jvm/attribute/code/exception.lux +++ b/stdlib/source/lux/target/jvm/attribute/code/exception.lux @@ -3,6 +3,8 @@ [abstract ["." equivalence (#+ Equivalence)]] [data + [number + ["n" nat]] [format [".F" binary (#+ Writer)]]]] ["." // #_ @@ -32,7 +34,7 @@ ## https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 (def: #export length Nat - ($_ n/+ + ($_ n.+ ## u2 start_pc; ////unsigned.u2-bytes ## u2 end_pc; diff --git a/stdlib/source/lux/target/jvm/constant/pool.lux b/stdlib/source/lux/target/jvm/constant/pool.lux index 6db92879c..bd8b7cb3d 100644 --- a/stdlib/source/lux/target/jvm/constant/pool.lux +++ b/stdlib/source/lux/target/jvm/constant/pool.lux @@ -11,6 +11,7 @@ [data [number ["." i32] + ["n" nat] ["." int] ["." frac]] ["." text @@ -85,10 +86,10 @@ (#.Some [index entry]) (let [index' (!raw-index index) <index>' (!raw-index <index>)] - (cond (n/< index' <index>') + (cond (n.< index' <index>') (recur (inc idx)) - (n/= index' <index>') + (n.= index' <index>') (case entry (<tag> value) [[next pool] (#try.Success value)] @@ -96,7 +97,7 @@ _ [[next pool] (exception.throw ..invalid-constant [<index> (name-of <tag>)])]) - ## (n/> index' <index>') + ## (n.> index' <index>') <failure>)) #.None diff --git a/stdlib/source/lux/target/jvm/encoding/signed.lux b/stdlib/source/lux/target/jvm/encoding/signed.lux index fb684847b..3609142a3 100644 --- a/stdlib/source/lux/target/jvm/encoding/signed.lux +++ b/stdlib/source/lux/target/jvm/encoding/signed.lux @@ -6,6 +6,7 @@ [data [number ["." i64] + ["n" nat] ["i" int]] [format [".F" binary (#+ Writer)]]] @@ -43,16 +44,16 @@ (def: #export <max> <name> - (|> <bytes> (n/* i64.bits-per-byte) dec i64.mask :abstraction)) + (|> <bytes> (n.* i64.bits-per-byte) dec i64.mask :abstraction)) (def: #export <constructor> (-> Int <name>) - (let [limit (|> <bytes> (n/* i64.bits-per-byte) i64.mask .nat)] + (let [limit (|> <bytes> (n.* i64.bits-per-byte) i64.mask .nat)] (|>> (i64.and limit) :abstraction))) (def: #export (<+> parameter subject) (-> <name> <name> <name>) - (let [limit (|> <bytes> (n/* i64.bits-per-byte) i64.mask .nat)] + (let [limit (|> <bytes> (n.* i64.bits-per-byte) i64.mask .nat)] (:abstraction (i64.and limit (i.+ (:representation parameter) diff --git a/stdlib/source/lux/target/jvm/encoding/unsigned.lux b/stdlib/source/lux/target/jvm/encoding/unsigned.lux index b0b8ff312..56885d576 100644 --- a/stdlib/source/lux/target/jvm/encoding/unsigned.lux +++ b/stdlib/source/lux/target/jvm/encoding/unsigned.lux @@ -5,7 +5,8 @@ [order (#+ Order)]] [data [number - ["." i64]] + ["." i64] + ["n" nat]] [format [".F" binary (#+ Writer)]]] [macro @@ -24,14 +25,14 @@ (structure: #export equivalence (All [brand] (Equivalence (Unsigned brand))) (def: (= reference sample) - (n/= (:representation reference) (:representation sample)))) + (n.= (:representation reference) (:representation sample)))) (structure: #export order (All [brand] (Order (Unsigned brand))) (def: &equivalence ..equivalence) (def: (< reference sample) - (n/< (:representation reference) (:representation sample)))) + (n.< (:representation reference) (:representation sample)))) (template [<bytes> <name> <size> <constructor> <max> <+>] [(with-expansions [<raw> (template.identifier [<name> "'"])] @@ -42,7 +43,7 @@ (def: #export <max> <name> - (|> <bytes> (n/* i64.bits-per-byte) i64.mask :abstraction)) + (|> <bytes> (n.* i64.bits-per-byte) i64.mask :abstraction)) (def: #export <constructor> (-> Nat <name>) @@ -52,7 +53,7 @@ (-> <name> <name> <name>) (:abstraction (i64.and (:representation <max>) - (n/+ (:representation parameter) + (n.+ (:representation parameter) (:representation subject)))))] [1 U1 u1-bytes u1 max-u1 u1/+] diff --git a/stdlib/source/lux/target/jvm/instruction.lux b/stdlib/source/lux/target/jvm/instruction.lux index ac4732e12..02057202b 100644 --- a/stdlib/source/lux/target/jvm/instruction.lux +++ b/stdlib/source/lux/target/jvm/instruction.lux @@ -13,7 +13,7 @@ [text ["%" format (#+ format)]] [number - ["." nat] + ["n" nat] ["i" int]] [collection ["." list ("#@." functor fold)] @@ -47,7 +47,7 @@ Tracker {#program-counter 0 #next-label 0 - #known-labels (dictionary.new nat.hash)}) + #known-labels (dictionary.new n.hash)}) (type: #export Partial (-> Resolver (Try Bytecode))) @@ -365,8 +365,8 @@ (def: (jump @from @to) (-> Address Address (Either Jump Big-Jump)) - (let [jump (.int (n/- @to @from)) - big? (n/> (//unsigned.nat //unsigned.max-u2) + (let [jump (.int (n.- @to @from)) + big? (n.> (//unsigned.nat //unsigned.max-u2) (.nat (i.* (if (i.>= +0 jump) +1 -1) diff --git a/stdlib/source/lux/target/jvm/instruction/bytecode.lux b/stdlib/source/lux/target/jvm/instruction/bytecode.lux index bef2628f6..8a51097b7 100644 --- a/stdlib/source/lux/target/jvm/instruction/bytecode.lux +++ b/stdlib/source/lux/target/jvm/instruction/bytecode.lux @@ -7,8 +7,9 @@ ["." try (#+ Try)] ["." exception (#+ exception:)]] [data - [number (#+ hex)] ["." binary] + [number (#+ hex) + ["n" nat]] [text ["%" format (#+ format)]] [format @@ -53,13 +54,13 @@ (def: (nullary' code) (-> Code Mutation) (function (_ [offset binary]) - [(n/+ 1 offset) + [(n.+ 1 offset) (try.assume (binary.write/8 offset code binary))])) (def: (nullary code [size mutation]) (-> Code (-> Specification Specification)) - [(n/+ 1 size) + [(n.+ 1 size) (|>> mutation ((nullary' code)))]) (template [<shift> <name> <inputT> <writer> <unwrap>] @@ -67,15 +68,15 @@ (def: (<private> code input0) (-> Code <inputT> Mutation) (function (_ [offset binary]) - [(n/+ <shift> offset) + [(n.+ <shift> offset) (try.assume (do try.monad [_ (binary.write/8 offset code binary)] - (<writer> (n/+ 1 offset) (<unwrap> input0) binary)))])) + (<writer> (n.+ 1 offset) (<unwrap> input0) binary)))])) (def: (<name> code input0 [size mutation]) (-> Code <inputT> (-> Specification Specification)) - [(n/+ <shift> size) + [(n.+ <shift> size) (|>> mutation ((<private> code input0)))]))] [2 unary/1 U1 binary.write/8 ///unsigned.nat] @@ -87,47 +88,47 @@ (def: (binary/11' code input0 input1) (-> Code U1 U1 Mutation) (function (_ [offset binary]) - [(n/+ 3 offset) + [(n.+ 3 offset) (try.assume (do try.monad [_ (binary.write/8 offset code binary) - _ (binary.write/8 (n/+ 1 offset) (///unsigned.nat input0) binary)] - (binary.write/8 (n/+ 2 offset) (///unsigned.nat input1) binary)))])) + _ (binary.write/8 (n.+ 1 offset) (///unsigned.nat input0) binary)] + (binary.write/8 (n.+ 2 offset) (///unsigned.nat input1) binary)))])) (def: (binary/11 code input0 input1 [size mutation]) (-> Code U1 U1 (-> Specification Specification)) - [(n/+ 3 size) + [(n.+ 3 size) (|>> mutation ((binary/11' code input0 input1)))]) (def: (binary/21' code input0 input1) (-> Code U2 U1 Mutation) (function (_ [offset binary]) - [(n/+ 4 offset) + [(n.+ 4 offset) (try.assume (do try.monad [_ (binary.write/8 offset code binary) - _ (binary.write/16 (n/+ 1 offset) (///unsigned.nat input0) binary)] - (binary.write/8 (n/+ 3 offset) (///unsigned.nat input1) binary)))])) + _ (binary.write/16 (n.+ 1 offset) (///unsigned.nat input0) binary)] + (binary.write/8 (n.+ 3 offset) (///unsigned.nat input1) binary)))])) (def: (binary/21 code input0 input1 [size mutation]) (-> Code U2 U1 (-> Specification Specification)) - [(n/+ 4 size) + [(n.+ 4 size) (|>> mutation ((binary/21' code input0 input1)))]) (def: (trinary/211' code input0 input1 input2) (-> Code U2 U1 U1 Mutation) (function (_ [offset binary]) - [(n/+ 5 offset) + [(n.+ 5 offset) (try.assume (do try.monad [_ (binary.write/8 offset code binary) - _ (binary.write/16 (n/+ 1 offset) (///unsigned.nat input0) binary) - _ (binary.write/8 (n/+ 3 offset) (///unsigned.nat input1) binary)] - (binary.write/8 (n/+ 4 offset) (///unsigned.nat input2) binary)))])) + _ (binary.write/16 (n.+ 1 offset) (///unsigned.nat input0) binary) + _ (binary.write/8 (n.+ 3 offset) (///unsigned.nat input1) binary)] + (binary.write/8 (n.+ 4 offset) (///unsigned.nat input2) binary)))])) (def: (trinary/211 code input0 input1 input2 [size mutation]) (-> Code U2 U1 U1 (-> Specification Specification)) - [(n/+ 5 size) + [(n.+ 5 size) (|>> mutation ((trinary/211' code input0 input1 input2)))]) (abstract: #export Primitive-Array-Type @@ -483,7 +484,7 @@ (def: identity ..nop) (def: (compose [left-size left] [right-size right]) - [(n/+ left-size right-size) + [(n.+ left-size right-size) (function (_ input) (do try.monad [temp (left input)] diff --git a/stdlib/source/lux/target/jvm/instruction/condition.lux b/stdlib/source/lux/target/jvm/instruction/condition.lux index 04bb8c60b..82c709800 100644 --- a/stdlib/source/lux/target/jvm/instruction/condition.lux +++ b/stdlib/source/lux/target/jvm/instruction/condition.lux @@ -7,8 +7,9 @@ ["." try (#+ Try)] ["." exception (#+ exception:)]] [data - [number (#+ hex)] ["." binary] + [number (#+ hex) + ["n" nat]] [text ["%" format (#+ format)]] [format @@ -44,9 +45,9 @@ (def: #export (produces amount env) (-> Nat Condition) - (let [stack (n/+ amount + (let [stack (n.+ amount (///unsigned.nat (get@ #stack env))) - max-stack (n/max stack + max-stack (n.max stack (///unsigned.nat (get@ [#resources #//resources.max-stack] env)))] (|> env (set@ #stack (///unsigned.u2 stack)) @@ -62,9 +63,9 @@ (def: #export (consumes wanted-pops env) (-> Nat Condition) (let [stack-size (///unsigned.nat (get@ #stack env))] - (if (n/<= stack-size wanted-pops) + (if (n.<= stack-size wanted-pops) (#try.Success (update@ #stack - (|>> ///unsigned.nat (n/- wanted-pops) ///unsigned.u2) + (|>> ///unsigned.nat (n.- wanted-pops) ///unsigned.u2) env)) (exception.throw ..cannot-pop-stack [stack-size wanted-pops])))) @@ -72,7 +73,7 @@ (def: #export (has-local local environment) (-> Local Condition) - (let [max-locals (n/max (///unsigned.nat (get@ [#resources #//resources.max-locals] environment)) + (let [max-locals (n.max (///unsigned.nat (get@ [#resources #//resources.max-locals] environment)) (///unsigned.nat local))] (|> environment (set@ [#resources #//resources.max-locals] diff --git a/stdlib/source/lux/target/jvm/instruction/resources.lux b/stdlib/source/lux/target/jvm/instruction/resources.lux index fa83c4071..c7d741a1d 100644 --- a/stdlib/source/lux/target/jvm/instruction/resources.lux +++ b/stdlib/source/lux/target/jvm/instruction/resources.lux @@ -3,6 +3,8 @@ [abstract ["." equivalence (#+ Equivalence)]] [data + [number + ["n" nat]] [format [".F" binary (#+ Writer) ("#@." monoid)]]]] ["." /// #_ @@ -19,7 +21,7 @@ #max-locals (///unsigned.u2 0)}) (def: #export length - ($_ n/+ + ($_ n.+ ## u2 max_stack; ///unsigned.u2-bytes ## u2 max_locals; diff --git a/stdlib/source/lux/target/jvm/reflection.lux b/stdlib/source/lux/target/jvm/reflection.lux index e52395dc3..89f759dcb 100644 --- a/stdlib/source/lux/target/jvm/reflection.lux +++ b/stdlib/source/lux/target/jvm/reflection.lux @@ -10,6 +10,8 @@ [parser ["<t>" text]]] [data + [number + ["n" nat]] ["." text ("#@." equivalence) ["%" format (#+ format)]] [collection @@ -264,7 +266,7 @@ num-class-params (list.size class-params) num-type-params (list.size params)] (if (text@= class-name name) - (if (n/= num-class-params num-type-params) + (if (n.= num-class-params num-type-params) (|> params (list.zip2 (list@map (|>> java/lang/reflect/TypeVariable::getName) class-params)) diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index ccb79d61d..9e1abb0fb 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -9,6 +9,8 @@ ["." promise (#+ Promise) ("#;." monad)]]] [data ["." product] + [number + ["n" nat]] ["." text ["%" format (#+ format)]] [collection @@ -25,8 +27,8 @@ (def: (add-counters parameter subject) (-> Counters Counters Counters) - {#successes (n/+ (get@ #successes parameter) (get@ #successes subject)) - #failures (n/+ (get@ #failures parameter) (get@ #failures subject))}) + {#successes (n.+ (get@ #successes parameter) (get@ #successes subject)) + #failures (n.+ (get@ #failures parameter) (get@ #failures subject))}) (def: start Counters @@ -106,7 +108,7 @@ (def: failed? (-> Counters Bit) - (|>> product.right (n/> 0))) + (|>> product.right (n.> 0))) (def: (times-failure seed documentation) (-> Seed Text Text) @@ -117,10 +119,10 @@ (def: #export (times amount test) (-> Nat Test Test) - (cond (n/= 0 amount) + (cond (n.= 0 amount) (fail (ex.construct must-try-test-at-least-once [])) - (n/= 1 amount) + (n.= 1 amount) test ## else @@ -138,7 +140,7 @@ (-> Counters Text) (let [successes (get@ #successes counters) failures (get@ #failures counters)] - (ex.report ["Tests" (%.nat (n/+ successes failures))] + (ex.report ["Tests" (%.nat (n.+ successes failures))] ["Successes" (%.nat successes)] ["Failures" (%.nat failures)]))) diff --git a/stdlib/source/lux/time/date.lux b/stdlib/source/lux/time/date.lux index 0b40932ef..dfb7baf7e 100644 --- a/stdlib/source/lux/time/date.lux +++ b/stdlib/source/lux/time/date.lux @@ -12,7 +12,7 @@ [data ["." maybe] [number - ["." nat ("#@." decimal)] + ["n" nat ("#@." decimal)] ["i" int ("#@." decimal)]] ["." text ("#@." monoid)] [collection @@ -34,7 +34,7 @@ (:: //month.equivalence = (get@ #month reference) (get@ #month sample)) - (n/= (get@ #day reference) + (n.= (get@ #day reference) (get@ #day sample))))) (structure: #export order (Order Date) @@ -50,13 +50,13 @@ (and (:: //month.order = (get@ #month reference) (get@ #month sample)) - (n/< (get@ #day reference) + (n.< (get@ #day reference) (get@ #day sample)))))))) ## Based on this: https://stackoverflow.com/a/42936293/6823464 (def: (pad value) (-> Int Text) - (let [digits (nat@encode (.nat value))] + (let [digits (n@encode (.nat value))] (if (i.< +10 value) (text@compose "0" digits) digits))) @@ -66,7 +66,7 @@ ($_ text@compose (if (i.< +0 year) (i@encode year) - (nat@encode (.nat year))) + (n@encode (.nat year))) "-" (pad (|> month //month.number inc .int)) "-" (pad (|> day .inc .int)))) @@ -75,7 +75,7 @@ (Parser Int) (do p.monad [sign (p.maybe (l.this "-")) - raw-year (p.codec nat.decimal (l.many l.decimal)) + raw-year (p.codec n.decimal (l.many l.decimal)) #let [signum (case sign (#.Some _) -1 @@ -86,7 +86,7 @@ (def: lex-section (Parser Int) - (p@map .int (p.codec nat.decimal (l.exactly 2 l.decimal)))) + (p@map .int (p.codec n.decimal (l.exactly 2 l.decimal)))) (def: (leap-years year) (-> Int Int) diff --git a/stdlib/source/lux/time/day.lux b/stdlib/source/lux/time/day.lux index a3f3fb3f2..caabc8797 100644 --- a/stdlib/source/lux/time/day.lux +++ b/stdlib/source/lux/time/day.lux @@ -1,9 +1,12 @@ (.module: - [lux #* + [lux (#- nat) [abstract [equivalence (#+ Equivalence)] [order (#+ Order)] - [enum (#+ Enum)]]]) + [enum (#+ Enum)]] + [data + [number + ["n" nat]]]]) (type: #export Day #Sunday @@ -31,7 +34,7 @@ _ #0))) -(def: (day-to-nat day) +(def: (nat day) (-> Day Nat) (case day #Sunday 0 @@ -45,7 +48,7 @@ (structure: #export order (Order Day) (def: &equivalence ..equivalence) (def: (< reference sample) - (n/< (day-to-nat reference) (day-to-nat sample)))) + (n.< (..nat reference) (..nat sample)))) (structure: #export enum (Enum Day) (def: &order ..order) diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index 892b8df5b..b9d504f1a 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -14,6 +14,7 @@ [data ["." maybe] [number + ["n" nat] ["i" int ("#@." decimal)]] ["." text ("#@." monoid)] [collection @@ -288,7 +289,7 @@ ## month-days-so-far (|> months ## row.to-list ## (list.take (.nat (dec utc-month))) -## (list@fold n/+ 0)) +## (list@fold n.+ 0)) ## total-days (|> year-days-so-far ## (i.+ (.int month-days-so-far)) ## (i.+ (dec utc-day)))]] diff --git a/stdlib/source/lux/time/month.lux b/stdlib/source/lux/time/month.lux index e2e248ce5..585a3f98a 100644 --- a/stdlib/source/lux/time/month.lux +++ b/stdlib/source/lux/time/month.lux @@ -3,7 +3,10 @@ [abstract [equivalence (#+ Equivalence)] [order (#+ Order)] - [enum (#+ Enum)]]]) + [enum (#+ Enum)]] + [data + [number + ["n" nat]]]]) (type: #export Month #January @@ -60,7 +63,7 @@ (structure: #export order (Order Month) (def: &equivalence ..equivalence) (def: (< reference sample) - (n/< (number reference) (number sample)))) + (n.< (number reference) (number sample)))) (structure: #export enum (Enum Month) (def: &order ..order) diff --git a/stdlib/source/lux/tool/compiler/analysis.lux b/stdlib/source/lux/tool/compiler/analysis.lux index f2e1cb978..33973f979 100644 --- a/stdlib/source/lux/tool/compiler/analysis.lux +++ b/stdlib/source/lux/tool/compiler/analysis.lux @@ -9,6 +9,8 @@ [data ["." product] ["." maybe] + [number + ["n" nat]] ["." text ("#@." equivalence) ["%" format (#+ Format format)]] [collection @@ -97,7 +99,7 @@ (def: (last? size tag) (-> Nat Tag Bit) - (n/= (dec size) tag)) + (n.= (dec size) tag)) (template: #export (no-op value) (|> 1 #reference.Local #reference.Variable #..Reference diff --git a/stdlib/source/lux/tool/compiler/default/syntax.lux b/stdlib/source/lux/tool/compiler/default/syntax.lux index 16a7b4771..0b938b49a 100644 --- a/stdlib/source/lux/tool/compiler/default/syntax.lux +++ b/stdlib/source/lux/tool/compiler/default/syntax.lux @@ -35,7 +35,7 @@ [data ["." maybe] [number - ["." nat] + ["n" nat] ["." int] ["." rev] ["." frac]] @@ -134,7 +134,7 @@ (def: (input-at start input) (-> Offset Text Text) - (let [end (|> start (n/+ amount-of-input-shown) (n/min ("lux text size" input)))] + (let [end (|> start (!n/+ amount-of-input-shown) (n.min ("lux text size" input)))] (!clip start end input))) (exception: #export (unrecognized-input {[file line column] Cursor} {context Text} {input Text} {offset Offset}) @@ -307,7 +307,7 @@ (text.replace-all ..digit-separator "") (:: <codec> decode)) (#.Right output) - (#.Right [[(update@ #.column (n/+ (!n/- <start> <end>)) where) + (#.Right [[(update@ #.column (|>> (!n/+ (!n/- <start> <end>))) where) <end> source-code] [where (<tag> output)]]) @@ -368,7 +368,7 @@ (recur (!inc g!end)) (!number-output start g!end <codec> <tag>)))))] - [parse-nat nat.decimal #.Nat] + [parse-nat n.decimal #.Nat] [parse-rev rev.decimal #.Rev] ) @@ -379,7 +379,7 @@ (parse-signed offset [where (!inc/2 offset) source-code]) (!parse-full-name offset [where (!inc offset) source-code] where @aliases #.Identifier))))) -(with-expansions [<output> (#.Right [[(update@ #.column (n/+ (!n/- start end)) where) +(with-expansions [<output> (#.Right [[(update@ #.column (|>> (!n/+ (!n/- start end))) where) end source-code] (!clip start end source-code)])] diff --git a/stdlib/source/lux/tool/compiler/meta/cache.lux b/stdlib/source/lux/tool/compiler/meta/cache.lux index 31cf37b9a..bb4c4d8c8 100644 --- a/stdlib/source/lux/tool/compiler/meta/cache.lux +++ b/stdlib/source/lux/tool/compiler/meta/cache.lux @@ -9,6 +9,8 @@ ["." bit ("#;." equivalence)] ["." maybe] ["." product] + [number + ["n" nat]] [format ["." binary (#+ Format)]] ["." text @@ -132,7 +134,7 @@ (get@ #//archive.signature key) signature)) _ (ex.assert stale-document [module current-hash document-hash] - (n/= current-hash document-hash)) + (n.= current-hash document-hash)) document (//archive.write key signature descriptor content)] (wrap [[module references] document])) (#try.Success [dependency document]) diff --git a/stdlib/source/lux/tool/compiler/name.lux b/stdlib/source/lux/tool/compiler/name.lux index 16a8d4786..19a7f5dae 100644 --- a/stdlib/source/lux/tool/compiler/name.lux +++ b/stdlib/source/lux/tool/compiler/name.lux @@ -2,6 +2,8 @@ [lux #* [data ["." maybe] + [number + ["n" nat]] ["." text ["%" format (#+ format)]]]]) @@ -39,7 +41,7 @@ (let [name/size (text.size name)] (loop [idx 0 output ""] - (if (n/< name/size idx) + (if (n.< name/size idx) (recur (inc idx) (|> name ("lux text char" idx) diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/case.lux b/stdlib/source/lux/tool/compiler/phase/analysis/case.lux index dd45ab734..c69abb4df 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis/case.lux @@ -8,6 +8,8 @@ [data ["." product] ["." maybe] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -187,15 +189,15 @@ num-subs (maybe.default (list.size subs) num-tags) num-sub-patterns (list.size sub-patterns) - matches (cond (n/< num-subs num-sub-patterns) + matches (cond (n.< num-subs num-sub-patterns) (let [[prefix suffix] (list.split (dec num-sub-patterns) subs)] (list.zip2 (list@compose prefix (list (type.tuple suffix))) sub-patterns)) - (n/> num-subs num-sub-patterns) + (n.> num-subs num-sub-patterns) (let [[prefix suffix] (list.split (dec num-subs) sub-patterns)] (list.zip2 subs (list@compose prefix (list (code.tuple suffix))))) - ## (n/= num-subs num-sub-patterns) + ## (n.= num-subs num-sub-patterns) (list.zip2 subs sub-patterns))] (do @ [[memberP+ thenA] (list@fold (: (All [a] @@ -246,16 +248,16 @@ num-cases (maybe.default size-sum num-tags)] (.case (list.nth idx flat-sum) (^multi (#.Some caseT) - (n/< num-cases idx)) + (n.< num-cases idx)) (do ///.monad - [[testP nextA] (if (and (n/> num-cases size-sum) - (n/= (dec num-cases) idx)) + [[testP nextA] (if (and (n.> num-cases size-sum) + (n.= (dec num-cases) idx)) (analyse-pattern #.None (type.variant (list.drop (dec num-cases) flat-sum)) (` [(~+ values)]) next) (analyse-pattern #.None caseT (` [(~+ values)]) next)) - #let [right? (n/= (dec num-cases) idx) + #let [right? (n.= (dec num-cases) idx) lefts (if right? (dec idx) idx)]] diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/case/coverage.lux b/stdlib/source/lux/tool/compiler/phase/analysis/case/coverage.lux index af43a0e53..f81fa19fd 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis/case/coverage.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis/case/coverage.lux @@ -10,7 +10,7 @@ ["." bit ("#@." equivalence)] ["." maybe] [number - ["." nat]] + ["n" nat]] ["." text ["%" format (#+ Format format)]] [collection @@ -29,7 +29,7 @@ (def: known-cases? (-> Nat Bit) - (n/> 0)) + (n.> 0)) ## The coverage of a pattern-matching expression summarizes how well ## all the possible values of an input are being covered by the @@ -147,7 +147,7 @@ (wrap (#Variant (if right? (#.Some idx) #.None) - (|> (dictionary.new nat.hash) + (|> (dictionary.new n.hash) (dictionary.put idx value-coverage))))))) (def: (xor left right) @@ -184,7 +184,7 @@ (bit@= sideR sideS) [(#Variant allR casesR) (#Variant allS casesS)] - (and (n/= (cases allR) + (and (n.= (cases allR) (cases allS)) (:: (dictionary.equivalence =) = casesR casesS)) @@ -195,7 +195,7 @@ [(#Alt _) (#Alt _)] (let [flatR (flatten-alt reference) flatS (flatten-alt sample)] - (and (n/= (list.size flatR) (list.size flatS)) + (and (n.= (list.size flatR) (list.size flatS)) (list.every? (function (_ [coverageR coverageS]) (= coverageR coverageS)) (list.zip2 flatR flatS)))) @@ -229,7 +229,7 @@ so-far-cases (cases allA)] (cond (and (known-cases? addition-cases) (known-cases? so-far-cases) - (not (n/= addition-cases so-far-cases))) + (not (n.= addition-cases so-far-cases))) (ex.throw variants-do-not-match [addition-cases so-far-cases]) (:: (dictionary.equivalence ..equivalence) = casesSF casesA) @@ -250,7 +250,7 @@ casesSF (dictionary.entries casesA))] (wrap (if (and (or (known-cases? addition-cases) (known-cases? so-far-cases)) - (n/= (inc (n/max addition-cases so-far-cases)) + (n.= (inc (n.max addition-cases so-far-cases)) (dictionary.size casesM)) (list.every? exhaustive? (dictionary.values casesM))) #Exhaustive diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/inference.lux b/stdlib/source/lux/tool/compiler/phase/analysis/inference.lux index 701e01167..f3cc27357 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis/inference.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis/inference.lux @@ -6,6 +6,8 @@ ["ex" exception (#+ exception:)]] [data ["." maybe] + [number + ["n" nat]] ["." text ["%" format (#+ format)]] [collection @@ -66,14 +68,14 @@ [#.Apply]) (#.Parameter idx) - (if (n/= parameter-idx idx) + (if (n.= parameter-idx idx) replacement type) (^template [<tag>] (<tag> env quantified) (<tag> (list@map (replace parameter-idx replacement) env) - (replace (n/+ 2 parameter-idx) replacement quantified))) + (replace (n.+ 2 parameter-idx) replacement quantified))) ([#.UnivQ] [#.ExQ]) @@ -183,7 +185,7 @@ ([#.Sum] [#.Product] [#.Function] [#.Apply]) (#.Parameter index) - (if (n/= target index) + (if (n.= target index) sub base) @@ -205,7 +207,7 @@ (^template [<tag>] (<tag> env bodyT) (do ///.monad - [bodyT+ (record' (n/+ 2 target) originalT bodyT)] + [bodyT+ (record' (n.+ 2 target) originalT bodyT)] (wrap (<tag> env bodyT+)))) ([#.UnivQ] [#.ExQ]) @@ -228,7 +230,7 @@ (def: #export (record inferT) (-> Type (Operation Type)) - (record' (n/- 2 0) inferT inferT)) + (record' (n.- 2 0) inferT inferT)) ## Turns a variant type into the kind of function type suitable for inference. (def: #export (variant tag expected-size inferT) @@ -253,28 +255,28 @@ (let [cases (type.flatten-variant currentT) actual-size (list.size cases) boundary (dec expected-size)] - (cond (or (n/= expected-size actual-size) - (and (n/> expected-size actual-size) - (n/< boundary tag))) + (cond (or (n.= expected-size actual-size) + (and (n.> expected-size actual-size) + (n.< boundary tag))) (case (list.nth tag cases) (#.Some caseT) - (///@wrap (if (n/= 0 depth) + (///@wrap (if (n.= 0 depth) (type.function (list caseT) currentT) - (let [replace' (replace (|> depth dec (n/* 2)) inferT)] + (let [replace' (replace (|> depth dec (n.* 2)) inferT)] (type.function (list (replace' caseT)) (replace' currentT))))) #.None (/.throw variant-tag-out-of-bounds [expected-size tag inferT])) - (n/< expected-size actual-size) + (n.< expected-size actual-size) (/.throw smaller-variant-than-expected [expected-size actual-size]) - (n/= boundary tag) + (n.= boundary tag) (let [caseT (type.variant (list.drop boundary cases))] - (///@wrap (if (n/= 0 depth) + (///@wrap (if (n.= 0 depth) (type.function (list caseT) currentT) - (let [replace' (replace (|> depth dec (n/* 2)) inferT)] + (let [replace' (replace (|> depth dec (n.* 2)) inferT)] (type.function (list (replace' caseT)) (replace' currentT)))))) diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/structure.lux b/stdlib/source/lux/tool/compiler/phase/analysis/structure.lux index eeb2cf9e0..49447e847 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis/structure.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis/structure.lux @@ -10,7 +10,7 @@ ["." product] ["." maybe] [number - ["." nat]] + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -94,7 +94,7 @@ (#.Sum _) (let [flat (type.flatten-variant expectedT) type-size (list.size flat) - right? (n/= (dec type-size) + right? (n.= (dec type-size) tag) lefts (if right? (dec tag) @@ -269,7 +269,7 @@ [#let [case-size (list.size group)] inferenceT (//inference.variant idx case-size variantT) [inferredT valueA+] (//inference.general analyse inferenceT (list valueC)) - #let [right? (n/= (dec case-size) idx) + #let [right? (n.= (dec case-size) idx) lefts (if right? (dec idx) idx)]] @@ -312,7 +312,7 @@ [_ tag-set recordT] (///extension.lift (macro.resolve-tag head-k)) #let [size-record (list.size record) size-ts (list.size tag-set)] - _ (if (n/= size-ts size-record) + _ (if (n.= size-ts size-record) (wrap []) (/.throw record-size-mismatch [size-ts size-record recordT record])) #let [tuple-range (list.indices size-ts) @@ -330,7 +330,7 @@ #.None (/.throw tag-does-not-belong-to-record [key recordT])))) (: (Dictionary Nat Code) - (dictionary.new nat.hash)) + (dictionary.new n.hash)) record) #let [ordered-tuple (list@map (function (_ idx) (maybe.assume (dictionary.get idx idx->val))) tuple-range)]] diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux index 3acecec11..85d7524f9 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux @@ -14,6 +14,8 @@ [data ["." maybe] ["." product] + [number + ["n" nat]] ["." text ("#@." equivalence) ["%" format (#+ format)]] [collection @@ -329,7 +331,7 @@ (analyse lengthC)) expectedT (///.lift macro.expected-type) [level elem-class] (array-type-info false expectedT) - _ (if (n/> 0 level) + _ (if (n.> 0 level) (wrap []) (/////analysis.throw ..non-array expectedT))] (wrap (#/////analysis.Extension extension-name (list (/////analysis.nat (dec level)) @@ -940,7 +942,7 @@ _ #1) - arity-matches? (n/= (list.size arg-classes) (list.size parameters)) + arity-matches? (n.= (list.size arg-classes) (list.size parameters)) inputs-match? (list@fold (function (_ [expectedJC actualJC] prev) (and prev (text@= expectedJC actualJC))) @@ -962,7 +964,7 @@ (:: try.monad map (list@map jvm.descriptor)) ////.lift)] (wrap (and (java/lang/Object::equals class (java/lang/reflect/Constructor::getDeclaringClass constructor)) - (n/= (list.size arg-classes) (list.size parameters)) + (n.= (list.size arg-classes) (list.size parameters)) (list@fold (function (_ [expectedJC actualJC] prev) (and prev (text@= expectedJC actualJC))) @@ -971,7 +973,7 @@ (def: idx-to-parameter (-> Nat .Type) - (|>> (n/* 2) inc #.Parameter)) + (|>> (n.* 2) inc #.Parameter)) (def: (jvm-type-var-mapping owner-tvars method-tvars) (-> (List Text) (List Text) [(List .Type) Mapping]) @@ -1830,7 +1832,7 @@ (and (text@= super-name sub-name) (method@= superJT subJT)))) list.size - (n/= 1) + (n.= 1) not)) sub-set)) @@ -1852,7 +1854,7 @@ array.to-list (list@map (|>> java/lang/reflect/TypeVariable::getName)))] _ (////.assert ..class-parameter-mismatch [expected-parameters actual-parameters] - (n/= (list.size expected-parameters) + (n.= (list.size expected-parameters) (list.size actual-parameters)))] (wrap (|> (list.zip2 expected-parameters actual-parameters) (list@fold (function (_ [expected actual] mapping) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux index efd917bd2..b73f30a6b 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux @@ -10,6 +10,8 @@ ["<c>" code (#+ Parser)]]] [data ["." maybe] + [number + ["n" nat]] ["." text ["%" format (#+ format)]] [collection @@ -48,7 +50,7 @@ (let [num-expected (list.size inputsT+)] (function (_ extension-name analyse args) (let [num-actual (list.size args)] - (if (n/= num-expected num-actual) + (if (n.= num-expected num-actual) (do ////.monad [_ (typeA.infer outputT) argsA (monad.map @ diff --git a/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/case.lux b/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/case.lux index 6b782a24d..6fdb37e34 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/case.lux @@ -6,6 +6,8 @@ ["ex" exception (#+ exception:)]] [data ["." text] + [number + ["n" nat]] [collection ["." list ("#@." functor fold)] ["." set]]] @@ -175,7 +177,7 @@ (do ////.monad [next! (pattern-matching' generate nextP')] (////@wrap ($_ _.progn - (..multi-pop! (n/+ 2 extra-pops)) + (..multi-pop! (n.+ 2 extra-pops)) next!)))) (^template [<tag> <combinator>] diff --git a/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/loop.lux index 13e049e1d..a00fc2b12 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/loop.lux @@ -4,6 +4,8 @@ ["." monad (#+ do)]] [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -27,7 +29,7 @@ (generate bodyS))] (wrap (_.labels (list [@scope {#_.input (|> initsS+ list.enumerate - (list@map (|>> product.left (n/+ start) //case.register)) + (list@map (|>> product.left (n.+ start) //case.register)) _.args) #_.output bodyG}]) (_.funcall/+ [(_.function/1 @scope) initsG+]))))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux index f17b2b983..d9956579c 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux @@ -6,6 +6,8 @@ ["ex" exception (#+ exception:)]] [data ["." text] + [number + ["n" nat]] [collection ["." list ("#@." functor fold)]]] [target @@ -207,7 +209,7 @@ (do ////.monad [next! (pattern-matching' generate nextP')] (////@wrap ($_ _.then - (multi-pop-cursor! (n/+ 2 extra-pops)) + (multi-pop-cursor! (n.+ 2 extra-pops)) next!)))) (^template [<tag> <combinator>] diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux index 65e691c51..101c49b95 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux @@ -5,6 +5,8 @@ [data ["." product] ["." text] + [number + ["n" nat]] [collection ["." list ("#@." functor)]]] [target @@ -28,7 +30,7 @@ #let [closure (_.function @scope (|> initsS+ list.enumerate - (list@map (|>> product.left (n/+ start) //case.register))) + (list@map (|>> product.left (n.+ start) //case.register))) (_.return bodyO))]] (wrap (_.apply/* closure initsO+)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/lua/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/lua/loop.lux index b575ec97b..f1bb7fb84 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/lua/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/lua/loop.lux @@ -4,6 +4,8 @@ ["." monad (#+ do)]] [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -28,7 +30,7 @@ _ (///.save! true ["" (_.code @loop)] (_.function @loop (|> initsS+ list.enumerate - (list@map (|>> product.left (n/+ start) //case.register))) + (list@map (|>> product.left (n.+ start) //case.register))) (_.return bodyO)))] (wrap (_.apply/* initsO+ @loop)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/php/case.lux b/stdlib/source/lux/tool/compiler/phase/generation/php/case.lux index fedfff63f..cbdbb1c70 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/php/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/php/case.lux @@ -9,6 +9,7 @@ ["." text ["%" format (#+ format)]] [number + ["n" nat] ["i" int]] [collection ["." list ("#@." functor fold)] @@ -188,7 +189,7 @@ ## (do ////.monad ## [next! (pattern-matching' generate nextP')] ## (////@wrap ($_ _.then - ## (..multi-pop! (n/+ 2 extra-pops)) + ## (..multi-pop! (n.+ 2 extra-pops)) ## next!)))) (^template [<tag> <combinator>] diff --git a/stdlib/source/lux/tool/compiler/phase/generation/php/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/php/loop.lux index 75cdedae3..3ec2d2d40 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/php/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/php/loop.lux @@ -4,6 +4,8 @@ ["." monad (#+ do)]] [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -34,7 +36,7 @@ (_.closure (list (_.reference @loopL)) (|> initsS+ list.enumerate - (list@map (|>> product.left (n/+ start) //case.register [#0]))) + (list@map (|>> product.left (n.+ start) //case.register [#0]))) (_.return bodyO))) (_.; (_.set @loopG @loopL))))] (wrap (_.apply/* initsO+ @loopG)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/case.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/case.lux index 9589e3336..aeaa18986 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/case.lux @@ -8,6 +8,7 @@ ["." text ["%" format (#+ format)]] [number + ["n" nat] ["i" int]] [collection ["." list ("#@." functor fold)] @@ -185,7 +186,7 @@ (do ////.monad [next! (pattern-matching' generate nextP')] (////@wrap ($_ _.then - (..multi-pop! (n/+ 2 extra-pops)) + (..multi-pop! (n.+ 2 extra-pops)) next!)))) (^template [<tag> <combinator>] diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/loop.lux index f0d75ef29..02d4a92ec 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/loop.lux @@ -4,6 +4,8 @@ ["." monad (#+ do)]] [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -28,7 +30,7 @@ _ (///.save! true ["" (_.code @loop)] (_.def @loop (|> initsS+ list.enumerate - (list@map (|>> product.left (n/+ start) //case.register))) + (list@map (|>> product.left (n.+ start) //case.register))) (_.return bodyO)))] (wrap (_.apply/* @loop initsO+)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/ruby/case.lux b/stdlib/source/lux/tool/compiler/phase/generation/ruby/case.lux index 695485a16..8d95783a9 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/ruby/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/ruby/case.lux @@ -7,6 +7,7 @@ [data ["." text] [number + ["n" nat] ["i" int]] [collection ["." list ("#@." functor fold)] @@ -186,7 +187,7 @@ (do ////.monad [next! (pattern-matching' generate nextP')] (////@wrap ($_ _.then - (..multi-pop! (n/+ 2 extra-pops)) + (..multi-pop! (n.+ 2 extra-pops)) next!)))) (^template [<tag> <combinator>] diff --git a/stdlib/source/lux/tool/compiler/phase/generation/ruby/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/ruby/loop.lux index 6503d23f8..4bb7d44c7 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/ruby/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/ruby/loop.lux @@ -4,6 +4,8 @@ ["." monad (#+ do)]] [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -29,7 +31,7 @@ (_.lambda (#.Some @loop) (|> initsS+ list.enumerate - (list@map (|>> product.left (n/+ start) //case.register)))) + (list@map (|>> product.left (n.+ start) //case.register)))) (_.apply/* initsO+))))) (def: #export (recur generate argsS+) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/scheme/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/scheme/loop.lux index a0a5d74eb..294b3ed2d 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/scheme/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/scheme/loop.lux @@ -5,6 +5,8 @@ [data ["." product] ["." text] + [number + ["n" nat]] [collection ["." list ("#;." functor)]]] [target @@ -27,7 +29,7 @@ (generate bodyS))] (wrap (_.letrec (list [@scope (_.lambda [(|> initsS+ list.enumerate - (list;map (|>> product.left (n/+ start) //case.register))) + (list;map (|>> product.left (n.+ start) //case.register))) #.None] bodyO)]) (_.apply/* @scope initsO+))))) diff --git a/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux b/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux index 8ee2ab8c2..55cdf5034 100644 --- a/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux @@ -10,6 +10,7 @@ ["." bit ("#@." equivalence)] ["." text ("#@." equivalence)] [number + ["n" nat] ["." frac ("#@." equivalence)]] [collection ["." list ("#@." functor fold monoid)] @@ -59,7 +60,7 @@ (#////analysis.Complex (#////analysis.Tuple tuple)) (let [tuple::last (dec (list.size tuple))] (list@fold (function (_ [tuple::lefts tuple::member] nextC) - (let [right? (n/= tuple::last tuple::lefts) + (let [right? (n.= tuple::last tuple::lefts) end?' (and end? right?)] (<| (///@map (|>> (#/.Seq (#/.Access (#/.Member (if right? (#.Right (dec tuple::lefts)) @@ -105,7 +106,7 @@ (^template [<access> <side>] [(#/.Access (<access> (<side> leftL))) (#/.Access (<access> (<side> rightL)))] - (if (n/= leftL rightL) + (if (n.= leftL rightL) rightP <default>)) ([#/.Side #.Left] @@ -114,7 +115,7 @@ [#/.Member #.Right]) [(#/.Bind leftR) (#/.Bind rightR)] - (if (n/= leftR rightR) + (if (n.= leftR rightR) rightP <default>) @@ -127,7 +128,7 @@ [inputS (synthesize^ inputA)] (with-expansions [<unnecesary-let> (as-is (^multi (^ (#////analysis.Reference (////reference.local outputR))) - (n/= inputR outputR)) + (n.= inputR outputR)) (wrap inputS)) <let> diff --git a/stdlib/source/lux/tool/compiler/phase/synthesis/loop.lux b/stdlib/source/lux/tool/compiler/phase/synthesis/loop.lux index 0ac6cc12b..62bfda31c 100644 --- a/stdlib/source/lux/tool/compiler/phase/synthesis/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/synthesis/loop.lux @@ -6,6 +6,8 @@ ["p" parser]] [data ["." maybe ("#;." monad)] + [number + ["n" nat]] [collection ["." list ("#;." functor)]]] [macro @@ -152,7 +154,7 @@ #.None))) (^ (#/.Function (recursive-apply argsS))) - (if (n/= arity (list.size argsS)) + (if (n.= arity (list.size argsS)) (#.Some (|> argsS #/.Recur #/.Loop #/.Control)) #.None) @@ -177,7 +179,7 @@ (function (recur pathS) (case pathS (#/.Bind register) - (#.Some (#/.Bind (n/+ offset register))) + (#.Some (#/.Bind (n.+ offset register))) (^template [<tag>] (<tag> leftS rightS) @@ -218,7 +220,7 @@ (#.Some exprS) (^ (////reference.local register)) - (#.Some (#/.Reference (////reference.local (n/+ offset register)))) + (#.Some (#/.Reference (////reference.local (n.+ offset register)))) (^ (////reference.foreign register)) (|> scope-environment @@ -250,7 +252,7 @@ (get@ #/.inits) (monad.map maybe.monad recur)) iteration' (recur (get@ #/.iteration scopeS))] - (wrap (/.loop/scope {#/.start (|> scopeS (get@ #/.start) (n/+ offset)) + (wrap (/.loop/scope {#/.start (|> scopeS (get@ #/.start) (n.+ offset)) #/.inits inits' #/.iteration iteration'}))) @@ -284,7 +286,7 @@ (def: #export (loop environment num-locals inits functionS) (-> Environment Nat (List Synthesis) Abstraction (Maybe Synthesis)) (let [bodyS (get@ #/.body functionS)] - (if (and (n/= (list.size inits) + (if (and (n.= (list.size inits) (get@ #/.arity functionS)) (proper? bodyS)) (|> bodyS diff --git a/stdlib/source/lux/tool/compiler/reference.lux b/stdlib/source/lux/tool/compiler/reference.lux index 53aa769a8..79f6c921e 100644 --- a/stdlib/source/lux/tool/compiler/reference.lux +++ b/stdlib/source/lux/tool/compiler/reference.lux @@ -6,6 +6,8 @@ [control pipe] [data + [number + ["n" nat]] [text ["%" format (#+ Format format)]]]]) @@ -24,7 +26,7 @@ (case [reference sample] (^template [<tag>] [(<tag> reference') (<tag> sample')] - (n/= reference' sample')) + (n.= reference' sample')) ([#Local] [#Foreign]) _ @@ -35,10 +37,10 @@ (def: (hash var) (case var (#Local register) - (n/* 1 register) + (n.* 1 register) (#Foreign register) - (n/* 2 register)))) + (n.* 2 register)))) (template [<name> <family> <tag>] [(template: #export (<name> content) diff --git a/stdlib/source/lux/tool/compiler/synthesis.lux b/stdlib/source/lux/tool/compiler/synthesis.lux index 463affb73..4c8959b26 100644 --- a/stdlib/source/lux/tool/compiler/synthesis.lux +++ b/stdlib/source/lux/tool/compiler/synthesis.lux @@ -10,6 +10,7 @@ ["." text ("#;." equivalence) ["%" format (#+ Format format)]] [number + ["n" nat] ["i" int] ["f" frac]] [collection @@ -414,7 +415,7 @@ (case [reference' sample'] (^template [<side>] [(<side> reference'') (<side> sample'')] - (n/= reference'' sample'')) + (n.= reference'' sample'')) ([#.Left] [#.Right]) @@ -442,7 +443,7 @@ [#Then Equivalence<a>]) [(#Bind reference') (#Bind sample')] - (n/= reference' sample') + (n.= reference' sample') (^template [<tag>] [(<tag> leftR rightR) (<tag> leftS rightS)] diff --git a/stdlib/source/lux/type.lux b/stdlib/source/lux/type.lux index 15f284d10..247f2db15 100644 --- a/stdlib/source/lux/type.lux +++ b/stdlib/source/lux/type.lux @@ -12,7 +12,7 @@ ["." text ("#@." monoid equivalence)] ["." name ("#@." equivalence codec)] [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] ["." maybe] [collection ["." array] @@ -106,13 +106,13 @@ " " (to-text out) ")")) (#.Parameter idx) - (nat@encode idx) + (n@encode idx) (#.Var id) - ($_ text@compose "⌈v:" (nat@encode id) "⌋") + ($_ text@compose "⌈v:" (n@encode id) "⌋") (#.Ex id) - ($_ text@compose "⟨e:" (nat@encode id) "⟩") + ($_ text@compose "⟨e:" (n@encode id) "⟩") (#.Apply param fun) (let [[type-func type-args] (flatten-application type)] @@ -154,12 +154,12 @@ (#.Parameter idx) (maybe.default (error! ($_ text@compose "Unknown type parameter" text.new-line - " Index: " (nat@encode idx) text.new-line + " Index: " (n@encode idx) text.new-line "Environment: " (|> env list.enumerate (list@map (.function (_ [index type]) ($_ text@compose - (nat@encode index) + (n@encode index) " " (..to-text type)))) (text.join-with (text@compose text.new-line " "))))) (list.nth idx env)) @@ -174,14 +174,14 @@ (case [x y] [(#.Primitive xname xparams) (#.Primitive yname yparams)] (and (text@= xname yname) - (n/= (list.size yparams) (list.size xparams)) + (n.= (list.size yparams) (list.size xparams)) (list@fold (.function (_ [x y] prev) (and prev (= x y))) #1 (list.zip2 xparams yparams))) (^template [<tag>] [(<tag> xid) (<tag> yid)] - (n/= yid xid)) + (n.= yid xid)) ([#.Var] [#.Ex] [#.Parameter]) (^or [(#.Function xleft xright) (#.Function yleft yright)] @@ -200,7 +200,7 @@ (^or [(#.UnivQ xenv xbody) (#.UnivQ yenv ybody)] [(#.ExQ xenv xbody) (#.ExQ yenv ybody)]) - (and (n/= (list.size yenv) (list.size xenv)) + (and (n.= (list.size yenv) (list.size xenv)) (= xbody ybody) (list@fold (.function (_ [x y] prev) (and prev (= x y))) #1 diff --git a/stdlib/source/lux/type/check.lux b/stdlib/source/lux/type/check.lux index ffbd8af09..36254634e 100644 --- a/stdlib/source/lux/type/check.lux +++ b/stdlib/source/lux/type/check.lux @@ -11,7 +11,7 @@ ["." maybe] ["." product] [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] ["." text ("#@." monoid equivalence)] [collection ["." list] @@ -26,11 +26,11 @@ (exception: #export (unknown-type-var {id Nat}) (exception.report - ["ID" (nat@encode id)])) + ["ID" (n@encode id)])) (exception: #export (unbound-type-var {id Nat}) (exception.report - ["ID" (nat@encode id)])) + ["ID" (n@encode id)])) (exception: #export (invalid-type-application {funcT Type} {argT Type}) (exception.report @@ -39,7 +39,7 @@ (exception: #export (cannot-rebind-var {id Nat} {type Type} {bound Type}) (exception.report - ["Var" (nat@encode id)] + ["Var" (n@encode id)] ["Wanted Type" (//.to-text type)] ["Current Type" (//.to-text bound)])) @@ -283,7 +283,7 @@ (type: #export Ring (Set Var)) -(def: empty-ring Ring (set.new nat.hash)) +(def: empty-ring Ring (set.new n.hash)) ## TODO: Optimize this by not using sets anymore. (def: #export (ring start) @@ -356,7 +356,7 @@ then) (do ..monad [ring (..ring id) - _ (assert "" (n/> 1 (set.size ring))) + _ (assert "" (n.> 1 (set.size ring))) _ (monad.map @ (update type) (set.to-list ring))] then) (do ..monad @@ -451,7 +451,7 @@ [actual-input actual-function] actual] (case [expected-function actual-function] [(#.Ex exE) (#.Ex exA)] - (if (n/= exE exA) + (if (!n/= exE exA) (check' assumptions expected-input actual-input) (fail "")) diff --git a/stdlib/source/lux/type/implicit.lux b/stdlib/source/lux/type/implicit.lux index 9de0d7d10..652ff6127 100644 --- a/stdlib/source/lux/type/implicit.lux +++ b/stdlib/source/lux/type/implicit.lux @@ -9,7 +9,8 @@ [data ["." product] ["." maybe] - ["." number] + ["." number + ["n" nat]] ["." text ("#@." equivalence) ["%" format (#+ format)]] [collection @@ -23,7 +24,7 @@ (def: (find-type-var id env) (-> Nat Type-Context (Meta Type)) - (case (list.find (|>> product.left (n/= id)) + (case (list.find (|>> product.left (n.= id)) (get@ #.var-bindings env)) (#.Some [_ (#.Some type)]) (case type @@ -67,12 +68,12 @@ (find-member-type idx sig-type')) (#.Product left right) - (if (n/= 0 idx) + (if (n.= 0 idx) (:: check.monad wrap left) (find-member-type (dec idx) right)) _ - (if (n/= 0 idx) + (if (n.= 0 idx) (:: check.monad wrap sig-type) (check.fail (format "Cannot find member type " (%.nat idx) " for " (%.type sig-type)))))) diff --git a/stdlib/source/lux/type/resource.lux b/stdlib/source/lux/type/resource.lux index 096598521..9f3a12680 100644 --- a/stdlib/source/lux/type/resource.lux +++ b/stdlib/source/lux/type/resource.lux @@ -15,7 +15,7 @@ ["." maybe] ["." product] [number - ["." nat]] + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -133,7 +133,7 @@ (def: indices (Parser (List Nat)) - (s.tuple (loop [seen (set.new nat.hash)] + (s.tuple (loop [seen (set.new n.hash)] (do p.monad [done? s.end?] (if done? @@ -158,7 +158,7 @@ (#.Cons head tail) (do macro.monad - [#let [max-idx (list@fold n/max head tail)] + [#let [max-idx (list@fold n.max head tail)] g!inputs (<| (monad.seq @) (list.repeat (inc max-idx)) (macro.gensym "input")) #let [g!outputs (|> (monad.fold maybe.monad (function (_ from to) @@ -188,7 +188,7 @@ (do p.monad [raw s.nat _ (p.assert (exception.construct amount-cannot-be-zero []) - (n/> 0 raw))] + (n.> 0 raw))] (wrap raw))) (template [<name> <m> <monad> <from> <to>] diff --git a/stdlib/source/lux/world/net/http/request.lux b/stdlib/source/lux/world/net/http/request.lux index 67dfeec6c..9ddc6ee94 100644 --- a/stdlib/source/lux/world/net/http/request.lux +++ b/stdlib/source/lux/world/net/http/request.lux @@ -11,7 +11,8 @@ ["<.>" json]]] [data ["." maybe] - ["." number] + ["." number + ["n" nat]] ["." text ["." encoding]] [format @@ -33,11 +34,11 @@ (monad.fold try.monad (function (_ input [offset output]) (let [amount (binary.size input)] - (:: try.functor map (|>> [(n/+ amount offset)]) + (:: try.functor map (|>> [(n.+ amount offset)]) (binary.copy amount 0 input offset output)))) [0 (|> inputs (list;map binary.size) - (list;fold n/+ 0) + (list;fold n.+ 0) binary.create)] inputs))] output)) diff --git a/stdlib/source/lux/world/net/http/route.lux b/stdlib/source/lux/world/net/http/route.lux index 766d28fa5..9210dc67c 100644 --- a/stdlib/source/lux/world/net/http/route.lux +++ b/stdlib/source/lux/world/net/http/route.lux @@ -6,7 +6,9 @@ ["." promise]]] [data ["." maybe] - ["." text ("#;." equivalence)]]] + ["." text ("#;." equivalence)] + [number + ["n" nat]]]] ["." // (#+ URI Server) ["#." status] ["#." response]]) @@ -66,6 +68,6 @@ (do promise.monad [response (primary request) #let [[status message] response]] - (if (n/= //status.not-found status) + (if (n.= //status.not-found status) (alternative request) (wrap response))))) diff --git a/stdlib/source/program/licentia/input.lux b/stdlib/source/program/licentia/input.lux index 0fb4b5f84..7d2192fe1 100644 --- a/stdlib/source/program/licentia/input.lux +++ b/stdlib/source/program/licentia/input.lux @@ -10,6 +10,7 @@ [format ["." json (#+ Reader)]] [number + ["n" nat] ["i" int] ["f" frac]]]] [// @@ -63,7 +64,7 @@ #let [period {#time.start start #time.end end}] _ (parser.assert (ex.construct invalid-period period) - (n/<= end start))] + (n.<= end start))] (wrap period)))) (def: copyright-holder diff --git a/stdlib/source/program/licentia/license/notice.lux b/stdlib/source/program/licentia/license/notice.lux index 947669035..d4df7d166 100644 --- a/stdlib/source/program/licentia/license/notice.lux +++ b/stdlib/source/program/licentia/license/notice.lux @@ -1,6 +1,8 @@ (.module: [lux #* [data + [number + ["n" nat]] ["." text ["%" format (#+ format)]] [collection @@ -18,7 +20,7 @@ (def: #export (copyright-holder holder) (-> //copyright.Holder Text) (let [(^slots [#//time.start #//time.end]) (get@ #//copyright.period holder) - single-year? (n/= start end) + single-year? (n.= start end) period-section (if single-year? (%.nat start) (format (%.nat start) "-" (%.nat end)))] diff --git a/stdlib/source/program/scriptum.lux b/stdlib/source/program/scriptum.lux index 3775fd006..f44abef88 100644 --- a/stdlib/source/program/scriptum.lux +++ b/stdlib/source/program/scriptum.lux @@ -12,6 +12,8 @@ [data ["." maybe] ["." product] + [number + ["n" nat]] [format ["md" markdown (#+ Markdown Span Block)]] ["." text ("#;." equivalence) @@ -40,8 +42,8 @@ (text.from-code char) #.None - (format (parameter-type-name (n// name-options-count id)) - (parameter-type-name (n/% name-options-count id))))) + (format (parameter-type-name (n./ name-options-count id)) + (parameter-type-name (n.% name-options-count id))))) (def: type-var-names (Sequence Text) @@ -52,13 +54,13 @@ (-> Nat Bit) (<partition> id))] - [type-func? n/even?] - [type-arg? n/odd?] + [type-func? n.even?] + [type-arg? n.odd?] ) (def: (arg-id level id) (-> Nat Nat Nat) - (n/- (n// 2 id) level)) + (n.- (n./ 2 id) level)) (def: (parameter->name [type-func-name type-function-arguments] level id) (-> [Text (List Text)] Nat Nat Text) @@ -77,12 +79,12 @@ (def: (level->args offset level) (-> Nat Nat (List Text)) - (if (n/= 0 level) + (if (n.= 0 level) (list) (|> level dec (list.n/range 0) - (list;map (|>> (n/+ (inc offset)) parameter-type-name))))) + (list;map (|>> (n.+ (inc offset)) parameter-type-name))))) (def: (prefix-lines prefix lines) (-> Text Text Text) @@ -174,7 +176,7 @@ [_ (<tag> _)] (let [[level' body] (<flatten> type) args (level->args level level') - body-doc (pprint-type-definition (n/+ level level') type-func-info tags module signature? recursive-type? body)] + body-doc (pprint-type-definition (n.+ level level') type-func-info tags module signature? recursive-type? body)] (format "(" <name> " " "[" (text.join-with " " args) "]" (case tags #.Nil @@ -239,7 +241,7 @@ (<tag> _) (let [[level' body] (<flatten> type) args (level->args level level') - body-doc (pprint-type (n/+ level level') type-func-name module body)] + body-doc (pprint-type (n.+ level level') type-func-name module body)] (format "(" <name> " " "[" (|> args (list.interpose " ") (text.join-with "")) "]" (format " " body-doc) ")"))) @@ -318,7 +320,7 @@ (def: (unravel-type-func level type) (-> Nat Type Type) - (if (n/> 0 level) + (if (n.> 0 level) (case type (#.UnivQ _env _type) (unravel-type-func (dec level) _type) diff --git a/stdlib/source/spec/compositor/generation/case.lux b/stdlib/source/spec/compositor/generation/case.lux index 00a5e4d7c..414b468e2 100644 --- a/stdlib/source/spec/compositor/generation/case.lux +++ b/stdlib/source/spec/compositor/generation/case.lux @@ -10,6 +10,7 @@ ["." text ("#@." equivalence) ["%" format (#+ format)]] [number + ["n" nat] ["f" frac]] [collection ["." list ("#@." fold)]]] @@ -31,11 +32,11 @@ (def: size (Random Nat) - (|> r.nat (:: r.monad map (|>> (n/% ..limit) (n/max 2))))) + (|> r.nat (:: r.monad map (|>> (n.% ..limit) (n.max 2))))) (def: (tail? size idx) (-> Nat Nat Bit) - (n/= (dec size) idx)) + (n.= (dec size) idx)) (def: #export (verify expected) (-> Frac (Try Any) Bit) @@ -65,13 +66,13 @@ [(r.unicode 5) synthesis.text synthesis.path/text])) (do r.monad [size ..size - idx (|> r.nat (:: @ map (n/% size))) + idx (|> r.nat (:: @ map (n.% size))) [subS subP] case #let [unitS (synthesis.text synthesis.unit) caseS (synthesis.tuple (list.concat (list (list.repeat idx unitS) (list subS) - (list.repeat (|> size dec (n/- idx)) unitS)))) + (list.repeat (|> size dec (n.- idx)) unitS)))) caseP ($_ synthesis.path/seq (if (tail? size idx) (synthesis.member/right idx) @@ -80,7 +81,7 @@ (wrap [caseS caseP])) (do r.monad [size ..size - idx (|> r.nat (:: @ map (n/% size))) + idx (|> r.nat (:: @ map (n.% size))) [subS subP] case #let [right? (tail? size idx) caseS (synthesis.variant diff --git a/stdlib/source/spec/compositor/generation/common.lux b/stdlib/source/spec/compositor/generation/common.lux index b7a114893..c2289571a 100644 --- a/stdlib/source/spec/compositor/generation/common.lux +++ b/stdlib/source/spec/compositor/generation/common.lux @@ -10,6 +10,7 @@ ["." bit ("#@." equivalence)] [number ["." i64] + ["n" nat] ["i" int] ["f" frac]] ["." text ("#@." equivalence) @@ -42,7 +43,7 @@ (synthesis.i64 subject))) (run (..sanitize <extension>)) (case> (#try.Success valueT) - (n/= (<reference> param subject) (:coerce Nat valueT)) + (n.= (<reference> param subject) (:coerce Nat valueT)) (#try.Failure _) false) @@ -51,8 +52,8 @@ ["lux i64 and" i64.and param] ["lux i64 or" i64.or param] ["lux i64 xor" i64.xor param] - ["lux i64 left-shift" i64.left-shift (n/% 64 param)] - ["lux i64 logical-right-shift" i64.logic-right-shift (n/% 64 param)] + ["lux i64 left-shift" i64.left-shift (n.% 64 param)] + ["lux i64 logical-right-shift" i64.logic-right-shift (n.% 64 param)] )] ($_ _.and <binary> @@ -68,7 +69,7 @@ (#try.Failure _) false) - (let [param (n/% 64 param)]))) + (let [param (n.% 64 param)]))) )))) (def: (i64 run) @@ -91,7 +92,7 @@ ["lux i64 f64" Frac i.frac f.= subject] ["lux i64 char" Text (|>> (:coerce Nat) text.from-code) text@= (|> subject (:coerce Nat) - (n/% (i64.left-shift 8 1)) + (n.% (i64.left-shift 8 1)) (:coerce Int))] )) (~~ (template [<extension> <reference> <outputT> <comp>] @@ -117,7 +118,7 @@ (def: simple-frac (Random Frac) - (|> r.nat (:: r.monad map (|>> (n/% 1000) .int i.frac)))) + (|> r.nat (:: r.monad map (|>> (n.% 1000) .int i.frac)))) (def: (f64 run) (-> Runner Test) @@ -174,12 +175,12 @@ (def: (text run) (-> Runner Test) (do r.monad - [sample-size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 1)))) + [sample-size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 1)))) sample-lower (r.ascii/lower-alpha sample-size) sample-upper (r.ascii/upper-alpha sample-size) sample-alpha (|> (r.ascii/alpha sample-size) (r.filter (|>> (text@= sample-upper) not))) - char-idx (|> r.nat (:: @ map (n/% sample-size))) + char-idx (|> r.nat (:: @ map (n.% sample-size))) #let [sample-lowerS (synthesis.text sample-lower) sample-upperS (synthesis.text sample-upper) sample-alphaS (synthesis.text sample-alpha) @@ -216,7 +217,7 @@ (|> (#synthesis.Extension "lux text size" (list sample-lowerS)) (run (..sanitize "lux text size")) (case> (#try.Success valueV) - (n/= sample-size (:coerce Nat valueV)) + (n.= sample-size (:coerce Nat valueV)) _ false))) @@ -224,7 +225,7 @@ (|> (#synthesis.Extension "lux text size" (list concatenatedS)) (run (..sanitize "lux text size")) (case> (#try.Success valueV) - (n/= (n/* 2 sample-size) (:coerce Nat valueV)) + (n.= (n.* 2 sample-size) (:coerce Nat valueV)) _ false))) @@ -235,7 +236,7 @@ (run (..sanitize "lux text index")) (case> (^multi (#try.Success valueV) [(:coerce (Maybe Nat) valueV) (#.Some valueV)]) - (n/= 0 valueV) + (n.= 0 valueV) _ false)) @@ -245,7 +246,7 @@ (run (..sanitize "lux text index")) (case> (^multi (#try.Success valueV) [(:coerce (Maybe Nat) valueV) (#.Some valueV)]) - (n/= sample-size valueV) + (n.= sample-size valueV) _ false)))) @@ -264,7 +265,7 @@ false))))] (_.test "Can clip text to extract sub-text." (and (test-clip 0 sample-size sample-lower) - (test-clip sample-size (n/* 2 sample-size) sample-upper)))) + (test-clip sample-size (n.* 2 sample-size) sample-upper)))) (_.test "Can extract individual characters from text." (|> (#synthesis.Extension "lux text char" (list sample-lowerS @@ -325,7 +326,7 @@ (run (..sanitize "lux io current-time")) (case> (#try.Success valueV) (let [[pre post] (:coerce [Nat Nat] valueV)] - (n/>= pre post)) + (n.>= pre post)) (#try.Failure _) false))) diff --git a/stdlib/source/spec/compositor/generation/function.lux b/stdlib/source/spec/compositor/generation/function.lux index 0b8810620..9af307287 100644 --- a/stdlib/source/spec/compositor/generation/function.lux +++ b/stdlib/source/spec/compositor/generation/function.lux @@ -7,6 +7,8 @@ [pipe (#+ case>)]] [data ["." maybe] + [number + ["n" nat]] [collection ["." list ("#@." functor)]]] [math @@ -25,11 +27,11 @@ (def: arity (Random Arity) - (|> r.nat (r@map (|>> (n/% max-arity) (n/max 1))))) + (|> r.nat (r@map (|>> (n.% max-arity) (n.max 1))))) (def: (local arity) (-> Arity (Random Register)) - (|> r.nat (r@map (|>> (n/% arity) inc)))) + (|> r.nat (r@map (|>> (n.% arity) inc)))) (def: function (Random [Arity Register Synthesis]) @@ -46,7 +48,7 @@ (-> Runner Test) (do r.monad [[arity local functionS] ..function - partial-arity (|> r.nat (:: @ map (|>> (n/% arity) (n/max 1)))) + partial-arity (|> r.nat (:: @ map (|>> (n.% arity) (n.max 1)))) inputs (r.list arity r.safe-frac) #let [expectation (maybe.assume (list.nth (dec local) inputs)) inputsS (list@map (|>> synthesis.f64) inputs)]] @@ -57,7 +59,7 @@ (run "with-local") (//case.verify expectation))) (_.test "Can partially apply functions." - (or (n/= 1 arity) + (or (n.= 1 arity) (let [preS (list.take partial-arity inputsS) postS (list.drop partial-arity inputsS) partialS (synthesis.function/apply {#synthesis.function functionS @@ -67,14 +69,14 @@ (run "partial-application") (//case.verify expectation))))) (_.test "Can read environment." - (or (n/= 1 arity) + (or (n.= 1 arity) (let [environment (|> partial-arity (list.n/range 1) (list@map (|>> #reference.Local))) - variableS (if (n/<= partial-arity local) + variableS (if (n.<= partial-arity local) (synthesis.variable/foreign (dec local)) - (synthesis.variable/local (|> local (n/- partial-arity)))) - inner-arity (n/- partial-arity arity) + (synthesis.variable/local (|> local (n.- partial-arity)))) + inner-arity (n.- partial-arity arity) innerS (synthesis.function/abstraction {#synthesis.environment environment #synthesis.arity inner-arity diff --git a/stdlib/source/spec/compositor/generation/reference.lux b/stdlib/source/spec/compositor/generation/reference.lux index a5e75b590..5da59d0b4 100644 --- a/stdlib/source/spec/compositor/generation/reference.lux +++ b/stdlib/source/spec/compositor/generation/reference.lux @@ -8,6 +8,7 @@ ["." try]] [data [number + ["n" nat] ["f" frac]]] [tool [compiler @@ -39,7 +40,7 @@ (def: (variable run) (-> Runner Test) (do r.monad - [register (|> r.nat (:: @ map (n/% 100))) + [register (|> r.nat (:: @ map (n.% 100))) expected r.safe-frac] (_.test "Local variables." (|> (synthesis.branch/let [(synthesis.f64 expected) diff --git a/stdlib/source/spec/compositor/generation/structure.lux b/stdlib/source/spec/compositor/generation/structure.lux index a93b27086..0697e5338 100644 --- a/stdlib/source/spec/compositor/generation/structure.lux +++ b/stdlib/source/spec/compositor/generation/structure.lux @@ -9,6 +9,7 @@ [data ["." maybe] [number + ["n" nat] ["i" int]] ["." text ("#@." equivalence) ["%" format (#+ format)]] @@ -30,9 +31,9 @@ (def: (variant run) (-> Runner Test) (do r.monad - [num-tags (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) - tag-in (|> r.nat (:: @ map (n/% num-tags))) - #let [last?-in (|> num-tags dec (n/= tag-in))] + [num-tags (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) + tag-in (|> r.nat (:: @ map (n.% num-tags))) + #let [last?-in (|> num-tags dec (n.= tag-in))] value-in r.i64] (_.test (%.name (name-of synthesis.variant)) (|> (synthesis.variant {#analysis.lefts (if last?-in @@ -43,11 +44,11 @@ (run "variant") (case> (#try.Success valueT) (let [valueT (:coerce (Array Any) valueT)] - (and (n/= 3 (array.size valueT)) + (and (n.= 3 (array.size valueT)) (let [tag-out (:coerce java/lang/Integer (maybe.assume (array.read 0 valueT))) last?-out (array.read 1 valueT) value-out (:coerce Any (maybe.assume (array.read 2 valueT))) - same-tag? (|> tag-out host.int-to-long (:coerce Nat) (n/= tag-in)) + same-tag? (|> tag-out host.int-to-long (:coerce Nat) (n.= tag-in)) same-flag? (case last?-out (#.Some last?-out') (and last?-in (text@= "" (:coerce Text last?-out'))) @@ -65,14 +66,14 @@ (def: (tuple run) (-> Runner Test) (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) + [size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) tuple-in (r.list size r.i64)] (_.test (%.name (name-of synthesis.tuple)) (|> (synthesis.tuple (list@map (|>> synthesis.i64) tuple-in)) (run "tuple") (case> (#try.Success tuple-out) (let [tuple-out (:coerce (Array Any) tuple-out)] - (and (n/= size (array.size tuple-out)) + (and (n.= size (array.size tuple-out)) (list.every? (function (_ [left right]) (i.= left (:coerce Int right))) (list.zip2 tuple-in (array.to-list tuple-out))))) diff --git a/stdlib/source/test/licentia.lux b/stdlib/source/test/licentia.lux index 7f623d26d..61bdbb0b2 100644 --- a/stdlib/source/test/licentia.lux +++ b/stdlib/source/test/licentia.lux @@ -7,9 +7,9 @@ [data ["." bit ("#;." equivalence)] ["." maybe ("#;." functor)] - [number - ["." nat ("#;." interval)]] ["." text] + [number + ["n" nat ("#@." interval)]] [collection ["." list ("#;." functor)]]] [math @@ -43,11 +43,11 @@ (def: period (Random (Period Nat)) (do r.monad - [start (r.filter (|>> (n/= nat;top) not) + [start (r.filter (|>> (n.= n@top) not) r.nat) - #let [wiggle-room (n/- start nat;top)] + #let [wiggle-room (n.- start n@top)] end (:: @ map - (|>> (n/% wiggle-room) (n/max 1)) + (|>> (n.% wiggle-room) (n.max 1)) r.nat)] (wrap {#time.start start #time.end end}))) @@ -105,7 +105,7 @@ (def: (variable-list max-size gen-element) (All [a] (-> Nat (Random a) (Random (List a)))) (do r.monad - [amount (:: @ map (n/% (n/max 1 max-size)) + [amount (:: @ map (n.% (n.max 1 max-size)) r.nat)] (r.list amount gen-element))) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 580c02d2e..e99cdb85a 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -20,6 +20,7 @@ ["." name] [number ["." i64] + ["n" nat] ["i" int] ["r" rev] ["f" frac]]] @@ -157,11 +158,11 @@ [value random.i64] ($_ _.and (_.test "'inc' and 'dec' are opposites." - (and (|> value inc dec (n/= value)) - (|> value dec inc (n/= value)))) + (and (|> value inc dec (n.= value)) + (|> value dec inc (n.= value)))) (_.test "'inc' and 'dec' shift the number by 1." - (and (|> (inc value) (n/- value) (n/= 1)) - (|> value (n/- (dec value)) (n/= 1))))))) + (and (|> (inc value) (n.- value) (n.= 1)) + (|> value (n.- (dec value)) (n.= 1))))))) (def: (check-neighbors has-property? value) (All [a] (-> (Predicate (I64 a)) (I64 a) Bit)) @@ -230,15 +231,15 @@ Test ($_ _.and (do random.monad - [factor (random@map (|>> (n/% 10) (n/max 1)) random.nat) - iterations (random@map (n/% 100) random.nat) - #let [expected (n/* factor iterations)]] + [factor (random@map (|>> (n.% 10) (n.max 1)) random.nat) + iterations (random@map (n.% 100) random.nat) + #let [expected (n.* factor iterations)]] (_.test "Can write loops." - (n/= expected + (n.= expected (loop [counter 0 value 0] - (if (n/< iterations counter) - (recur (inc counter) (n/+ factor value)) + (if (n.< iterations counter) + (recur (inc counter) (n.+ factor value)) value))))) (do random.monad @@ -248,32 +249,32 @@ (_.test "Can create lists easily through macros." (and (case (list first second third) (#.Cons first' (#.Cons second' (#.Cons third' #.Nil))) - (and (n/= first first') - (n/= second second') - (n/= third third')) + (and (n.= first first') + (n.= second second') + (n.= third third')) _ false) (case (list& first (list second third)) (#.Cons first' (#.Cons second' (#.Cons third' #.Nil))) - (and (n/= first first') - (n/= second second') - (n/= third third')) + (and (n.= first first') + (n.= second second') + (n.= third third')) _ false) (case (list& first second (list third)) (#.Cons first' (#.Cons second' (#.Cons third' #.Nil))) - (and (n/= first first') - (n/= second second') - (n/= third third')) + (and (n.= first first') + (n.= second second') + (n.= third third')) _ false)))) )) (template: (quadrance cat0 cat1) - (n/+ (n/* cat0 cat0) (n/* cat1 cat1))) + (n.+ (n.* cat0 cat0) (n.* cat1 cat1))) (def: templates Test @@ -281,7 +282,7 @@ [cat0 random.nat cat1 random.nat] (_.test "Template application is a stand-in for the templated code." - (n/= (n/+ (n/* cat0 cat0) (n/* cat1 cat1)) + (n.= (n.+ (n.* cat0 cat0) (n.* cat1 cat1)) (quadrance cat0 cat1))))) (def: cross-platform-support @@ -292,11 +293,11 @@ on-valid-host random.nat] ($_ _.and (_.test "Can provide default in case there is no particular host/platform support." - (n/= on-default + (n.= on-default (for {"" on-fake-host} on-default))) (_.test "Can pick code depending on the host/platform being targeted." - (n/= on-valid-host + (n.= on-valid-host (`` (for {(~~ (static @.old)) on-valid-host (~~ (static @.jvm)) on-valid-host (~~ (static @.js)) on-valid-host} @@ -312,7 +313,7 @@ (<| (_.context "Even or odd.") ($_ _.and (<| (_.context "Natural numbers.") - (..even-or-odd random.nat n/even? n/odd?)) + (..even-or-odd random.nat n.even? n.odd?)) (<| (_.context "Integers.") (..even-or-odd random.int i.even? i.odd?)))) (<| (_.context "Minimum and maximum.") @@ -322,7 +323,7 @@ (..minimum-and-maximum <gen> <=> [<lt> <min>] [<gt> <max>]))] [i.= i.< i.min i.> i.max random.int "Integers."] - [n/= n/< n/min n/> n/max random.nat "Natural numbers."] + [n.= n.< n.min n.> n.max random.nat "Natural numbers."] [r.= r.< r.min r.> r.max random.rev "Revolutions."] [f.= f.< f.min f.> f.max random.safe-frac "Fractions."] ))))) @@ -334,7 +335,7 @@ (..conversion <gen> <forward> <backward> <=>))] [i.= .nat .int (random@map (i.% +1,000,000) random.int)] - [n/= .int .nat (random@map (n/% 1,000,000) random.nat)] + [n.= .int .nat (random@map (n.% 1,000,000) random.nat)] [i.= i.frac f.int (random@map (i.% +1,000,000) random.int)] [f.= f.int i.frac (random@map (|>> (i.% +1,000,000) i.frac) random.int)] [r.= r.frac f.rev frac-rev] diff --git a/stdlib/source/test/lux/abstract/apply.lux b/stdlib/source/test/lux/abstract/apply.lux index b2d67d3e9..87c706f55 100644 --- a/stdlib/source/test/lux/abstract/apply.lux +++ b/stdlib/source/test/lux/abstract/apply.lux @@ -2,6 +2,8 @@ [lux #* [abstract/monad (#+ do)] [data + [number + ["n" nat]] [text ["%" format (#+ format)]]] [control @@ -19,7 +21,7 @@ (do r.monad [sample (:: @ map injection r.nat)] (_.test "Identity." - ((comparison n/=) + ((comparison n.=) (_;apply (injection function.identity) sample) sample)))) @@ -27,9 +29,9 @@ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test)) (do r.monad [sample r.nat - increase (:: @ map n/+ r.nat)] + increase (:: @ map n.+ r.nat)] (_.test "Homomorphism." - ((comparison n/=) + ((comparison n.=) (_;apply (injection increase) (injection sample)) (injection (increase sample)))))) @@ -37,9 +39,9 @@ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test)) (do r.monad [sample r.nat - increase (:: @ map n/+ r.nat)] + increase (:: @ map n.+ r.nat)] (_.test "Interchange." - ((comparison n/=) + ((comparison n.=) (_;apply (injection increase) (injection sample)) (_;apply (injection (function (_ f) (f sample))) (injection increase)))))) @@ -47,10 +49,10 @@ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test)) (do r.monad [sample r.nat - increase (:: @ map n/+ r.nat) - decrease (:: @ map n/- r.nat)] + increase (:: @ map n.+ r.nat) + decrease (:: @ map n.- r.nat)] (_.test "Composition." - ((comparison n/=) + ((comparison n.=) (_$ _;apply (injection function.compose) (injection increase) diff --git a/stdlib/source/test/lux/abstract/fold.lux b/stdlib/source/test/lux/abstract/fold.lux index 99ac25c5b..334d43e50 100644 --- a/stdlib/source/test/lux/abstract/fold.lux +++ b/stdlib/source/test/lux/abstract/fold.lux @@ -3,7 +3,10 @@ ["_" test (#+ Test)] ["%" data/text/format (#+ format)] ["r" math/random] - [abstract/monad (#+ do)]] + [abstract/monad (#+ do)] + [data + [number + ["n" nat]]]] [// [functor (#+ Injection Comparison)]] {1 @@ -16,5 +19,5 @@ [subject r.nat parameter r.nat] (_.test "Can fold." - (n/= (/@fold n/+ parameter (injection subject)) - (n/+ parameter subject)))))) + (n.= (/@fold n.+ parameter (injection subject)) + (n.+ parameter subject)))))) diff --git a/stdlib/source/test/lux/abstract/functor.lux b/stdlib/source/test/lux/abstract/functor.lux index 4c7c87c63..388a66ffc 100644 --- a/stdlib/source/test/lux/abstract/functor.lux +++ b/stdlib/source/test/lux/abstract/functor.lux @@ -7,7 +7,10 @@ [equivalence (#+ Equivalence)] [monad (#+ do)]] [control - ["." function]]] + ["." function]] + [data + [number + ["n" nat]]]] {1 ["." / (#+ Functor)]}) @@ -24,7 +27,7 @@ (do r.monad [sample (:: @ map injection r.nat)] (_.test "Identity." - ((comparison n/=) + ((comparison n.=) (/@map function.identity sample) sample)))) @@ -32,9 +35,9 @@ (All [f] (-> (Injection f) (Comparison f) (Functor f) Test)) (do r.monad [sample r.nat - increase (:: @ map n/+ r.nat)] + increase (:: @ map n.+ r.nat)] (_.test "Homomorphism." - ((comparison n/=) + ((comparison n.=) (/@map increase (injection sample)) (injection (increase sample)))))) @@ -42,10 +45,10 @@ (All [f] (-> (Injection f) (Comparison f) (Functor f) Test)) (do r.monad [sample (:: @ map injection r.nat) - increase (:: @ map n/+ r.nat) - decrease (:: @ map n/- r.nat)] + increase (:: @ map n.+ r.nat) + decrease (:: @ map n.- r.nat)] (_.test "Composition." - ((comparison n/=) + ((comparison n.=) (|> sample (/@map increase) (/@map decrease)) (|> sample (/@map (|>> increase decrease))))))) diff --git a/stdlib/source/test/lux/abstract/interval.lux b/stdlib/source/test/lux/abstract/interval.lux index e4a489822..92f2a6faf 100644 --- a/stdlib/source/test/lux/abstract/interval.lux +++ b/stdlib/source/test/lux/abstract/interval.lux @@ -11,7 +11,7 @@ [pipe (#+ case>)]] [data [number - ["." nat]] + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -27,20 +27,20 @@ (Random (Interval Nat)) (do r.monad [bottom r.nat - top (|> r.nat (r.filter (|>> (n/= bottom) not)))] + top (|> r.nat (r.filter (|>> (n.= bottom) not)))] (if (<cmp> top bottom) - (wrap (/.between nat.enum bottom top)) - (wrap (/.between nat.enum top bottom)))))] + (wrap (/.between n.enum bottom top)) + (wrap (/.between n.enum top bottom)))))] - [inner n/<] - [outer n/>] + [inner n.<] + [outer n.>] ) (def: #export singleton (Random (Interval Nat)) (do r.monad [point r.nat] - (wrap (/.singleton nat.enum point)))) + (wrap (/.singleton n.enum point)))) (def: #export interval (Random (Interval Nat)) @@ -54,7 +54,7 @@ (do r.monad [bottom r.nat top r.nat - #let [interval (/.between nat.enum bottom top)]] + #let [interval (/.between n.enum bottom top)]] ($_ _.and (_.test "A boundary value belongs to its interval." (and (/.within? interval bottom) @@ -124,16 +124,16 @@ (def: location Test (do r.monad - [[l m r] (|> (r.set nat.hash 3 r.nat) + [[l m r] (|> (r.set n.hash 3 r.nat) (:: @ map (|>> set.to-list - (list.sort n/<) + (list.sort n.<) (case> (^ (list b t1 t2)) [b t1 t2] _ (undefined))))) - #let [left (/.singleton nat.enum l) - right (/.singleton nat.enum r)]] + #let [left (/.singleton n.enum l) + right (/.singleton n.enum r)]] ($_ _.and (_.test "'precedes?' and 'succeeds?' are symetric." (and (/.precedes? right left) @@ -146,36 +146,36 @@ (def: touch Test (do r.monad - [[b t1 t2] (|> (r.set nat.hash 3 r.nat) + [[b t1 t2] (|> (r.set n.hash 3 r.nat) (:: @ map (|>> set.to-list - (list.sort n/<) + (list.sort n.<) (case> (^ (list b t1 t2)) [b t1 t2] _ (undefined))))) - #let [int-left (/.between nat.enum t1 t2) - int-right (/.between nat.enum b t1)]] + #let [int-left (/.between n.enum t1 t2) + int-right (/.between n.enum b t1)]] ($_ _.and (_.test "An interval meets another if its top is the other's bottom." (/.meets? int-left int-right)) (_.test "Two intervals touch one another if any one meets the other." (/.touches? int-left int-right)) (_.test "Can check if 2 intervals start together." - (/.starts? (/.between nat.enum b t2) - (/.between nat.enum b t1))) + (/.starts? (/.between n.enum b t2) + (/.between n.enum b t1))) (_.test "Can check if 2 intervals finish together." - (/.finishes? (/.between nat.enum b t2) - (/.between nat.enum t1 t2))) + (/.finishes? (/.between n.enum b t2) + (/.between n.enum t1 t2))) ))) (def: overlap Test (do r.monad [some-interval ..interval - [x0 x1 x2 x3] (|> (r.set nat.hash 4 r.nat) + [x0 x1 x2 x3] (|> (r.set n.hash 4 r.nat) (:: @ map (|>> set.to-list - (list.sort n/<) + (list.sort n.<) (case> (^ (list x0 x1 x2 x3)) [x0 x1 x2 x3] @@ -186,30 +186,30 @@ (/.nested? some-interval some-interval)) (_.test "No interval overlaps with itself." (not (/.overlaps? some-interval some-interval))) - (let [small-inner (/.between nat.enum x1 x2) - large-inner (/.between nat.enum x0 x3)] + (let [small-inner (/.between n.enum x1 x2) + large-inner (/.between n.enum x0 x3)] (_.test "Inner intervals can be nested inside one another." (and (/.nested? large-inner small-inner) (not (/.nested? small-inner large-inner))))) - (let [left-inner (/.between nat.enum x0 x2) - right-inner (/.between nat.enum x1 x3)] + (let [left-inner (/.between n.enum x0 x2) + right-inner (/.between n.enum x1 x3)] (_.test "Inner intervals can overlap one another." (and (/.overlaps? left-inner right-inner) (/.overlaps? right-inner left-inner)))) - (let [small-outer (/.between nat.enum x2 x1) - large-outer (/.between nat.enum x3 x0)] + (let [small-outer (/.between n.enum x2 x1) + large-outer (/.between n.enum x3 x0)] (_.test "Outer intervals can be nested inside one another." (and (/.nested? small-outer large-outer) (not (/.nested? large-outer small-outer))))) - (let [left-inner (/.between nat.enum x0 x1) - right-inner (/.between nat.enum x2 x3) - outer (/.between nat.enum x0 x3)] + (let [left-inner (/.between n.enum x0 x1) + right-inner (/.between n.enum x2 x3) + outer (/.between n.enum x0 x3)] (_.test "Inners can be nested inside outers." (and (/.nested? outer left-inner) (/.nested? outer right-inner)))) - (let [left-inner (/.between nat.enum x0 x2) - right-inner (/.between nat.enum x1 x3) - outer (/.between nat.enum x1 x2)] + (let [left-inner (/.between n.enum x0 x2) + right-inner (/.between n.enum x1 x3) + outer (/.between n.enum x1 x2)] (_.test "Inners can overlap outers." (and (/.overlaps? outer left-inner) (/.overlaps? outer right-inner)))) diff --git a/stdlib/source/test/lux/abstract/monad.lux b/stdlib/source/test/lux/abstract/monad.lux index c420d6416..ecb292afb 100644 --- a/stdlib/source/test/lux/abstract/monad.lux +++ b/stdlib/source/test/lux/abstract/monad.lux @@ -1,6 +1,8 @@ (.module: [lux #* [data + [number + ["n" nat]] [text ["%" format (#+ format)]]] [control @@ -18,10 +20,10 @@ (do r.monad [sample r.nat morphism (:: @ map (function (_ diff) - (|>> (n/+ diff) _;wrap)) + (|>> (n.+ diff) _;wrap)) r.nat)] (_.test "Left identity." - ((comparison n/=) + ((comparison n.=) (|> (injection sample) (_;map morphism) _;join) (morphism sample))))) @@ -30,7 +32,7 @@ (do r.monad [sample r.nat] (_.test "Right identity." - ((comparison n/=) + ((comparison n.=) (|> (injection sample) (_;map _;wrap) _;join) (injection sample))))) @@ -39,13 +41,13 @@ (do r.monad [sample r.nat increase (:: @ map (function (_ diff) - (|>> (n/+ diff) _;wrap)) + (|>> (n.+ diff) _;wrap)) r.nat) decrease (:: @ map (function (_ diff) - (|>> (n/- diff) _;wrap)) + (|>> (n.- diff) _;wrap)) r.nat)] (_.test "Associativity." - ((comparison n/=) + ((comparison n.=) (|> (injection sample) (_;map increase) _;join (_;map decrease) _;join) (|> (injection sample) (_;map (|>> increase (_;map decrease) _;join)) _;join))))) diff --git a/stdlib/source/test/lux/control/concurrency/actor.lux b/stdlib/source/test/lux/control/concurrency/actor.lux index cc7456292..cde83e09d 100644 --- a/stdlib/source/test/lux/control/concurrency/actor.lux +++ b/stdlib/source/test/lux/control/concurrency/actor.lux @@ -7,6 +7,8 @@ ["ex" exception] ["." io (#+ IO io)]] [data + [number + ["n" nat]] [text ["%" format (#+ format)]]] [math @@ -33,7 +35,7 @@ (message: #export Counter (count! {increment Nat} state self Nat) - (let [state' (n/+ increment state)] + (let [state' (n.+ increment state)] (promise;wrap (#try.Success [state' state'])))) (def: #export test @@ -69,9 +71,9 @@ output-1 (count! 1 counter) output-2 (count! 1 counter) output-3 (count! 1 counter)] - (wrap (and (n/= 1 output-1) - (n/= 2 output-2) - (n/= 3 output-3))))] + (wrap (and (n.= 1 output-1) + (n.= 2 output-2) + (n.= 3 output-3))))] (_.assert "Can send messages to actors." (case result (#try.Success outcome) diff --git a/stdlib/source/test/lux/control/concurrency/atom.lux b/stdlib/source/test/lux/control/concurrency/atom.lux index 15d24b826..1cf645530 100644 --- a/stdlib/source/test/lux/control/concurrency/atom.lux +++ b/stdlib/source/test/lux/control/concurrency/atom.lux @@ -6,7 +6,10 @@ [math ["r" random]] [control - ["." io]]] + ["." io]] + [data + [number + ["n" nat]]]] {1 ["." /]}) @@ -20,17 +23,17 @@ #let [box (/.atom value)]] ($_ _.and (_.test "Can obtain the value of an atom." - (n/= value (io.run (/.read box)))) + (n.= value (io.run (/.read box)))) (_.test "Can swap the value of an atom." (and (io.run (/.compare-and-swap value swap-value box)) - (n/= swap-value (io.run (/.read box))))) + (n.= swap-value (io.run (/.read box))))) (_.test "Can update the value of an atom." (exec (io.run (/.update inc box)) - (n/= (inc swap-value) (io.run (/.read box))))) + (n.= (inc swap-value) (io.run (/.read box))))) (_.test "Can immediately set the value of an atom." (exec (io.run (/.write set-value box)) - (n/= set-value (io.run (/.read box))))) + (n.= set-value (io.run (/.read box))))) )))) diff --git a/stdlib/source/test/lux/control/concurrency/frp.lux b/stdlib/source/test/lux/control/concurrency/frp.lux index f9cea5737..ab705bfce 100644 --- a/stdlib/source/test/lux/control/concurrency/frp.lux +++ b/stdlib/source/test/lux/control/concurrency/frp.lux @@ -6,7 +6,7 @@ ["." io (#+ IO io)]] [data [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." functor)]]] [math @@ -19,7 +19,7 @@ (def: #export test Test - (let [(^open "list@.") (list.equivalence nat.equivalence)] + (let [(^open "list@.") (list.equivalence n.equivalence)] (do r.monad [inputs (r.list 5 r.nat) sample r.nat] @@ -27,10 +27,10 @@ (wrap (do promise.monad [output (|> inputs (/.sequential 0) - (/.filter n/even?) + (/.filter n.even?) /.consume)] (_.assert "Can filter a channel's elements." - (list@= (list.filter n/even? inputs) + (list@= (list.filter n.even? inputs) output)))) (wrap (do promise.monad [output (|> inputs diff --git a/stdlib/source/test/lux/control/concurrency/semaphore.lux b/stdlib/source/test/lux/control/concurrency/semaphore.lux index 05329d9f0..bd5d72d43 100644 --- a/stdlib/source/test/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/test/lux/control/concurrency/semaphore.lux @@ -10,6 +10,8 @@ ["." atom (#+ Atom)]]] [data ["." maybe] + [number + ["n" nat]] ["." text ("#;." equivalence monoid) ["%" format (#+ format)]] [collection @@ -21,7 +23,7 @@ ## (def: (wait-many-times times semaphore) ## (-> Nat /.Semaphore (Promise Any)) ## (loop [steps times] -## (if (n/> 0 steps) +## (if (n.> 0 steps) ## (do promise.monad ## [_ (/.wait semaphore)] ## (recur (dec steps))) @@ -30,7 +32,7 @@ ## (context: "Semaphore." ## (<| (times 100) ## (do @ -## [open-positions (|> r.nat (:: @ map (|>> (n/% 10) (n/max 1))))] +## [open-positions (|> r.nat (:: @ map (|>> (n.% 10) (n.max 1))))] ## ($_ seq ## (let [semaphore (/.semaphore open-positions)] ## (wrap (do promise.monad @@ -51,8 +53,8 @@ ## (let [semaphore (/.semaphore open-positions)] ## (wrap (do promise.monad ## [_ (: (Promise Any) -## (loop [steps (n/* 2 open-positions)] -## (if (n/> 0 steps) +## (loop [steps (n.* 2 open-positions)] +## (if (n.> 0 steps) ## (do @ ## [_ (/.wait semaphore) ## _ (/.signal semaphore)] @@ -82,7 +84,7 @@ ## (context: "Mutex." ## (<| (times 100) ## (do @ -## [repetitions (|> r.nat (:: @ map (|>> (n/% 100) (n/max 10))))] +## [repetitions (|> r.nat (:: @ map (|>> (n.% 100) (n.max 10))))] ## ($_ seq ## (let [mutex (/.mutex [])] ## (wrap (do promise.monad diff --git a/stdlib/source/test/lux/control/concurrency/stm.lux b/stdlib/source/test/lux/control/concurrency/stm.lux index ca9d3c050..c84663a96 100644 --- a/stdlib/source/test/lux/control/concurrency/stm.lux +++ b/stdlib/source/test/lux/control/concurrency/stm.lux @@ -7,7 +7,7 @@ [data ["%" text/format (#+ format)] [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." functor)]]] [math @@ -43,29 +43,29 @@ (wrap (do promise.monad [output (/.commit (/.read (/.var 0)))] (_.assert "Can read STM vars." - (n/= 0 output)))) + (n.= 0 output)))) (wrap (do promise.monad [#let [_var (/.var 0)] output (/.commit (do /.monad [_ (/.write 5 _var)] (/.read _var)))] (_.assert "Can write STM vars." - (n/= 5 output)))) + (n.= 5 output)))) (wrap (do promise.monad [#let [_var (/.var 5)] output (/.commit (do /.monad - [_ (/.update (n/* 3) _var)] + [_ (/.update (n.* 3) _var)] (/.read _var)))] (_.assert "Can update STM vars." - (n/= 15 output)))) + (n.= 15 output)))) (wrap (do promise.monad [#let [_var (/.var 0) changes (io.run (read! (io.run (/.follow _var))))] _ (/.commit (/.write 5 _var)) - _ (/.commit (/.update (n/* 3) _var)) + _ (/.commit (/.update (n.* 3) _var)) changes (promise.future (atom.read changes))] (_.assert "Can follow all the changes to STM vars." - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = (list 5 15) (list.reverse changes))))) (wrap (let [_concurrency-var (/.var 0)] @@ -80,5 +80,5 @@ last-val (/.commit (/.read _concurrency-var))] (_.assert "Can modify STM vars concurrently from multiple threads." (|> process.parallelism - (n/* iterations-per-process) - (n/= last-val)))))))))) + (n.* iterations-per-process) + (n.= last-val)))))))))) diff --git a/stdlib/source/test/lux/control/continuation.lux b/stdlib/source/test/lux/control/continuation.lux index b8d4b96d2..105dccd3f 100644 --- a/stdlib/source/test/lux/control/continuation.lux +++ b/stdlib/source/test/lux/control/continuation.lux @@ -10,7 +10,7 @@ ["$." monad]]}] [data [number - ["." nat]] + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -43,10 +43,10 @@ ($monad.spec ..injection ..comparison /.monad) (_.test "Can run continuations to compute their values." - (n/= sample (/.run (_;wrap sample)))) + (n.= sample (/.run (_;wrap sample)))) (_.test "Can use the current-continuation as a escape hatch." - (n/= (n/* 2 sample) + (n.= (n.* 2 sample) (/.run (do /.monad [value (/.call/cc (function (_ k) @@ -54,21 +54,21 @@ [temp (k sample)] ## If this code where to run, ## the output would be - ## (n/* 4 sample) + ## (n.* 4 sample) (k temp))))] - (wrap (n/* 2 value)))))) + (wrap (n.* 2 value)))))) (_.test "Can use the current-continuation to build a time machine." - (n/= (n/+ 100 sample) + (n.= (n.+ 100 sample) (/.run (do /.monad [[restart [output idx]] (/.portal [sample 0])] - (if (n/< 10 idx) - (restart [(n/+ 10 output) (inc idx)]) + (if (n.< 10 idx) + (restart [(n.+ 10 output) (inc idx)]) (wrap output)))))) (_.test "Can use delimited continuations with shifting." (let [(^open "_;.") /.monad - (^open "list;.") (list.equivalence nat.equivalence) + (^open "list;.") (list.equivalence n.equivalence) visit (: (-> (List Nat) (Cont (List Nat) (List Nat))) (function (visit xs) diff --git a/stdlib/source/test/lux/control/exception.lux b/stdlib/source/test/lux/control/exception.lux index 46d495a4b..fde485472 100644 --- a/stdlib/source/test/lux/control/exception.lux +++ b/stdlib/source/test/lux/control/exception.lux @@ -2,6 +2,8 @@ [lux #* [abstract/monad (#+ do)] [data + [number + ["n" nat]] [text ["%" format (#+ format)]]] [math @@ -16,22 +18,22 @@ (def: #export test (do r.monad [right r.nat - wrong (r.filter (|>> (n/= right) not) r.nat)] + wrong (r.filter (|>> (n.= right) not) r.nat)] (<| (_.context (%.name (name-of /.Exception))) ($_ _.and (_.test "Can catch exceptions." - (n/= right + (n.= right (|> (/.throw an-exception []) (/.catch an-exception (function (_ ex) right)) (/.otherwise (function (_ ex) wrong))))) (_.test "Can catch multiple exceptions." - (n/= right + (n.= right (|> (/.throw another-exception []) (/.catch an-exception (function (_ ex) wrong)) (/.catch another-exception (function (_ ex) right)) (/.otherwise (function (_ ex) wrong))))) (_.test "Can handle uncaught exceptions." - (n/= right + (n.= right (|> (/.throw another-exception []) (/.catch an-exception (function (_ ex) wrong)) (/.otherwise (function (_ ex) right))))))))) diff --git a/stdlib/source/test/lux/control/io.lux b/stdlib/source/test/lux/control/io.lux index 4e000d39c..fb5d3e67b 100644 --- a/stdlib/source/test/lux/control/io.lux +++ b/stdlib/source/test/lux/control/io.lux @@ -9,7 +9,10 @@ [/ ["$." functor (#+ Injection Comparison)] ["$." apply] - ["$." monad]]}]] + ["$." monad]]}] + [data + [number + ["n" nat]]]] {1 ["." / (#+ IO) [// @@ -36,7 +39,7 @@ ($monad.spec ..injection ..comparison /.monad) (_.test "Can execute computations designated as I/O computations." - (n/= sample (/.run (/.io sample)))) + (n.= sample (/.run (/.io sample)))) (_.test "I/O operations won't execute unless they are explicitly run." (exec (/.exit exit-code) true)))))) diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index fc8de4828..58a35ae02 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -15,7 +15,7 @@ ["s" code]]] [data [number - ["." nat]] + ["n" nat]] ["." text ("#;." equivalence) ["%" format (#+ format)]] [collection @@ -76,17 +76,17 @@ Test (do r.monad [expected0 r.nat - variadic (:: @ map (|>> (n/max 1) (n/min 20)) r.nat) + variadic (:: @ map (|>> (n.max 1) (n.min 20)) r.nat) expected+ (r.list variadic r.nat) - even0 (r.filter n/even? r.nat) - odd0 (r.filter n/odd? r.nat) + even0 (r.filter n.even? r.nat) + odd0 (r.filter n.odd? r.nat) not0 r.bit] ($_ _.and (_.test "Can optionally succeed with some parser." (and (|> (list (code.nat expected0)) (/.run (/.maybe s.nat)) (match (#.Some actual) - (n/= expected0 actual))) + (n.= expected0 actual))) (|> (list (code.int (.int expected0))) (/.run (/.maybe s.nat)) (match #.None @@ -95,7 +95,7 @@ (and (|> (list;map code.nat expected+) (/.run (/.some s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = expected+ actual))) + (:: (list.equivalence n.equivalence) = expected+ actual))) (|> (list;map (|>> .int code.int) expected+) (/.run (/.some s.nat)) (match #.Nil @@ -104,23 +104,23 @@ (and (|> (list;map code.nat expected+) (/.run (/.many s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = expected+ actual))) + (:: (list.equivalence n.equivalence) = expected+ actual))) (|> (list (code.nat expected0)) (/.run (/.many s.nat)) (match (list actual) - (n/= expected0 actual))) + (n.= expected0 actual))) (|> (list;map (|>> .int code.int) expected+) (/.run (/.many s.nat)) fails?))) (_.test "Can use either parser." - (let [even (/.filter n/even? s.nat) - odd (/.filter n/odd? s.nat)] + (let [even (/.filter n.even? s.nat) + odd (/.filter n.odd? s.nat)] (and (|> (list (code.nat even0)) (/.run (/.either even odd)) - (match actual (n/= even0 actual))) + (match actual (n.= even0 actual))) (|> (list (code.nat odd0)) (/.run (/.either even odd)) - (match actual (n/= odd0 actual))) + (match actual (n.= odd0 actual))) (|> (list (code.bit not0)) (/.run (/.either even odd)) fails?)))) @@ -137,8 +137,8 @@ Test (do r.monad [failure (r.ascii 1) - variadic (:: @ map (|>> (n/max 1) (n/min 20)) r.nat) - times (:: @ map (n/% variadic) r.nat) + variadic (:: @ map (|>> (n.max 1) (n.min 20)) r.nat) + times (:: @ map (n.% variadic) r.nat) expected+ (r.list variadic r.nat) separator (r.ascii 1)] ($_ _.and @@ -150,7 +150,7 @@ (and (|> (list;map code.nat expected+) (/.run (/.exactly times s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = (list.take times expected+) actual))) (|> (list;map code.nat expected+) @@ -160,7 +160,7 @@ (and (|> (list;map code.nat expected+) (/.run (/.at-least times s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = expected+ actual))) (|> (list;map code.nat expected+) @@ -170,33 +170,33 @@ (and (|> (list;map code.nat expected+) (/.run (/.at-most times s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = (list.take times expected+) actual))) (|> (list;map code.nat expected+) (/.run (/.at-most (inc variadic) s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = expected+ actual))))) (_.test "Can apply a parser between N and M times." (and (|> (list;map code.nat expected+) (/.run (/.between times variadic s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = expected+ actual))) (|> (list;map code.nat (list.take times expected+)) (/.run (/.between times variadic s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = (list.take times expected+) actual))))) (_.test "Can parse while taking separators into account." (|> (list.interpose (code.text separator) (list;map code.nat expected+)) (/.run (/.sep-by (s.this! (code.text separator)) s.nat)) (match actual - (:: (list.equivalence nat.equivalence) = + (:: (list.equivalence n.equivalence) = expected+ actual)))) (_.test "Can obtain the whole of the remaining input." diff --git a/stdlib/source/test/lux/control/parser/cli.lux b/stdlib/source/test/lux/control/parser/cli.lux index b304a2ab2..c41a33878 100644 --- a/stdlib/source/test/lux/control/parser/cli.lux +++ b/stdlib/source/test/lux/control/parser/cli.lux @@ -11,7 +11,7 @@ ["p" parser]] [data [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] ["." text ("#@." equivalence)] [collection ["." list]]]] @@ -22,8 +22,8 @@ Test (<| (_.context (name.module (name-of /._))) (do r.monad - [num-args (|> r.nat (:: @ map (n/% 10))) - #let [gen-arg (:: @ map nat@encode r.nat)] + [num-args (|> r.nat (:: @ map (n.% 10))) + #let [gen-arg (:: @ map n@encode r.nat)] yes gen-arg #let [gen-ignore (r.filter (|>> (text@= yes) not) (r.unicode 5))] @@ -52,12 +52,12 @@ (#try.Success _) #0)))) (_.test "Can use custom token parsers." - (|> (/.run (/.parse nat@decode) (list yes)) + (|> (/.run (/.parse n@decode) (list yes)) (case> (#try.Failure _) #0 (#try.Success parsed) - (text@= (nat@encode parsed) + (text@= (n@encode parsed) yes)))) (_.test "Can query if there are any more inputs." (and (|> (/.run /.end (list)) diff --git a/stdlib/source/test/lux/control/parser/text.lux b/stdlib/source/test/lux/control/parser/text.lux index 8917e63fa..441f2f5da 100644 --- a/stdlib/source/test/lux/control/parser/text.lux +++ b/stdlib/source/test/lux/control/parser/text.lux @@ -10,6 +10,8 @@ ["p" parser]] [data ["." text ("#@." equivalence)] + [number + ["n" nat]] [collection ["." list]]] [math @@ -41,7 +43,7 @@ "") (case> (#.Right _) true _ false))) (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 10)))) + [size (|> r.nat (:: @ map (|>> (n.% 100) (n.max 10)))) sample (r.unicode size) non-sample (|> (r.unicode size) (r.filter (|>> (text@= sample) not)))] diff --git a/stdlib/source/test/lux/control/pipe.lux b/stdlib/source/test/lux/control/pipe.lux index 4d4e03a79..0aecde080 100644 --- a/stdlib/source/test/lux/control/pipe.lux +++ b/stdlib/source/test/lux/control/pipe.lux @@ -6,6 +6,8 @@ [data ["." identity] ["." name] + [number + ["n" nat]] ["." text ("#@." equivalence) ["%" format (#+ format)]]] [math @@ -22,65 +24,65 @@ (do @ [another r.nat] (_.test "Can dismiss previous pipeline results and begin a new one." - (n/= (inc another) + (n.= (inc another) (|> sample - (n/* 3) - (n/+ 4) + (n.* 3) + (n.+ 4) (new> another [inc]))))) (_.test "Let-binding" - (n/= (n/+ sample sample) + (n.= (n.+ sample sample) (|> sample - (let> x [(n/+ x x)])))) + (let> x [(n.+ x x)])))) (_.test "'Conditional' branching." - (text@= (cond (n/= 0 sample) "zero" - (n/even? sample) "even" + (text@= (cond (n.= 0 sample) "zero" + (n.even? sample) "even" "odd") (|> sample - (cond> [(n/= 0)] [(new> "zero" [])] - [n/even?] [(new> "even" [])] + (cond> [(n.= 0)] [(new> "zero" [])] + [n.even?] [(new> "even" [])] [(new> "odd" [])])))) (_.test "'If' branching." - (text@= (if (n/even? sample) + (text@= (if (n.even? sample) "even" "odd") (|> sample - (if> [n/even?] + (if> [n.even?] [(new> "even" [])] [(new> "odd" [])])))) (_.test "'When' branching." - (n/= (if (n/even? sample) - (n/* 2 sample) + (n.= (if (n.even? sample) + (n.* 2 sample) sample) (|> sample - (when> [n/even?] - [(n/* 2)])))) + (when> [n.even?] + [(n.* 2)])))) (_.test "Can loop." - (n/= (n/* 10 sample) + (n.= (n.* 10 sample) (|> sample - (loop> [(n/= (n/* 10 sample)) not] - [(n/+ sample)])))) + (loop> [(n.= (n.* 10 sample)) not] + [(n.+ sample)])))) (_.test "Monads." - (n/= (inc (n/+ 4 (n/* 3 sample))) + (n.= (inc (n.+ 4 (n.* 3 sample))) (|> sample (do> identity.monad - [(n/* 3)] - [(n/+ 4)] + [(n.* 3)] + [(n.+ 4)] [inc])))) (_.test "Execution." - (n/= (n/* 10 sample) + (n.= (n.* 10 sample) (|> sample (exec> [%.nat (format "sample = ") log!]) - (n/* 10)))) + (n.* 10)))) (_.test "Tuple." (let [[left middle right] (|> sample (tuple> [inc] [dec] [%.nat]))] - (and (n/= (inc sample) left) - (n/= (dec sample) middle) + (and (n.= (inc sample) left) + (n.= (dec sample) middle) (text@= (%.nat sample) right)))) (_.test "Pattern-matching." - (text@= (case (n/% 10 sample) + (text@= (case (n.% 10 sample) 0 "zero" 1 "one" 2 "two" @@ -93,7 +95,7 @@ 9 "nine" _ "???") (|> sample - (n/% 10) + (n.% 10) (case> 0 "zero" 1 "one" 2 "two" diff --git a/stdlib/source/test/lux/control/reader.lux b/stdlib/source/test/lux/control/reader.lux index 49cb23a48..434ec5896 100644 --- a/stdlib/source/test/lux/control/reader.lux +++ b/stdlib/source/test/lux/control/reader.lux @@ -9,6 +9,8 @@ ["$." apply] ["$." monad]]}] [data + [number + ["n" nat]] [text ["%" format (#+ format)]]] [math @@ -40,18 +42,18 @@ ($monad.spec ..injection ..comparison /.monad) (_.test "Can query the environment." - (n/= sample + (n.= sample (/.run sample /.ask))) (_.test "Can modify an environment locally." - (n/= (n/* factor sample) - (/.run sample (/.local (n/* factor) /.ask)))) + (n.= (n.* factor sample) + (/.run sample (/.local (n.* factor) /.ask)))) (let [(^open "io@.") io.monad] (_.test "Can add reader functionality to any monad." (|> (: (/.Reader Any (IO Nat)) (do (/.with io.monad) [a (/.lift (io@wrap sample)) b (wrap factor)] - (wrap (n/* b a)))) + (wrap (n.* b a)))) (/.run []) io.run - (n/= (n/* factor sample))))))))) + (n.= (n.* factor sample))))))))) diff --git a/stdlib/source/test/lux/control/region.lux b/stdlib/source/test/lux/control/region.lux index 9ecf520c2..e7000fc48 100644 --- a/stdlib/source/test/lux/control/region.lux +++ b/stdlib/source/test/lux/control/region.lux @@ -6,6 +6,8 @@ [control ["." try (#+ Try)]] [data + [number + ["n" nat]] [text ["%" format (#+ format)]] [collection @@ -38,7 +40,7 @@ Test (<| (_.context (%.name (name-of /._))) (do r.monad - [expected-clean-ups (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1))))] + [expected-clean-ups (|> r.nat (:: @ map (|>> (n.% 100) (n.max 1))))] ($_ _.and (_.test "Clean-up functions are always run when region execution is done." (thread.run @@ -56,7 +58,7 @@ (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (success? outcome) - (n/= expected-clean-ups + (n.= expected-clean-ups actual-clean-ups)))))) (_.test "Can clean-up despite errors." (thread.run @@ -75,7 +77,7 @@ (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (failure? outcome) - (n/= expected-clean-ups + (n.= expected-clean-ups actual-clean-ups)))))) (_.test "Errors can propagate from the cleaners." (thread.run @@ -92,9 +94,9 @@ (list.n/range 1 expected-clean-ups))] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] - (wrap (and (or (n/= 0 expected-clean-ups) + (wrap (and (or (n.= 0 expected-clean-ups) (failure? outcome)) - (n/= expected-clean-ups + (n.= expected-clean-ups actual-clean-ups)))))) (_.test "Can lift operations." (thread.run @@ -107,6 +109,6 @@ (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (success? outcome) - (n/= expected-clean-ups + (n.= expected-clean-ups actual-clean-ups)))))) )))) diff --git a/stdlib/source/test/lux/control/security/policy.lux b/stdlib/source/test/lux/control/security/policy.lux index edbacddd6..6aebf504b 100644 --- a/stdlib/source/test/lux/control/security/policy.lux +++ b/stdlib/source/test/lux/control/security/policy.lux @@ -15,7 +15,9 @@ ["!" capability]]] [data ["." name] - ["." text ("#@." equivalence)]] + ["." text ("#@." equivalence)] + [number + ["n" nat]]] [math ["r" random]]] {1 @@ -81,7 +83,7 @@ (_.test "Can work with private values under the same label." (and (:: policy-0 = password password) - (n/= (:: text.hash hash raw-password) + (n.= (:: text.hash hash raw-password) (:: policy-0 hash password)))) (let [policy-1 (policy []) delegate (/.delegation (:: policy-0 can-downgrade) (:: policy-1 can-upgrade))] diff --git a/stdlib/source/test/lux/control/state.lux b/stdlib/source/test/lux/control/state.lux index 778162d61..1d9899539 100644 --- a/stdlib/source/test/lux/control/state.lux +++ b/stdlib/source/test/lux/control/state.lux @@ -13,6 +13,8 @@ ["." io]] [data ["." product] + [number + ["n" nat]] [text ["%" format (#+ format)]]] [math @@ -25,7 +27,7 @@ (|> computation (/.run state) product.right - (n/= output))) + (n.= output))) (def: basics (do r.monad @@ -41,16 +43,16 @@ [_ (/.put value)] /.get))) (_.test "Can update the state." - (with-conditions [state (n/* value state)] + (with-conditions [state (n.* value state)] (do /.monad - [_ (/.update (n/* value))] + [_ (/.update (n.* value))] /.get))) (_.test "Can use the state." (with-conditions [state (inc state)] (/.use inc))) (_.test "Can use a temporary (local) state." - (with-conditions [state (n/* value state)] - (/.local (n/* value) + (with-conditions [state (n.* value state)] + (/.local (n.* value) /.get))) ))) @@ -78,23 +80,23 @@ (def: loops Test (do r.monad - [limit (|> r.nat (:: @ map (n/% 10))) + [limit (|> r.nat (:: @ map (n.% 10))) #let [condition (do /.monad [state /.get] - (wrap (n/< limit state)))]] + (wrap (n.< limit state)))]] ($_ _.and (_.test "'while' will only execute if the condition is #1." (|> (/.while condition (/.update inc)) (/.run 0) (let> [state' output'] - (n/= limit state')))) + (n.= limit state')))) (_.test "'do-while' will execute at least once." (|> (/.do-while condition (/.update inc)) (/.run 0) (let> [state' output'] - (or (n/= limit state') - (and (n/= 0 limit) - (n/= 1 state')))))) + (or (n.= limit state') + (and (n.= 0 limit) + (n.= 1 state')))))) ))) (def: monad-transformer @@ -109,12 +111,12 @@ (do (/.with io.monad) [a (/.lift io.monad (io;wrap left)) b (wrap right)] - (wrap (n/+ a b)))) + (wrap (n.+ a b)))) (/.run' state) io.run (let> [state' output'] - (and (n/= state state') - (n/= (n/+ left right) output'))))) + (and (n.= state state') + (n.= (n.+ left right) output'))))) ))) (def: #export test diff --git a/stdlib/source/test/lux/control/thread.lux b/stdlib/source/test/lux/control/thread.lux index 84bcfbcd4..7d6ed0ceb 100644 --- a/stdlib/source/test/lux/control/thread.lux +++ b/stdlib/source/test/lux/control/thread.lux @@ -9,6 +9,8 @@ ["$." apply] ["$." monad]]}] [data + [number + ["n" nat]] [text ["%" format (#+ format)]]] [math @@ -37,10 +39,10 @@ ($monad.spec ..injection ..comparison /.monad) (_.test "Can safely do mutation." - (n/= (n/* factor original) + (n.= (n.* factor original) (/.run (: (All [!] (Thread ! Nat)) (do /.monad [box (/.box original) - old (/.update (n/* factor) box)] + old (/.update (n.* factor) box)] (/.read box)))))) )))) diff --git a/stdlib/source/test/lux/control/try.lux b/stdlib/source/test/lux/control/try.lux index 40015c5df..47e51b54b 100644 --- a/stdlib/source/test/lux/control/try.lux +++ b/stdlib/source/test/lux/control/try.lux @@ -15,7 +15,7 @@ [data ["%" text/format (#+ format)] [number - ["." nat]]] + ["n" nat]]] [math ["r" random (#+ Random)]]] {1 @@ -40,24 +40,24 @@ Test (<| (_.context (%.name (name-of /._))) ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (..try r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (..try r.nat)) ($functor.spec ..injection ..comparison /.functor) ($apply.spec ..injection ..comparison /.apply) ($monad.spec ..injection ..comparison /.monad) (do r.monad [left r.nat right r.nat - #let [expected (n/+ left right) + #let [expected (n.+ left right) (^open "io@.") io.monad]] (_.test "Can add try functionality to any monad." (let [lift (/.lift io.monad)] (|> (do (/.with io.monad) [a (lift (io@wrap left)) b (wrap right)] - (wrap (n/+ a b))) + (wrap (n.+ a b))) io.run (case> (#/.Success actual) - (n/= expected actual) + (n.= expected actual) _ false))))) diff --git a/stdlib/source/test/lux/control/writer.lux b/stdlib/source/test/lux/control/writer.lux index 5f510d6c0..d33cd3969 100644 --- a/stdlib/source/test/lux/control/writer.lux +++ b/stdlib/source/test/lux/control/writer.lux @@ -14,6 +14,8 @@ ["." io]] [data ["." product] + [number + ["n" nat]] ["." text ("#;." equivalence) ["%" format (#+ format)]]] [math @@ -51,7 +53,7 @@ (|> (io.run (do (/.with text.monoid io.monad) [a (lift (io;wrap left)) b (wrap right)] - (wrap (n/+ a b)))) + (wrap (n.+ a b)))) product.right - (n/= (n/+ left right))))) + (n.= (n.+ left right))))) )))) diff --git a/stdlib/source/test/lux/data/binary.lux b/stdlib/source/test/lux/data/binary.lux index 4b1ff0c54..9889fa0ae 100644 --- a/stdlib/source/test/lux/data/binary.lux +++ b/stdlib/source/test/lux/data/binary.lux @@ -13,7 +13,7 @@ [data [number ["." i64] - ["." nat]] + ["n" nat]] [collection ["." list]]]] {1 @@ -32,7 +32,7 @@ (-> Nat (Random Binary)) (let [output (/.create size)] (loop [idx 0] - (if (n/< size idx) + (if (n.< size idx) (do r.monad [byte r.nat] (exec (try.assume (/.write/8 idx byte output)) @@ -44,29 +44,29 @@ (let [binary (/.create bytes) cap (case bytes 8 (dec 0) - _ (|> 1 (i64.left-shift (n/* 8 bytes)) dec)) + _ (|> 1 (i64.left-shift (n.* 8 bytes)) dec)) capped-value (i64.and cap value)] (succeed (do try.monad [_ (write 0 value binary) output (read 0 binary)] - (wrap (n/= capped-value output)))))) + (wrap (n.= capped-value output)))))) (def: #export test Test (<| (_.context (%.name (name-of /._))) (do r.monad - [#let [gen-size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 8))))] + [#let [gen-size (|> r.nat (:: @ map (|>> (n.% 100) (n.max 8))))] binary-size gen-size random-binary (binary binary-size) value r.nat - #let [gen-idx (|> r.nat (:: @ map (n/% binary-size)))] + #let [gen-idx (|> r.nat (:: @ map (n.% binary-size)))] [from to] (r.and gen-idx gen-idx) - #let [[from to] [(n/min from to) (n/max from to)]]] + #let [[from to] [(n.min from to) (n.max from to)]]] ($_ _.and ($equivalence.spec /.equivalence (binary binary-size)) (_.test "Can get size of binary." - (|> random-binary /.size (n/= binary-size))) + (|> random-binary /.size (n.= binary-size))) (_.test "Can read/write 8-bit values." (bits-io 1 /.read/8 /.write/8 value)) (_.test "Can read/write 16-bit values." @@ -76,15 +76,15 @@ (_.test "Can read/write 64-bit values." (bits-io 8 /.read/64 /.write/64 value)) (_.test "Can slice binaries." - (let [slice-size (|> to (n/- from) inc) + (let [slice-size (|> to (n.- from) inc) random-slice (try.assume (/.slice from to random-binary)) idxs (list.n/range 0 (dec slice-size)) reader (function (_ binary idx) (/.read/8 idx binary))] - (and (n/= slice-size (/.size random-slice)) + (and (n.= slice-size (/.size random-slice)) (case [(monad.map try.monad (reader random-slice) idxs) - (monad.map try.monad (|>> (n/+ from) (reader random-binary)) idxs)] + (monad.map try.monad (|>> (n.+ from) (reader random-binary)) idxs)] [(#try.Success slice-vals) (#try.Success binary-vals)] - (:: (list.equivalence nat.equivalence) = slice-vals binary-vals) + (:: (list.equivalence n.equivalence) = slice-vals binary-vals) _ #0)))) diff --git a/stdlib/source/test/lux/data/collection/array.lux b/stdlib/source/test/lux/data/collection/array.lux index 50b1fcc71..c6dc407eb 100644 --- a/stdlib/source/test/lux/data/collection/array.lux +++ b/stdlib/source/test/lux/data/collection/array.lux @@ -15,7 +15,7 @@ [data ["." maybe] [number - ["." nat]] + ["n" nat]] [collection ["." list]]] [math @@ -30,7 +30,7 @@ (def: bounded-size (Random Nat) (|> r.nat - (:: r.monad map (|>> (n/% 100) (n/+ 1))))) + (:: r.monad map (|>> (n.% 100) (n.+ 1))))) (def: #export test Test @@ -38,8 +38,8 @@ (do r.monad [size bounded-size] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (r.array size r.nat)) - ($monoid.spec (/.equivalence nat.equivalence) /.monoid (r.array size r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (r.array size r.nat)) + ($monoid.spec (/.equivalence n.equivalence) /.monoid (r.array size r.nat)) ($functor.spec ..injection /.equivalence /.functor) ($fold.spec ..injection /.equivalence /.fold) @@ -48,16 +48,16 @@ original (r.array size r.nat)] ($_ _.and (_.test "Size function must correctly return size of array." - (n/= size (/.size original))) + (n.= size (/.size original))) (_.test "Cloning an array should yield and identical array, but not the same one." (let [clone (/.clone original)] - (and (:: (/.equivalence nat.equivalence) = original clone) + (and (:: (/.equivalence n.equivalence) = original clone) (not (is? original clone))))) (_.test "Full-range manual copies should give the same result as cloning." (let [copy (: (Array Nat) (/.new size))] (exec (/.copy size 0 original 0 copy) - (and (:: (/.equivalence nat.equivalence) = original copy) + (and (:: (/.equivalence n.equivalence) = original copy) (not (is? original copy)))))) (_.test "Array folding should go over all values." (let [manual-copy (: (Array Nat) @@ -68,17 +68,17 @@ (inc idx))) 0 original) - (:: (/.equivalence nat.equivalence) = original manual-copy)))) + (:: (/.equivalence n.equivalence) = original manual-copy)))) (_.test "Transformations between (full) arrays and lists shouldn't cause lose or change any values." (|> original /.to-list /.from-list - (:: (/.equivalence nat.equivalence) = original))) + (:: (/.equivalence n.equivalence) = original))) )) (do r.monad [size bounded-size - idx (:: @ map (n/% size) r.nat) + idx (:: @ map (n.% size) r.nat) array (|> (r.array size r.nat) - (r.filter (|>> /.to-list (list.any? n/odd?)))) + (r.filter (|>> /.to-list (list.any? n.odd?)))) #let [value (maybe.assume (/.read idx array))]] ($_ _.and (_.test "Shouldn't be able to find a value in an unoccupied cell." @@ -87,31 +87,31 @@ #.None true)) (_.test "You should be able to access values put into the array." (case (/.read idx (/.write idx value array)) - (#.Some value') (n/= value' value) + (#.Some value') (n.= value' value) #.None false)) (_.test "All cells should be occupied on a full array." - (and (n/= size (/.occupied array)) - (n/= 0 (/.vacant array)))) + (and (n.= size (/.occupied array)) + (n.= 0 (/.vacant array)))) (_.test "Filtering mutates the array to remove invalid values." - (exec (/.filter! n/even? array) - (and (n/< size (/.occupied array)) - (n/> 0 (/.vacant array)) - (n/= size (n/+ (/.occupied array) + (exec (/.filter! n.even? array) + (and (n.< size (/.occupied array)) + (n.> 0 (/.vacant array)) + (n.= size (n.+ (/.occupied array) (/.vacant array)))))) )) (do r.monad [size bounded-size array (|> (r.array size r.nat) - (r.filter (|>> /.to-list (list.any? n/even?))))] + (r.filter (|>> /.to-list (list.any? n.even?))))] ($_ _.and (_.test "Can find values inside arrays." - (|> (/.find n/even? array) + (|> (/.find n.even? array) (case> (#.Some _) true #.None false))) (_.test "Can find values inside arrays (with access to indices)." (|> (/.find+ (function (_ idx n) - (and (n/even? n) - (n/< size idx))) + (and (n.even? n) + (n.< size idx))) array) (case> (#.Some _) true #.None false))))) diff --git a/stdlib/source/test/lux/data/collection/bits.lux b/stdlib/source/test/lux/data/collection/bits.lux index b0f4dec0e..77e346116 100644 --- a/stdlib/source/test/lux/data/collection/bits.lux +++ b/stdlib/source/test/lux/data/collection/bits.lux @@ -8,6 +8,9 @@ {[0 #test] [/ ["$." equivalence]]}] + [data + [number + ["n" nat]]] [math ["r" random (#+ Random)]]] {1 @@ -16,13 +19,13 @@ (def: (size min max) (-> Nat Nat (Random Nat)) (|> r.nat - (:: r.monad map (|>> (n/% max) (n/max min))))) + (:: r.monad map (|>> (n.% max) (n.max min))))) (def: #export bits (Random Bits) (do r.monad [size (size 1 1,000) - idx (|> r.nat (:: @ map (n/% size)))] + idx (|> r.nat (:: @ map (n.% size)))] (wrap (|> /.empty (/.set idx))))) (def: #export test @@ -32,7 +35,7 @@ ($equivalence.spec /.equivalence ..bits) (do r.monad [size (size 1 1,000) - idx (|> r.nat (:: @ map (n/% size))) + idx (|> r.nat (:: @ map (n.% size))) sample bits] ($_ _.and (_.test "Can set individual bits." @@ -44,14 +47,14 @@ (and (|> /.empty (/.flip idx) (/.get idx)) (|> /.empty (/.flip idx) (/.flip idx) (/.get idx) not))) (_.test "Bits (only) grow when (and as much as) necessary." - (and (n/= 0 (/.capacity /.empty)) + (and (n.= 0 (/.capacity /.empty)) (|> /.empty (/.set idx) /.capacity - (n/- idx) - (predicate.unite (n/>= 0) - (n/< /.chunk-size))))) + (n.- idx) + (predicate.unite (n.>= 0) + (n.< /.chunk-size))))) (_.test "Bits (must) shrink when (and as much as) possible." (let [grown (/.flip idx /.empty)] - (and (n/> 0 (/.capacity grown)) + (and (n.> 0 (/.capacity grown)) (is? /.empty (/.flip idx grown))))) (_.test "Intersection can be detected when there are set bits in common." (and (not (/.intersects? /.empty @@ -68,12 +71,12 @@ (is? /.empty (/.and sample (/.not sample)))) (_.test "'or' with one's opposite fully saturates a bit-set." - (n/= (/.size (/.or sample (/.not sample))) + (n.= (/.size (/.or sample (/.not sample))) (/.capacity sample))) (_.test "'xor' with oneself yields the empty bit-set." (is? /.empty (/.xor sample sample))) (_.test "'xor' with one's opposite fully saturates a bit-set." - (n/= (/.size (/.xor sample (/.not sample))) + (n.= (/.size (/.xor sample (/.not sample))) (/.capacity sample))) (_.test "Double negation results in original bit-set." (:: /.equivalence = sample (/.not (/.not sample)))) diff --git a/stdlib/source/test/lux/data/collection/dictionary.lux b/stdlib/source/test/lux/data/collection/dictionary.lux index 4512c0bec..432909629 100644 --- a/stdlib/source/test/lux/data/collection/dictionary.lux +++ b/stdlib/source/test/lux/data/collection/dictionary.lux @@ -12,7 +12,7 @@ [data ["." maybe] [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." functor)]]] [math @@ -22,30 +22,30 @@ (def: injection (Injection (/.Dictionary Nat)) - (|>> [0] list (/.from-list nat.hash))) + (|>> [0] list (/.from-list n.hash))) (def: #export test Test (<| (_.context (%.name (name-of /.Dictionary))) (do r.monad - [#let [capped-nat (:: r.monad map (n/% 100) r.nat)] + [#let [capped-nat (:: r.monad map (n.% 100) r.nat)] size capped-nat - dict (r.dictionary nat.hash size r.nat capped-nat) + dict (r.dictionary n.hash size r.nat capped-nat) non-key (|> r.nat (r.filter (function (_ key) (not (/.contains? key dict))))) - test-val (|> r.nat (r.filter (function (_ val) (not (list.member? nat.equivalence (/.values dict) val)))))] + test-val (|> r.nat (r.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) - (r.dictionary nat.hash size r.nat r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) + (r.dictionary n.hash size r.nat r.nat)) ($functor.spec ..injection /.equivalence /.functor) (_.test "Size function should correctly represent Dictionary size." - (n/= size (/.size dict))) + (n.= size (/.size dict))) (_.test "Dictionaries of size 0 should be considered empty." - (if (n/= 0 size) + (if (n.= 0 size) (/.empty? dict) (not (/.empty? dict)))) (_.test "The functions 'entries', 'keys' and 'values' should be synchronized." - (:: (list.equivalence (eq.product nat.equivalence nat.equivalence)) = + (:: (list.equivalence (eq.product n.equivalence n.equivalence)) = (/.entries dict) (list.zip2 (/.keys dict) (/.values dict)))) @@ -63,18 +63,18 @@ _ #1)) (_.test "Should be able to put and then get a value." (case (/.get non-key (/.put non-key test-val dict)) - (#.Some v) (n/= test-val v) + (#.Some v) (n.= test-val v) _ #1)) (_.test "Should be able to try-put and then get a value." (case (/.get non-key (/.try-put non-key test-val dict)) - (#.Some v) (n/= test-val v) + (#.Some v) (n.= test-val v) _ #1)) (_.test "Shouldn't be able to try-put an existing key." - (or (n/= 0 size) + (or (n.= 0 size) (let [first-key (|> dict /.keys list.head maybe.assume)] (case (/.get first-key (/.try-put first-key test-val dict)) - (#.Some v) (not (n/= test-val v)) + (#.Some v) (not (n.= test-val v)) _ #1)))) (_.test "Removing a key should make it's value inaccessible." (let [base (/.put non-key test-val dict)] @@ -85,45 +85,45 @@ updt (/.update non-key inc base)] (case [(/.get non-key base) (/.get non-key updt)] [(#.Some x) (#.Some y)] - (n/= (inc x) y) + (n.= (inc x) y) _ #0))) (_.test "Additions and removals to a Dictionary should affect its size." (let [plus (/.put non-key test-val dict) base (/.remove non-key plus)] - (and (n/= (inc (/.size dict)) (/.size plus)) - (n/= (dec (/.size plus)) (/.size base))))) + (and (n.= (inc (/.size dict)) (/.size plus)) + (n.= (dec (/.size plus)) (/.size base))))) (_.test "A Dictionary should equal itself & going to<->from lists shouldn't change that." - (let [(^open ".") (/.equivalence nat.equivalence)] + (let [(^open ".") (/.equivalence n.equivalence)] (and (= dict dict) - (|> dict /.entries (/.from-list nat.hash) (= dict))))) + (|> dict /.entries (/.from-list n.hash) (= dict))))) (_.test "Merging a Dictionary to itself changes nothing." - (let [(^open ".") (/.equivalence nat.equivalence)] + (let [(^open ".") (/.equivalence n.equivalence)] (= dict (/.merge dict dict)))) (_.test "If you merge, and the second dict has overlapping keys, it should overwrite yours." (let [dict' (|> dict /.entries (list@map (function (_ [k v]) [k (inc v)])) - (/.from-list nat.hash)) - (^open ".") (/.equivalence nat.equivalence)] + (/.from-list n.hash)) + (^open ".") (/.equivalence n.equivalence)] (= dict' (/.merge dict' dict)))) (_.test "Can merge values in such a way that they become combined." - (list.every? (function (_ [x x*2]) (n/= (n/* 2 x) x*2)) + (list.every? (function (_ [x x*2]) (n.= (n.* 2 x) x*2)) (list.zip2 (/.values dict) - (/.values (/.merge-with n/+ dict dict))))) + (/.values (/.merge-with n.+ dict dict))))) (_.test "Should be able to select subset of keys from dict." (|> dict (/.put non-key test-val) (/.select (list non-key)) /.size - (n/= 1))) + (n.= 1))) (_.test "Should be able to re-bind existing values to different keys." - (or (n/= 0 size) + (or (n.= 0 size) (let [first-key (|> dict /.keys list.head maybe.assume) rebound (/.re-bind first-key non-key dict)] - (and (n/= (/.size dict) (/.size rebound)) + (and (n.= (/.size dict) (/.size rebound)) (/.contains? non-key rebound) (not (/.contains? first-key rebound)) - (n/= (maybe.assume (/.get first-key dict)) + (n.= (maybe.assume (/.get first-key dict)) (maybe.assume (/.get non-key rebound))))))) )))) diff --git a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux index 28119cd93..19b124c40 100644 --- a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux @@ -12,7 +12,7 @@ [data ["." product] [number - ["." nat]] + ["n" nat]] [collection ["." set] ["." list ("#@." functor)]]] @@ -41,31 +41,31 @@ Test (<| (_.context (%.name (name-of /.Dictionary))) (do r.monad - [size (|> r.nat (:: @ map (n/% 100))) - keys (r.set nat.hash size r.nat) - values (r.set nat.hash size r.nat) + [size (|> r.nat (:: @ map (n.% 100))) + keys (r.set n.hash size r.nat) + values (r.set n.hash size r.nat) extra-key (|> r.nat (r.filter (|>> (set.member? keys) not))) extra-value r.nat #let [pairs (list.zip2 (set.to-list keys) (set.to-list values)) - sample (/.from-list nat.order pairs) + sample (/.from-list n.order pairs) sorted-pairs (list.sort (function (_ [left _] [right _]) - (n/< left right)) + (n.< left right)) pairs) sorted-values (list@map product.right sorted-pairs) - (^open "/@.") (/.equivalence nat.equivalence)]] + (^open "/@.") (/.equivalence n.equivalence)]] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (..dictionary nat.order r.nat r.nat size)) + ($equivalence.spec (/.equivalence n.equivalence) (..dictionary n.order r.nat r.nat size)) (_.test "Can query the size of a dictionary." - (n/= size (/.size sample))) + (n.= size (/.size sample))) (_.test "Can query value for minimum key." (case [(/.min sample) (list.head sorted-values)] [#.None #.None] #1 [(#.Some reference) (#.Some sample)] - (n/= reference sample) + (n.= reference sample) _ #0)) @@ -75,19 +75,19 @@ #1 [(#.Some reference) (#.Some sample)] - (n/= reference sample) + (n.= reference sample) _ #0)) (_.test "Converting dictionaries to/from lists cannot change their values." (|> sample - /.entries (/.from-list nat.order) + /.entries (/.from-list n.order) (/@= sample))) (_.test "Order is preserved." (let [(^open "list@.") (list.equivalence (: (Equivalence [Nat Nat]) (function (_ [kr vr] [ks vs]) - (and (n/= kr ks) - (n/= vr vs)))))] + (and (n.= kr ks) + (n.= vr vs)))))] (list@= (/.entries sample) sorted-pairs))) (_.test "Every key in a dictionary must be identifiable." @@ -102,7 +102,7 @@ (case [(/.get extra-key sample') (/.get extra-key sample'')] [(#.Some found) #.None] - (n/= extra-value found) + (n.= extra-value found) _ #0))) diff --git a/stdlib/source/test/lux/data/collection/list.lux b/stdlib/source/test/lux/data/collection/list.lux index 77d473fd6..954e3f15d 100644 --- a/stdlib/source/test/lux/data/collection/list.lux +++ b/stdlib/source/test/lux/data/collection/list.lux @@ -20,7 +20,7 @@ ["." product] ["." maybe] [number - ["." nat] + ["n" nat] ["." int]]] [math ["r" random]]] @@ -30,15 +30,15 @@ (def: bounded-size (r.Random Nat) (|> r.nat - (:: r.monad map (|>> (n/% 100) (n/+ 10))))) + (:: r.monad map (|>> (n.% 100) (n.+ 10))))) (def: signatures Test (do r.monad [size bounded-size] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (r.list size r.nat)) - ($monoid.spec (/.equivalence nat.equivalence) /.monoid (r.list size r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (r.list size r.nat)) + ($monoid.spec (/.equivalence n.equivalence) /.monoid (r.list size r.nat)) ($fold.spec /@wrap /.equivalence /.fold) ($functor.spec /@wrap /.equivalence /.functor) ($apply.spec /@wrap /.equivalence /.apply) @@ -49,14 +49,14 @@ subject r.nat] (let [lift (/.lift io.monad) (^open "io@.") io.monad - expected (n/+ parameter subject)] + expected (n.+ parameter subject)] (_.test "Can add list functionality to any monad." (|> (io.run (do (/.with io.monad) [a (lift (io@wrap parameter)) b (wrap subject)] - (wrap (n/+ a b)))) + (wrap (n.+ a b)))) (case> (^ (list actual)) - (n/= expected actual) + (n.= expected actual) _ false))))) @@ -67,10 +67,10 @@ (<| (_.context (%.name (name-of .List))) (do r.monad [size bounded-size - #let [(^open "/@.") (/.equivalence nat.equivalence) + #let [(^open "/@.") (/.equivalence n.equivalence) (^open "/@.") /.functor (^open "/@.") /.monoid] - idx (:: @ map (n/% 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) @@ -79,31 +79,31 @@ ..signatures (_.test "The size function should correctly portray the size of the list." - (n/= size (/.size sample))) + (n.= size (/.size sample))) (_.test "The repeat function should produce as many elements as asked of it." - (n/= size (/.size (/.repeat size [])))) + (n.= size (/.size (/.repeat size [])))) (_.test "Reversing a list does not change it's size." - (n/= (/.size sample) + (n.= (/.size sample) (/.size (/.reverse sample)))) (_.test "Reversing a list twice results in the original list." (/@= sample (/.reverse (/.reverse sample)))) (_.test "Filtering by a predicate and its complement should result in a number of elements equal to the original list." - (and (n/= (/.size sample) - (n/+ (/.size (/.filter n/even? sample)) - (/.size (/.filter (bit.complement n/even?) sample)))) - (let [[plus minus] (/.partition n/even? sample)] - (n/= (/.size sample) - (n/+ (/.size plus) + (and (n.= (/.size sample) + (n.+ (/.size (/.filter n.even? sample)) + (/.size (/.filter (bit.complement n.even?) sample)))) + (let [[plus minus] (/.partition n.even? sample)] + (n.= (/.size sample) + (n.+ (/.size plus) (/.size minus)))))) (_.test "If every element in a list satisfies a predicate, there can't be any that satisfy its complement." - (if (/.every? n/even? sample) - (and (not (/.any? (bit.complement n/even?) sample)) - (/.empty? (/.filter (bit.complement n/even?) sample))) - (/.any? (bit.complement n/even?) sample))) + (if (/.every? n.even? sample) + (and (not (/.any? (bit.complement n.even?) sample)) + (/.empty? (/.filter (bit.complement n.even?) sample))) + (/.any? (bit.complement n.even?) sample))) (_.test "Any element of the list can be considered its member." (let [elem (maybe.assume (/.nth idx sample))] - (/.member? nat.equivalence sample elem))) + (/.member? n.equivalence sample elem))) (_.test "Appending the head and the tail should yield the original list." (let [head (maybe.assume (/.head sample)) tail (maybe.assume (/.tail sample))] @@ -116,7 +116,7 @@ (/@compose inits (list last))))) (_.test "Splitting a list into chunks and re-appending them should yield the original list." (let [[left right] (/.split idx sample) - [left' right'] (/.split-with n/even? sample)] + [left' right'] (/.split-with n.even? sample)] (and (/@= sample (/@compose left right)) (/@= sample @@ -125,21 +125,21 @@ (/@compose (/.take idx sample) (/.drop idx sample))) (/@= sample - (/@compose (/.take-while n/even? sample) - (/.drop-while n/even? sample))) + (/@compose (/.take-while n.even? sample) + (/.drop-while n.even? sample))) ))) (_.test "Segmenting the list in pairs should yield as many elements as N/2." - (n/= (n// 2 size) + (n.= (n./ 2 size) (/.size (/.as-pairs sample)))) (_.test "Sorting a list shouldn't change it's size." - (n/= (/.size sample) - (/.size (/.sort n/< sample)))) + (n.= (/.size sample) + (/.size (/.sort n.< sample)))) (_.test "Sorting a list with one order should yield the reverse of sorting it with the opposite order." - (/@= (/.sort n/< sample) - (/.reverse (/.sort n/> sample)))) + (/@= (/.sort n.< sample) + (/.reverse (/.sort n.> sample)))) (_.test "If you zip 2 lists, the result's size will be that of the smaller list." - (n/= (/.size (/.zip2 sample other-sample)) - (n/min (/.size sample) (/.size other-sample)))) + (n.= (/.size (/.zip2 sample other-sample)) + (n.min (/.size sample) (/.size other-sample)))) (_.test "I can pair-up elements of a list in order." (let [zipped (/.zip2 sample other-sample) num-zipper (/.size zipped)] @@ -147,32 +147,32 @@ (|> zipped (/@map product.right) (/@= (/.take num-zipper other-sample)))))) (_.test "You can generate indices for any size, and they will be in ascending order." (let [indices (/.indices size)] - (and (n/= size (/.size indices)) + (and (n.= size (/.size indices)) (/@= indices - (/.sort n/< indices)) - (/.every? (n/= (dec size)) - (/.zip2-with n/+ + (/.sort n.< indices)) + (/.every? (n.= (dec size)) + (/.zip2-with n.+ indices - (/.sort n/> indices))) + (/.sort n.> indices))) ))) (_.test "The 'interpose' function places a value between every member of a list." (let [sample+ (/.interpose separator sample)] - (and (n/= (|> size (n/* 2) dec) + (and (n.= (|> size (n.* 2) dec) (/.size sample+)) - (|> sample+ /.as-pairs (/@map product.right) (/.every? (n/= separator)))))) + (|> sample+ /.as-pairs (/@map product.right) (/.every? (n.= separator)))))) (_.test "You can find any value that satisfies some criterium, if such values exist in the list." - (case (/.find n/even? sample) + (case (/.find n.even? sample) (#.Some found) - (and (n/even? found) - (/.any? n/even? sample) - (not (/.every? (bit.complement n/even?) sample))) + (and (n.even? found) + (/.any? n.even? sample) + (not (/.every? (bit.complement n.even?) sample))) #.None - (and (not (/.any? n/even? sample)) - (/.every? (bit.complement n/even?) sample)))) + (and (not (/.any? n.even? sample)) + (/.every? (bit.complement n.even?) sample)))) (_.test "You can iteratively construct a list, generating values until you're done." (/@= (/.n/range 0 (dec size)) - (/.iterate (function (_ n) (if (n/< size n) (#.Some (inc n)) #.None)) + (/.iterate (function (_ n) (if (n.< size n) (#.Some (inc n)) #.None)) 0))) (_.test "Can enumerate all elements in a list." (let [enum-sample (/.enumerate sample)] @@ -181,8 +181,8 @@ (/@= sample (/@map product.right enum-sample))))) (do r.monad - [from (|> r.nat (:: @ map (n/% 10))) - to (|> r.nat (:: @ map (n/% 10)))] + [from (|> r.nat (:: @ map (n.% 10))) + to (|> r.nat (:: @ map (n.% 10)))] (_.test "Ranges can be constructed forward and backwards." (and (/@= (/.n/range from to) (/.reverse (/.n/range to from))) diff --git a/stdlib/source/test/lux/data/collection/queue.lux b/stdlib/source/test/lux/data/collection/queue.lux index f9a32c0c8..64e9c5e56 100644 --- a/stdlib/source/test/lux/data/collection/queue.lux +++ b/stdlib/source/test/lux/data/collection/queue.lux @@ -10,7 +10,7 @@ ["$." functor (#+ Injection)]]}] [data [number - ["." nat]]] + ["n" nat]]] [math ["r" random]]] {1 @@ -24,25 +24,25 @@ Test (<| (_.context (%.name (name-of /.Queue))) (do r.monad - [size (:: @ map (n/% 100) r.nat) + [size (:: @ map (n.% 100) r.nat) sample (r.queue size r.nat) non-member (|> r.nat - (r.filter (|>> (/.member? nat.equivalence sample) not)))] + (r.filter (|>> (/.member? n.equivalence sample) not)))] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (r.queue size r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (r.queue size r.nat)) ($functor.spec ..injection /.equivalence /.functor) (_.test "I can query the size of a queue (and empty queues have size 0)." - (if (n/= 0 size) + (if (n.= 0 size) (/.empty? sample) - (n/= size (/.size sample)))) + (n.= size (/.size sample)))) (_.test "Enqueueing and dequeing affects the size of queues." - (and (n/= (inc size) (/.size (/.push non-member sample))) + (and (n.= (inc size) (/.size (/.push non-member sample))) (or (/.empty? sample) - (n/= (dec size) (/.size (/.pop sample)))) - (n/= size (/.size (/.pop (/.push non-member sample)))))) + (n.= (dec size) (/.size (/.pop sample)))) + (n.= size (/.size (/.pop (/.push non-member sample)))))) (_.test "Transforming to/from list can't change the queue." - (let [(^open "/;.") (/.equivalence nat.equivalence)] + (let [(^open "/;.") (/.equivalence n.equivalence)] (|> sample /.to-list /.from-list (/;= sample)))) @@ -51,14 +51,14 @@ #.None (/.empty? sample) (#.Some _) #1)) (_.test "I can query whether an element belongs to a queue." - (and (not (/.member? nat.equivalence sample non-member)) - (/.member? nat.equivalence (/.push non-member sample) + (and (not (/.member? n.equivalence sample non-member)) + (/.member? n.equivalence (/.push non-member sample) non-member) (case (/.peek sample) #.None (/.empty? sample) (#.Some first) - (and (/.member? nat.equivalence sample first) - (not (/.member? nat.equivalence (/.pop sample) first)))))) + (and (/.member? n.equivalence sample first) + (not (/.member? n.equivalence (/.pop sample) first)))))) )))) diff --git a/stdlib/source/test/lux/data/collection/queue/priority.lux b/stdlib/source/test/lux/data/collection/queue/priority.lux index 9464819a3..78e4bc2b8 100644 --- a/stdlib/source/test/lux/data/collection/queue/priority.lux +++ b/stdlib/source/test/lux/data/collection/queue/priority.lux @@ -7,7 +7,7 @@ [data ["." maybe] [number - ["." nat]]] + ["n" nat]]] [math ["r" random (#+ Random)]]] {1 @@ -28,29 +28,29 @@ Test (<| (_.context (%.name (name-of /.Queue))) (do r.monad - [size (|> r.nat (:: @ map (n/% 100))) + [size (|> r.nat (:: @ map (n.% 100))) sample (..queue size) non-member-priority r.nat - non-member (|> r.nat (r.filter (|>> (/.member? nat.equivalence sample) not)))] + non-member (|> r.nat (r.filter (|>> (/.member? n.equivalence sample) not)))] ($_ _.and (_.test "I can query the size of a queue (and empty queues have size 0)." - (n/= size (/.size sample))) + (n.= size (/.size sample))) (_.test "Enqueueing and dequeing affects the size of queues." - (and (n/= (inc size) + (and (n.= (inc size) (/.size (/.push non-member-priority non-member sample))) - (or (n/= 0 (/.size sample)) - (n/= (dec size) + (or (n.= 0 (/.size sample)) + (n.= (dec size) (/.size (/.pop sample)))))) (_.test "I can query whether an element belongs to a queue." - (and (and (not (/.member? nat.equivalence sample non-member)) - (/.member? nat.equivalence + (and (and (not (/.member? n.equivalence sample non-member)) + (/.member? n.equivalence (/.push non-member-priority non-member sample) non-member)) - (or (n/= 0 (/.size sample)) - (and (/.member? nat.equivalence + (or (n.= 0 (/.size sample)) + (and (/.member? n.equivalence sample (maybe.assume (/.peek sample))) - (not (/.member? nat.equivalence + (not (/.member? n.equivalence (/.pop sample) (maybe.assume (/.peek sample)))))))) )))) diff --git a/stdlib/source/test/lux/data/collection/row.lux b/stdlib/source/test/lux/data/collection/row.lux index 7afbafd59..80917c7eb 100644 --- a/stdlib/source/test/lux/data/collection/row.lux +++ b/stdlib/source/test/lux/data/collection/row.lux @@ -15,7 +15,7 @@ [data ["." maybe] [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." fold)]]] [math @@ -27,32 +27,32 @@ Test (<| (_.context (%.name (name-of /._))) (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 10))))] + [size (|> r.nat (:: @ map (|>> (n.% 100) (n.max 10))))] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (r.row size r.nat)) - ($monoid.spec (/.equivalence nat.equivalence) /.monoid (r.row size r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (r.row size r.nat)) + ($monoid.spec (/.equivalence n.equivalence) /.monoid (r.row size r.nat)) ($fold.spec /@wrap /.equivalence /.fold) ($functor.spec /@wrap /.equivalence /.functor) ($apply.spec /@wrap /.equivalence /.apply) ($monad.spec /@wrap /.equivalence /.monad) (do @ - [idx (|> r.nat (:: @ map (n/% size))) + [idx (|> r.nat (:: @ map (n.% size))) sample (r.row size r.nat) other-sample (r.row size r.nat) - non-member (|> r.nat (r.filter (|>> (/.member? nat.equivalence sample) not))) - #let [(^open "/@.") (/.equivalence nat.equivalence)]] + non-member (|> r.nat (r.filter (|>> (/.member? n.equivalence sample) not))) + #let [(^open "/@.") (/.equivalence n.equivalence)]] ($_ _.and (_.test (format (%.name (name-of /.size)) " " (%.name (name-of /.empty?))) (if (/.empty? sample) - (and (n/= 0 size) - (n/= 0 (/.size sample))) - (n/= size (/.size sample)))) + (and (n.= 0 size) + (n.= 0 (/.size sample))) + (n.= size (/.size sample)))) (_.test (format (%.name (name-of /.add)) " " (%.name (name-of /.pop))) - (and (n/= (inc size) (/.size (/.add non-member sample))) - (n/= (dec size) (/.size (/.pop sample))))) + (and (n.= (inc size) (/.size (/.add non-member sample))) + (n.= (dec size) (/.size (/.pop sample))))) (_.test (format (%.name (name-of /.put)) " " (%.name (name-of /.nth))) (|> sample @@ -64,13 +64,13 @@ (|> sample (/.put idx non-member) (/.update idx inc) (/.nth idx) maybe.assume - (n/= (inc non-member)))) + (n.= (inc non-member)))) (_.test (format (%.name (name-of /.to-list)) " " (%.name (name-of /.from-list))) (|> sample /.to-list /.from-list (/@= sample))) (_.test (%.name (name-of /.member?)) - (and (not (/.member? nat.equivalence sample non-member)) - (/.member? nat.equivalence (/.add non-member sample) non-member))) + (and (not (/.member? n.equivalence sample non-member)) + (/.member? n.equivalence (/.add non-member sample) non-member))) (_.test (%.name (name-of /.reverse)) (and (not (/@= sample (/.reverse sample))) diff --git a/stdlib/source/test/lux/data/collection/sequence.lux b/stdlib/source/test/lux/data/collection/sequence.lux index 2beb3599f..6e4f59930 100644 --- a/stdlib/source/test/lux/data/collection/sequence.lux +++ b/stdlib/source/test/lux/data/collection/sequence.lux @@ -9,7 +9,7 @@ [data ["." maybe] [number - ["." nat ("#@." decimal)]] + ["n" nat ("#@." decimal)]] ["." text ("#@." monoid)] [collection ["." list]]] @@ -22,80 +22,80 @@ Test (<| (_.context (%.name (name-of /.Sequence))) (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 2)))) - offset (|> r.nat (:: @ map (n/% 100))) - factor (|> r.nat (:: @ map (|>> (n/% 100) (n/max 2)))) + [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.equivalence nat.equivalence) + cycle-sample-idx (|> r.nat (:: @ map (n.% 1000))) + #let [(^open "list@.") (list.equivalence n.equivalence) sample0 (/.iterate inc 0) sample1 (/.iterate inc offset)]] ($_ _.and (_.test "Can move along a sequence and take slices off it." (and (and (list@= (list.n/range 0 (dec size)) (/.take size sample0)) - (list@= (list.n/range offset (dec (n/+ offset size))) + (list@= (list.n/range offset (dec (n.+ offset size))) (/.take size (/.drop offset sample0))) (let [[drops takes] (/.split size sample0)] (and (list@= (list.n/range 0 (dec size)) drops) - (list@= (list.n/range size (dec (n/* 2 size))) + (list@= (list.n/range size (dec (n.* 2 size))) (/.take size takes))))) (and (list@= (list.n/range 0 (dec size)) - (/.take-while (n/< size) sample0)) - (list@= (list.n/range offset (dec (n/+ offset size))) - (/.take-while (n/< (n/+ offset size)) - (/.drop-while (n/< offset) sample0))) - (let [[drops takes] (/.split-while (n/< size) sample0)] + (/.take-while (n.< size) sample0)) + (list@= (list.n/range offset (dec (n.+ offset size))) + (/.take-while (n.< (n.+ offset size)) + (/.drop-while (n.< offset) sample0))) + (let [[drops takes] (/.split-while (n.< size) sample0)] (and (list@= (list.n/range 0 (dec size)) drops) - (list@= (list.n/range size (dec (n/* 2 size))) - (/.take-while (n/< (n/* 2 size)) takes))))) + (list@= (list.n/range size (dec (n.* 2 size))) + (/.take-while (n.< (n.* 2 size)) takes))))) )) (_.test "Can repeat any element and infinite number of times." - (n/= elem (/.nth offset (/.repeat elem)))) + (n.= elem (/.nth offset (/.repeat elem)))) (_.test "Can obtain the head & tail of a sequence." - (and (n/= offset (/.head sample1)) - (list@= (list.n/range (inc offset) (n/+ offset size)) + (and (n.= offset (/.head sample1)) + (list@= (list.n/range (inc offset) (n.+ offset size)) (/.take size (/.tail sample1))))) (_.test "Can filter sequences." - (and (n/= (n/* 2 offset) + (and (n.= (n.* 2 offset) (/.nth offset - (/.filter n/even? sample0))) - (let [[evens odds] (/.partition n/even? (/.iterate inc 0))] - (and (n/= (n/* 2 offset) + (/.filter n.even? sample0))) + (let [[evens odds] (/.partition n.even? (/.iterate inc 0))] + (and (n.= (n.* 2 offset) (/.nth offset evens)) - (n/= (inc (n/* 2 offset)) + (n.= (inc (n.* 2 offset)) (/.nth offset odds)))))) (_.test "Functor goes over 'all' elements in a sequence." (let [(^open "/@.") /.functor - there (/@map (n/* factor) sample0) - back-again (/@map (n// factor) there)] + there (/@map (n.* factor) sample0) + back-again (/@map (n./ factor) there)] (and (not (list@= (/.take size sample0) (/.take size there))) (list@= (/.take size sample0) (/.take size back-again))))) (_.test "CoMonad produces a value for every element in a sequence." (let [(^open "/@.") /.functor] - (list@= (/.take size (/@map (n/* factor) sample1)) + (list@= (/.take size (/@map (n.* factor) sample1)) (/.take size (be /.comonad [inputs sample1] - (n/* factor (/.head inputs))))))) + (n.* factor (/.head inputs))))))) (_.test "'unfold' generalizes 'iterate'." (let [(^open "/@.") /.functor (^open "list@.") (list.equivalence text.equivalence)] (list@= (/.take size - (/@map nat@encode (/.iterate inc offset))) + (/@map n@encode (/.iterate inc offset))) (/.take size - (/.unfold (function (_ n) [(inc n) (nat@encode n)]) + (/.unfold (function (_ n) [(inc n) (n@encode n)]) offset))))) (_.test "Can cycle over the same elements as an infinite sequence." (|> (/.cycle cycle-seed) maybe.assume (/.nth cycle-sample-idx) - (n/= (|> cycle-seed - (list.nth (n/% size cycle-sample-idx)) + (n.= (|> cycle-seed + (list.nth (n.% size cycle-sample-idx)) maybe.assume)))) )))) diff --git a/stdlib/source/test/lux/data/collection/set.lux b/stdlib/source/test/lux/data/collection/set.lux index 6e668af56..d742352ec 100644 --- a/stdlib/source/test/lux/data/collection/set.lux +++ b/stdlib/source/test/lux/data/collection/set.lux @@ -10,7 +10,7 @@ ["$." monoid]]}] [data [number - ["." nat]] + ["n" nat]] [collection ["." list]]] [math @@ -21,7 +21,7 @@ (def: gen-nat (r.Random Nat) (|> r.nat - (:: r.monad map (n/% 100)))) + (:: r.monad map (n.% 100)))) (def: #export test Test @@ -29,24 +29,24 @@ (do r.monad [size gen-nat] ($_ _.and - ($equivalence.spec /.equivalence (r.set nat.hash size r.nat)) - ($monoid.spec /.equivalence (/.monoid nat.hash) (r.set nat.hash size r.nat)) + ($equivalence.spec /.equivalence (r.set n.hash size r.nat)) + ($monoid.spec /.equivalence (/.monoid n.hash) (r.set n.hash size r.nat)) (do r.monad [sizeL gen-nat sizeR gen-nat - setL (r.set nat.hash sizeL gen-nat) - setR (r.set nat.hash sizeR gen-nat) + setL (r.set n.hash sizeL gen-nat) + setR (r.set n.hash sizeR gen-nat) non-member (|> gen-nat (r.filter (|>> (/.member? setL) not))) #let [(^open "/@.") /.equivalence]] ($_ _.and (_.test "I can query the size of a set." - (and (n/= sizeL (/.size setL)) - (n/= sizeR (/.size setR)))) + (and (n.= sizeL (/.size setL)) + (n.= sizeR (/.size setR)))) (_.test "Converting sets to/from lists can't change their values." (|> setL - /.to-list (/.from-list nat.hash) + /.to-list (/.from-list n.hash) (/@= setL))) (_.test "Every set is a sub-set of the union of itself with another." (let [setLR (/.union setL setR)] @@ -58,10 +58,10 @@ (/.super? setLR setR)))) (_.test "Union with the empty set leaves a set unchanged." (/@= setL - (/.union (/.new nat.hash) + (/.union (/.new n.hash) setL))) (_.test "Intersection with the empty set results in the empty set." - (let [empty-set (/.new nat.hash)] + (let [empty-set (/.new n.hash)] (/@= empty-set (/.intersection empty-set setL)))) (_.test "After substracting a set A from another B, no member of A can be a member of B." diff --git a/stdlib/source/test/lux/data/collection/set/ordered.lux b/stdlib/source/test/lux/data/collection/set/ordered.lux index fa7c00798..30ff8f6db 100644 --- a/stdlib/source/test/lux/data/collection/set/ordered.lux +++ b/stdlib/source/test/lux/data/collection/set/ordered.lux @@ -10,7 +10,7 @@ ["$." equivalence]]}] [data [number - ["." nat]] + ["n" nat]] [collection ["." list]]] [math @@ -22,7 +22,7 @@ (def: gen-nat (r.Random Nat) (|> r.nat - (:: r.monad map (n/% 100)))) + (:: r.monad map (n.% 100)))) (def: #export (set &order gen-value size) (All [a] (-> (Order a) (Random a) Nat (Random (Set a)))) @@ -44,29 +44,29 @@ (do r.monad [size gen-nat] ($_ _.and - ($equivalence.spec /.equivalence (..set nat.order r.nat size)) + ($equivalence.spec /.equivalence (..set n.order r.nat size)) )) (do r.monad [sizeL gen-nat sizeR gen-nat - listL (|> (r.set nat.hash sizeL gen-nat) (:: @ map //.to-list)) - listR (|> (r.set nat.hash sizeR gen-nat) (:: @ map //.to-list)) + listL (|> (r.set n.hash sizeL gen-nat) (:: @ map //.to-list)) + listR (|> (r.set n.hash sizeR gen-nat) (:: @ map //.to-list)) #let [(^open "/@.") /.equivalence - setL (/.from-list nat.order listL) - setR (/.from-list nat.order listR) - sortedL (list.sort n/< listL) + setL (/.from-list n.order listL) + setR (/.from-list n.order listR) + sortedL (list.sort n.< listL) minL (list.head sortedL) maxL (list.last sortedL)]] ($_ _.and (_.test "I can query the size of a set." - (n/= sizeL (/.size setL))) + (n.= sizeL (/.size setL))) (_.test "Can query minimum value." (case [(/.min setL) minL] [#.None #.None] true [(#.Some reference) (#.Some sample)] - (n/= reference sample) + (n.= reference sample) _ false)) @@ -76,19 +76,19 @@ true [(#.Some reference) (#.Some sample)] - (n/= reference sample) + (n.= reference sample) _ false)) (_.test "Converting sets to/from lists can't change their values." (|> setL - /.to-list (/.from-list nat.order) + /.to-list (/.from-list n.order) (/@= setL))) (_.test "Order is preserved." (let [listL (/.to-list setL) - (^open "list@.") (list.equivalence nat.equivalence)] + (^open "list@.") (list.equivalence n.equivalence)] (list@= listL - (list.sort n/< listL)))) + (list.sort n.< listL)))) (_.test "Every set is a sub-set of the union of itself with another." (let [setLR (/.union setL setR)] (and (/.sub? setLR setL) @@ -99,10 +99,10 @@ (/.super? setLR setR)))) (_.test "Union with the empty set leaves a set unchanged." (/@= setL - (/.union (/.new nat.order) + (/.union (/.new n.order) setL))) (_.test "Intersection with the empty set results in the empty set." - (let [empty-set (/.new nat.order)] + (let [empty-set (/.new n.order)] (/@= empty-set (/.intersection empty-set setL)))) (_.test "After substracting a set A from another B, no member of A can be a member of B." diff --git a/stdlib/source/test/lux/data/collection/stack.lux b/stdlib/source/test/lux/data/collection/stack.lux index 74ddf6c86..a71b128a8 100644 --- a/stdlib/source/test/lux/data/collection/stack.lux +++ b/stdlib/source/test/lux/data/collection/stack.lux @@ -11,7 +11,7 @@ [data ["." maybe] [number - ["." nat]]] + ["n" nat]]] [math ["r" random]]] {1 @@ -24,7 +24,7 @@ (def: gen-nat (r.Random Nat) (|> r.nat - (:: r.monad map (n/% 100)))) + (:: r.monad map (n.% 100)))) (def: #export test Test @@ -34,11 +34,11 @@ sample (r.stack size gen-nat) new-top gen-nat] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (r.stack size r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (r.stack size r.nat)) ($functor.spec ..injection /.equivalence /.functor) (_.test (%.name (name-of /.size)) - (n/= size (/.size sample))) + (n.= size (/.size sample))) (_.test (%.name (name-of /.peek)) (case (/.peek sample) #.None (/.empty? sample) @@ -53,7 +53,7 @@ false) expected (case (/.pop sample) (#.Some sample') - (and (n/= (dec expected) (/.size sample')) + (and (n.= (dec expected) (/.size sample')) (not (/.empty? sample))) #.None @@ -61,7 +61,7 @@ (_.test (%.name (name-of /.push)) (and (is? sample (|> sample (/.push new-top) /.pop maybe.assume)) - (n/= (inc (/.size sample)) + (n.= (inc (/.size sample)) (/.size (/.push new-top sample))) (|> (/.push new-top sample) /.peek maybe.assume (is? new-top)))) diff --git a/stdlib/source/test/lux/data/collection/tree.lux b/stdlib/source/test/lux/data/collection/tree.lux index 1506494c8..f42bc4f4d 100644 --- a/stdlib/source/test/lux/data/collection/tree.lux +++ b/stdlib/source/test/lux/data/collection/tree.lux @@ -11,7 +11,7 @@ ["$." functor]]}] [data [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." functor fold)]]] [math @@ -39,8 +39,8 @@ (do r.monad [value gen-value #let [size (dec size)] - left (tree (n// 2 size) gen-value) - right (tree (n/+ (n/% 2 size) (n// 2 size)) + left (tree (n./ 2 size) gen-value) + right (tree (n.+ (n.% 2 size) (n./ 2 size)) gen-value)] (wrap (/.branch value (list left right)))) ))) @@ -49,15 +49,15 @@ Test (<| (_.context (%.name (name-of /.Tree))) (do r.monad - [size (:: @ map (|>> (n/% 100) (n/+ 1)) r.nat)] + [size (:: @ map (|>> (n.% 100) (n.+ 1)) r.nat)] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (..tree size r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (..tree size r.nat)) ($fold.spec /.leaf /.equivalence /.fold) ($functor.spec /.leaf /.equivalence /.functor) (do @ [sample (..tree size r.nat)] (_.test "Can flatten a tree to get all the nodes as a flat tree." - (n/= size + (n.= size (list.size (/.flatten sample))))) )))) diff --git a/stdlib/source/test/lux/data/collection/tree/zipper.lux b/stdlib/source/test/lux/data/collection/tree/zipper.lux index 71d5a71cd..9ed7da62e 100644 --- a/stdlib/source/test/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/test/lux/data/collection/tree/zipper.lux @@ -9,7 +9,7 @@ ["." maybe] ["." text] [number - ["." nat]] + ["n" nat]] [collection ["." list]]] [math @@ -24,14 +24,14 @@ Test (<| (_.context (%.name (name-of /.Zipper))) (do r.monad - [size (:: @ map (|>> (n/% 90) (n/+ 10)) r.nat) + [size (:: @ map (|>> (n.% 90) (n.+ 10)) r.nat) sample (//.tree size r.nat) mid-val r.nat new-val r.nat pre-val r.nat post-val r.nat - #let [(^open "tree@.") (tree.equivalence nat.equivalence) - (^open "list@.") (list.equivalence nat.equivalence)]] + #let [(^open "tree@.") (tree.equivalence n.equivalence) + (^open "list@.") (list.equivalence n.equivalence)]] ($_ _.and (_.test "Trees can be converted to/from zippers." (|> sample @@ -86,14 +86,14 @@ (case> (#.Some _) false #.None true)))))) (_.test "Can set and update the value of a node." - (|> sample /.zip (/.set new-val) /.value (n/= new-val))) + (|> sample /.zip (/.set new-val) /.value (n.= new-val))) (_.test "Zipper traversal follows the outline of the tree depth-first." (let [root (/.zip sample)] (list@= (tree.flatten sample) (loop [zipper (/.start root)] (let [zipper' (/.next zipper)] (#.Cons (/.value zipper) - (if (:: (/.equivalence nat.equivalence) = root zipper') + (if (:: (/.equivalence n.equivalence) = root zipper') (list) (recur zipper')))))))) (_.test "Backwards zipper traversal yield reverse tree flatten." @@ -101,7 +101,7 @@ (list@= (list.reverse (tree.flatten sample)) (loop [zipper (/.end root)] (#.Cons (/.value zipper) - (if (:: (/.equivalence nat.equivalence) = root zipper) + (if (:: (/.equivalence n.equivalence) = root zipper) (list) (recur (/.prev zipper)))))))) (_.test "Can remove nodes (except start nodes)." diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index 4ccd4e337..6f16a0088 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -18,6 +18,7 @@ ["." maybe] ["." text] [number + ["n" nat] ["." frac]] [collection [row (#+ row)] @@ -50,7 +51,7 @@ (Random JSON) (r.rec (function (_ recur) (do r.monad - [size (:: @ map (n/% 2) r.nat)] + [size (:: @ map (n.% 2) r.nat)] ($_ r.or (:: @ wrap []) r.bit diff --git a/stdlib/source/test/lux/data/format/xml.lux b/stdlib/source/test/lux/data/format/xml.lux index a7236ede6..a3dc6b0e0 100644 --- a/stdlib/source/test/lux/data/format/xml.lux +++ b/stdlib/source/test/lux/data/format/xml.lux @@ -17,6 +17,8 @@ ["." name] ["." maybe] ["." text ("#@." equivalence)] + [number + ["n" nat]] [collection ["." dictionary] ["." list ("#@." functor)]]] @@ -34,12 +36,12 @@ (def: char (Random Nat) (do r.monad - [idx (|> r.nat (:: @ map (n/% (text.size char-range))))] + [idx (|> r.nat (:: @ map (n.% (text.size char-range))))] (wrap (maybe.assume (text.nth idx char-range))))) (def: (size bottom top) (-> Nat Nat (Random Nat)) - (let [constraint (|>> (n/% top) (n/max bottom))] + (let [constraint (|>> (n.% top) (n.max bottom))] (r@map constraint r.nat))) (def: (text bottom top) @@ -73,7 +75,7 @@ (do r.monad [text (..text 1 10) - num-children (|> r.nat (:: @ map (n/% 5))) + num-children (|> r.nat (:: @ map (n.% 5))) children (r.list num-children (..text 1 10)) tag xml-identifier^ attr xml-identifier^ diff --git a/stdlib/source/test/lux/data/lazy.lux b/stdlib/source/test/lux/data/lazy.lux index cfc096326..a52326bef 100644 --- a/stdlib/source/test/lux/data/lazy.lux +++ b/stdlib/source/test/lux/data/lazy.lux @@ -12,7 +12,7 @@ [data ["%" text/format (#+ format)] [number - ["." nat]]] + ["n" nat]]] [math ["r" random (#+ Random)]]] {1 @@ -37,16 +37,16 @@ (do r.monad [left r.nat right r.nat - #let [lazy (/.freeze (n/* left right)) - expected (n/* left right)]] + #let [lazy (/.freeze (n.* left right)) + expected (n.* left right)]] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (..lazy r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (..lazy r.nat)) ($functor.spec ..injection ..comparison /.functor) ($apply.spec ..injection ..comparison /.apply) ($monad.spec ..injection ..comparison /.monad) (_.test "Freezing does not alter the expected value." - (n/= expected + (n.= expected (/.thaw lazy))) (_.test "Lazy values only evaluate once." (and (not (is? expected diff --git a/stdlib/source/test/lux/data/maybe.lux b/stdlib/source/test/lux/data/maybe.lux index 60d154a7a..18d2f4248 100644 --- a/stdlib/source/test/lux/data/maybe.lux +++ b/stdlib/source/test/lux/data/maybe.lux @@ -16,7 +16,7 @@ ["." text ["%" format (#+ format)]] [number - ["." nat]]] + ["n" nat]]] [math ["r" random (#+ Random)]]] {1 @@ -30,7 +30,7 @@ Test (<| (_.context (%.name (name-of .Maybe))) ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (..maybe r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) (..maybe r.nat)) ($functor.spec /@wrap /.equivalence /.functor) ($apply.spec /@wrap /.equivalence /.apply) ($monad.spec /@wrap /.equivalence /.monad) @@ -38,15 +38,15 @@ (do r.monad [left r.nat right r.nat - #let [expected (n/+ left right)]] + #let [expected (n.+ left right)]] (let [lift (/.lift io.monad)] (_.test "Can add maybe functionality to any monad." (|> (io.run (do (/.with io.monad) [a (lift (io@wrap left)) b (wrap right)] - (wrap (n/+ a b)))) + (wrap (n.+ a b)))) (case> (#.Some actual) - (n/= expected actual) + (n.= expected actual) _ false))))) diff --git a/stdlib/source/test/lux/data/name.lux b/stdlib/source/test/lux/data/name.lux index 63acad50b..6190ab19a 100644 --- a/stdlib/source/test/lux/data/name.lux +++ b/stdlib/source/test/lux/data/name.lux @@ -10,6 +10,8 @@ [control pipe] [data + [number + ["n" nat]] ["." text ("#@." equivalence) ["%" format (#+ format)]]] [math @@ -31,12 +33,12 @@ (<| (_.context (%.name (name-of .Name))) (do r.monad [## First Name - sizeM1 (|> r.nat (:: @ map (n/% 100))) - sizeS1 (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1)))) + sizeM1 (|> r.nat (:: @ map (n.% 100))) + sizeS1 (|> r.nat (:: @ map (|>> (n.% 100) (n.max 1)))) (^@ name1 [module1 short1]) (..name sizeM1 sizeS1) ## Second Name - sizeM2 (|> r.nat (:: @ map (n/% 100))) - sizeS2 (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1)))) + sizeM2 (|> r.nat (:: @ map (n.% 100))) + sizeS2 (|> r.nat (:: @ map (|>> (n.% 100) (n.max 1)))) (^@ name2 [module2 short2]) (..name sizeM2 sizeS2)] ($_ _.and ($equivalence.spec /.equivalence (..name sizeM1 sizeS1)) diff --git a/stdlib/source/test/lux/data/number/complex.lux b/stdlib/source/test/lux/data/number/complex.lux index 1aa14e5be..5890ce0d4 100644 --- a/stdlib/source/test/lux/data/number/complex.lux +++ b/stdlib/source/test/lux/data/number/complex.lux @@ -11,6 +11,7 @@ ["$." codec]]}] [data [number + ["n" nat] ["." int] ["f" frac]] [collection @@ -34,7 +35,7 @@ (def: dimension (Random Frac) (do r.monad - [factor (|> r.nat (:: @ map (|>> (n/% 1000) (n/max 1)))) + [factor (|> r.nat (:: @ map (|>> (n.% 1000) (n.max 1)))) measure (|> r.safe-frac (r.filter (f.> +0.0)))] (wrap (f.* (|> factor .int int.frac) measure)))) @@ -184,7 +185,7 @@ Test (do r.monad [sample ..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 (/.roots degree) diff --git a/stdlib/source/test/lux/data/number/i64.lux b/stdlib/source/test/lux/data/number/i64.lux index fbfecf07a..838746854 100644 --- a/stdlib/source/test/lux/data/number/i64.lux +++ b/stdlib/source/test/lux/data/number/i64.lux @@ -16,7 +16,7 @@ ["r" random]]] {1 ["." / - ["." // #_ + ["/#" // #_ ["#." nat]]]}) (def: #export test @@ -24,21 +24,21 @@ (<| (_.context (name.module (name-of /._))) (do r.monad [pattern r.nat - idx (:: @ map (n/% /.width) r.nat)] + idx (:: @ map (//nat.% /.width) r.nat)] ($_ _.and ($equivalence.spec /.equivalence r.i64) ($monoid.spec //nat.equivalence /.disjunction r.nat) ($monoid.spec //nat.equivalence /.conjunction r.nat) (_.test "Clearing and settings bits should alter the count." - (and (n/= (dec (/.count (/.set idx pattern))) - (/.count (/.clear idx pattern))) + (and (//nat.= (dec (/.count (/.set idx pattern))) + (/.count (/.clear idx pattern))) (|> (/.count pattern) - (n/- (/.count (/.clear idx pattern))) - (n/<= 1)) + (//nat.- (/.count (/.clear idx pattern))) + (//nat.<= 1)) (|> (/.count (/.set idx pattern)) - (n/- (/.count pattern)) - (n/<= 1)))) + (//nat.- (/.count pattern)) + (//nat.<= 1)))) (_.test "Can query whether a bit is set." (and (or (and (/.set? idx pattern) (not (/.set? idx (/.clear idx pattern)))) @@ -50,38 +50,38 @@ (and (not (/.set? idx pattern)) (/.set? idx (/.flip idx pattern)))))) (_.test "The negation of a bit pattern should have a complementary bit-count." - (n/= /.width - (n/+ (/.count pattern) - (/.count (/.not pattern))))) + (//nat.= /.width + (//nat.+ (/.count pattern) + (/.count (/.not pattern))))) (_.test "Can do simple binary logic." - (and (n/= 0 - (/.and pattern - (/.not pattern))) - (n/= (/.not 0) - (/.or pattern - (/.not pattern))) - (n/= (/.not 0) - (/.xor pattern - (/.not pattern))) - (n/= 0 - (/.xor pattern - pattern)))) + (and (//nat.= 0 + (/.and pattern + (/.not pattern))) + (//nat.= (/.not 0) + (/.or pattern + (/.not pattern))) + (//nat.= (/.not 0) + (/.xor pattern + (/.not pattern))) + (//nat.= 0 + (/.xor pattern + pattern)))) (_.test "rotate-left and rotate-right are inverses of one another." (and (|> pattern (/.rotate-left idx) (/.rotate-right idx) - (n/= pattern)) + (//nat.= pattern)) (|> pattern (/.rotate-right idx) (/.rotate-left idx) - (n/= pattern)))) + (//nat.= pattern)))) (_.test "Rotate as many spaces as the bit-pattern's width leaves the pattern unchanged." (and (|> pattern (/.rotate-left /.width) - (n/= pattern)) + (//nat.= pattern)) (|> pattern (/.rotate-right /.width) - (n/= pattern)))) + (//nat.= pattern)))) (_.test "Shift right respect the sign of ints." (let [value (.int pattern)] (if (i.< +0 value) diff --git a/stdlib/source/test/lux/data/number/nat.lux b/stdlib/source/test/lux/data/number/nat.lux index 9a7f5907c..2a96ef9d5 100644 --- a/stdlib/source/test/lux/data/number/nat.lux +++ b/stdlib/source/test/lux/data/number/nat.lux @@ -40,10 +40,10 @@ )) (_.test "Alternate notations." - (and (n/= (bin "11001001") + (and (/.= (bin "11001001") (bin "11,00,10,01")) - (n/= (oct "615243") + (/.= (oct "615243") (oct "615,243")) - (n/= (hex "deadBEEF") + (/.= (hex "deadBEEF") (hex "dead,BEEF")))) )))) diff --git a/stdlib/source/test/lux/data/number/ratio.lux b/stdlib/source/test/lux/data/number/ratio.lux index f2162681d..fa3d6a01e 100644 --- a/stdlib/source/test/lux/data/number/ratio.lux +++ b/stdlib/source/test/lux/data/number/ratio.lux @@ -10,6 +10,9 @@ ["$." order] ["$." monoid] ["$." codec]]}] + [data + [number + ["n" nat]]] [math ["r" random (#+ Random)]]] {1 @@ -17,13 +20,13 @@ (def: part (Random Nat) - (|> r.nat (:: r.monad map (|>> (n/% 1,000,000) (n/max 1))))) + (|> r.nat (:: r.monad map (|>> (n.% 1,000,000) (n.max 1))))) (def: #export ratio (Random Ratio) (do r.monad [numerator ..part - denominator (r.filter (|>> (n/= 0) not) ..part)] + denominator (r.filter (|>> (n.= 0) not) ..part)] (wrap (/.ratio numerator denominator)))) (def: #export test diff --git a/stdlib/source/test/lux/data/sum.lux b/stdlib/source/test/lux/data/sum.lux index 29e02de04..b90206fe7 100644 --- a/stdlib/source/test/lux/data/sum.lux +++ b/stdlib/source/test/lux/data/sum.lux @@ -6,6 +6,8 @@ pipe] [data ["." text] + [number + ["n" nat]] [collection ["." list]]]] {1 @@ -30,10 +32,10 @@ (/.rights (: (List (| Text Text)) (list (0 "0") (1 "1") (0 "2")))))))) (_.test "Can apply a function to an Either value depending on the case." - (and (n/= 10 (/.either (function (_ _) 10) + (and (n.= 10 (/.either (function (_ _) 10) (function (_ _) 20) (: (| Text Text) (0 "")))) - (n/= 20 (/.either (function (_ _) 10) + (n.= 20 (/.either (function (_ _) 10) (function (_ _) 20) (: (| Text Text) (1 "")))))) )))) diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux index 8adabf715..b3cd2e735 100644 --- a/stdlib/source/test/lux/data/text.lux +++ b/stdlib/source/test/lux/data/text.lux @@ -11,6 +11,8 @@ [control pipe] [data + [number + ["n" nat]] [collection ["." list]]] [math @@ -21,7 +23,7 @@ (def: bounded-size (r.Random Nat) (|> r.nat - (:: r.monad map (|>> (n/% 20) (n/+ 1))))) + (:: r.monad map (|>> (n.% 20) (n.+ 1))))) (def: #export test Test @@ -31,17 +33,17 @@ ($order.spec /.order (r.ascii 2)) (do r.monad - [size (:: @ map (n/% 10) r.nat) + [size (:: @ map (n.% 10) r.nat) sample (r.unicode size)] ($_ _.and (_.test "Can get the size of text." - (n/= size (/.size sample))) + (n.= size (/.size sample))) (_.test "Text with size 0 is considered 'empty'." - (or (not (n/= 0 size)) + (or (not (n.= 0 size)) (/.empty? sample))))) (do r.monad [size bounded-size - idx (:: @ map (n/% size) r.nat) + idx (:: @ map (n.% size) r.nat) sample (r.unicode size)] (_.test "Character locations." (|> sample @@ -54,11 +56,11 @@ (/.last-index-of' char idx sample)] [(#.Some io) (#.Some lio) (#.Some io') (#.Some lio')]]) - (and (n/<= idx io) - (n/>= idx lio) + (and (n.<= idx io) + (n.>= idx lio) - (n/= idx io') - (n/>= idx lio') + (n.= idx io') + (n.>= idx lio') (/.contains? char sample)) @@ -114,7 +116,7 @@ #let [## The wider unicode charset includes control characters that ## can make text replacement work improperly. ## Because of that, I restrict the charset. - normal-char-gen (|> r.nat (:: @ map (|>> (n/% 128) (n/max 1))))] + normal-char-gen (|> r.nat (:: @ map (|>> (n.% 128) (n.max 1))))] sep1 (r.text normal-char-gen 1) sep2 (r.text normal-char-gen 1) #let [part-gen (|> (r.text normal-char-gen sizeP) @@ -125,7 +127,7 @@ (^open "/@.") /.equivalence]] ($_ _.and (_.test "Can split text multiple times through a separator." - (n/= (list.size parts) + (n.= (list.size parts) (list.size (/.split-all-with sep1 sample1)))) (_.test "Can replace occurrences of a piece of text inside a larger text." diff --git a/stdlib/source/test/lux/host.jvm.lux b/stdlib/source/test/lux/host.jvm.lux index d1753e7a1..8ff26e2e9 100644 --- a/stdlib/source/test/lux/host.jvm.lux +++ b/stdlib/source/test/lux/host.jvm.lux @@ -6,6 +6,7 @@ [data ["." text ("#;." equivalence)] [number + ["n" nat] ["i" int]]] [math ["r" random]] @@ -121,12 +122,12 @@ (def: arrays Test (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1)))) - idx (|> r.nat (:: @ map (n/% size))) + [size (|> r.nat (:: @ map (|>> (n.% 100) (n.max 1)))) + idx (|> r.nat (:: @ map (n.% size))) value r.int] ($_ _.and (_.test "Can create arrays of some length." - (n/= size (/.array-length (/.array Long size)))) + (n.= size (/.array-length (/.array Long size)))) (_.test "Can set and get array values." (let [arr (/.array Long size)] diff --git a/stdlib/source/test/lux/host.old.lux b/stdlib/source/test/lux/host.old.lux index 19e8ae9ba..9258aa5de 100644 --- a/stdlib/source/test/lux/host.old.lux +++ b/stdlib/source/test/lux/host.old.lux @@ -6,6 +6,7 @@ [data ["." text ("#;." equivalence)] [number + ["n" nat] ["i" int]]] [math ["r" random]] @@ -114,12 +115,12 @@ (def: arrays Test (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1)))) - idx (|> r.nat (:: @ map (n/% size))) + [size (|> r.nat (:: @ map (|>> (n.% 100) (n.max 1)))) + idx (|> r.nat (:: @ map (n.% size))) value r.int] ($_ _.and (_.test "Can create arrays of some length." - (n/= size (/.array-length (/.array Long size)))) + (n.= size (/.array-length (/.array Long size)))) (_.test "Can set and get array values." (let [arr (/.array Long size)] diff --git a/stdlib/source/test/lux/macro/poly/equivalence.lux b/stdlib/source/test/lux/macro/poly/equivalence.lux index adf150aee..7b9d0b97c 100644 --- a/stdlib/source/test/lux/macro/poly/equivalence.lux +++ b/stdlib/source/test/lux/macro/poly/equivalence.lux @@ -11,6 +11,7 @@ ["." bit] ["." maybe] [number + ["n" nat] ["i" int]] ["." text] [collection @@ -49,7 +50,7 @@ (def: gen-record (Random Record) (do random.monad - [size (:: @ map (n/% 2) random.nat) + [size (:: @ map (n.% 2) random.nat) #let [gen-int (|> random.int (:: @ map (|>> i.abs (i.% +1,000,000))))]] ($_ random.and random.bit diff --git a/stdlib/source/test/lux/macro/poly/json.lux b/stdlib/source/test/lux/macro/poly/json.lux index 0921cce9e..8a72e0e2b 100644 --- a/stdlib/source/test/lux/macro/poly/json.lux +++ b/stdlib/source/test/lux/macro/poly/json.lux @@ -20,6 +20,7 @@ ["." maybe] ["." text] [number + ["n" nat] ["." frac]] [format [json (#+)]] @@ -89,7 +90,7 @@ (def: gen-record (Random Record) (do r.monad - [size (:: @ map (n/% 2) r.nat)] + [size (:: @ map (n.% 2) r.nat)] ($_ r.and r.bit r.frac diff --git a/stdlib/source/test/lux/math.lux b/stdlib/source/test/lux/math.lux index ffe990c50..17ed2086c 100644 --- a/stdlib/source/test/lux/math.lux +++ b/stdlib/source/test/lux/math.lux @@ -7,6 +7,7 @@ [data ["." bit ("#@." equivalence)] [number + ["n" nat] ["." int] ["f" frac]]]] {1 @@ -71,21 +72,21 @@ (|> sample /.exp /.log (within? +0.000000000000001 sample))))) (<| (_.context "Greatest-Common-Divisor and Least-Common-Multiple") (do r.monad - [#let [gen-nat (|> r.nat (:: @ map (|>> (n/% 1000) (n/max 1))))] + [#let [gen-nat (|> r.nat (:: @ map (|>> (n.% 1000) (n.max 1))))] x gen-nat y gen-nat] ($_ _.and (_.test "GCD" - (let [gcd (/.n/gcd x y)] - (and (n/= 0 (n/% gcd x)) - (n/= 0 (n/% gcd y)) - (n/>= 1 gcd)))) + (let [gcd (n.gcd x y)] + (and (n.= 0 (n.% gcd x)) + (n.= 0 (n.% gcd y)) + (n.>= 1 gcd)))) (_.test "LCM" - (let [lcm (/.n/lcm x y)] - (and (n/= 0 (n/% x lcm)) - (n/= 0 (n/% y lcm)) - (n/<= (n/* x y) lcm)))) + (let [lcm (n.lcm x y)] + (and (n.= 0 (n.% x lcm)) + (n.= 0 (n.% y lcm)) + (n.<= (n.* x y) lcm)))) ))) /infix.test diff --git a/stdlib/source/test/lux/math/infix.lux b/stdlib/source/test/lux/math/infix.lux index e2850f549..8085d5f98 100644 --- a/stdlib/source/test/lux/math/infix.lux +++ b/stdlib/source/test/lux/math/infix.lux @@ -7,6 +7,7 @@ [data ["." bit ("#@." equivalence)] [number + ["n" nat] ["f" frac]]]] {1 ["." / @@ -22,23 +23,23 @@ angle r.frac] ($_ _.and (_.test "Constant values don't change." - (n/= subject + (n.= subject (/.infix subject))) (_.test "Can call binary functions." - (n/= (//.n/gcd parameter subject) - (/.infix [subject //.n/gcd parameter]))) + (n.= (n.gcd parameter subject) + (/.infix [subject n.gcd parameter]))) (_.test "Can call unary functions." (f.= (//.sin angle) (/.infix [//.sin angle]))) (_.test "Can use regular syntax in the middle of infix code." - (n/= (//.n/gcd extra (n/* parameter subject)) - (/.infix [(n/* parameter subject) //.n/gcd extra]))) + (n.= (n.gcd extra (n.* parameter subject)) + (/.infix [(n.* parameter subject) n.gcd extra]))) (_.test "Can use non-numerical functions/macros as operators." - (bit@= (and (n/< parameter subject) (n/< extra parameter)) - (/.infix [[subject n/< parameter] and [parameter n/< extra]]))) + (bit@= (and (n.< parameter subject) (n.< extra parameter)) + (/.infix [[subject n.< parameter] and [parameter n.< extra]]))) (_.test "Can combine bit operations in special ways via special keywords." - (and (bit@= (and (n/< parameter subject) (n/< extra parameter)) - (/.infix [#and subject n/< parameter n/< extra])) - (bit@= (and (n/< parameter subject) (n/> extra parameter)) - (/.infix [#and subject n/< parameter n/> extra])))) + (and (bit@= (and (n.< parameter subject) (n.< extra parameter)) + (/.infix [#and subject n.< parameter n.< extra])) + (bit@= (and (n.< parameter subject) (n.> extra parameter)) + (/.infix [#and subject n.< parameter n.> extra])))) )))) diff --git a/stdlib/source/test/lux/math/logic/fuzzy.lux b/stdlib/source/test/lux/math/logic/fuzzy.lux index 35dff4a03..e53028522 100644 --- a/stdlib/source/test/lux/math/logic/fuzzy.lux +++ b/stdlib/source/test/lux/math/logic/fuzzy.lux @@ -8,7 +8,7 @@ [data ["." bit ("#@." equivalence)] [number - ["." nat] + ["n" nat] ["r" rev]] [collection ["." list] @@ -142,12 +142,12 @@ (def: predicates-and-sets Test (do random.monad - [#let [set-10 (set.from-list nat.hash (list.n/range 0 10))] - sample (|> random.nat (:: @ map (n/% 20)))] + [#let [set-10 (set.from-list n.hash (list.n/range 0 10))] + sample (|> random.nat (:: @ map (n.% 20)))] ($_ _.and (_.test (%.name (name-of /.from-predicate)) - (bit@= (r.= //.true (/.membership sample (/.from-predicate n/even?))) - (n/even? sample))) + (bit@= (r.= //.true (/.membership sample (/.from-predicate n.even?))) + (n.even? sample))) (_.test (%.name (name-of /.from-set)) (bit@= (r.= //.true (/.membership sample (/.from-set set-10))) (set.member? set-10 sample))) diff --git a/stdlib/source/test/lux/time/duration.lux b/stdlib/source/test/lux/time/duration.lux index 9eea2e03b..fe196cb29 100644 --- a/stdlib/source/test/lux/time/duration.lux +++ b/stdlib/source/test/lux/time/duration.lux @@ -12,6 +12,7 @@ ["$." codec]]}] [data [number + ["n" nat] ["i" int]]] [math ["r" random (#+ Random)]]] @@ -39,7 +40,7 @@ (do r.monad [sample (|> duration (:: @ map (/.frame /.day))) frame duration - factor (|> r.nat (:: @ map (|>> (n/% 10) (n/max 1)))) + factor (|> r.nat (:: @ map (|>> (n.% 10) (n.max 1)))) #let [(^open "/@.") /.order]] ($_ _.and (_.test "Can scale a duration." diff --git a/stdlib/source/test/lux/tool/compiler/default/syntax.lux b/stdlib/source/test/lux/tool/compiler/default/syntax.lux index 1b9e5c7a4..2b53cbfdb 100644 --- a/stdlib/source/test/lux/tool/compiler/default/syntax.lux +++ b/stdlib/source/test/lux/tool/compiler/default/syntax.lux @@ -3,7 +3,9 @@ [abstract/monad (#+ do)] [data ["%" text/format (#+ format)] - ["." name]] + ["." name] + [number + ["n" nat]]] ["r" math/random (#+ Random) ("#@." monad)] ["_" test (#+ Test)] [control @@ -29,7 +31,7 @@ (def: name-part^ (Random Text) (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 20) (n/max 1))))] + [size (|> r.nat (:: @ map (|>> (n.% 20) (n.max 1))))] (r.ascii/lower-alpha size))) (def: name^ @@ -48,7 +50,7 @@ textual^ (: (Random Code) ($_ r.either (do r.monad - [size (|> r.nat (r@map (n/% 20)))] + [size (|> r.nat (r@map (n.% 20)))] (|> (r.ascii/upper-alpha size) (r@map code.text))) (|> name^ (r@map code.identifier)) (|> name^ (r@map code.tag)))) @@ -59,14 +61,14 @@ (r.rec (function (_ code^) (let [multi^ (do r.monad - [size (|> r.nat (r@map (n/% 3)))] + [size (|> r.nat (r@map (n.% 3)))] (r.list size code^)) composite^ (: (Random Code) ($_ r.either (|> multi^ (r@map code.form)) (|> multi^ (r@map code.tuple)) (do r.monad - [size (|> r.nat (r@map (n/% 3)))] + [size (|> r.nat (r@map (n.% 3)))] (|> (r.list size (r.and code^ code^)) (r@map code.record)))))] ($_ r.either @@ -110,9 +112,9 @@ (def: comment-text^ (Random Text) - (let [char-gen (|> r.nat (r.filter (|>> (n/= (`` (char (~~ (static text.new-line))))) not)))] + (let [char-gen (|> r.nat (r.filter (|>> (n.= (`` (char (~~ (static text.new-line))))) not)))] (do r.monad - [size (|> r.nat (r@map (n/% 20)))] + [size (|> r.nat (r@map (n.% 20)))] (r.text char-gen size)))) (def: comment^ diff --git a/stdlib/source/test/lux/tool/compiler/phase/analysis/case.lux b/stdlib/source/test/lux/tool/compiler/phase/analysis/case.lux index 30b446bb5..1a74a3cf2 100644 --- a/stdlib/source/test/lux/tool/compiler/phase/analysis/case.lux +++ b/stdlib/source/test/lux/tool/compiler/phase/analysis/case.lux @@ -12,6 +12,8 @@ ["." product] ["." maybe] ["." text ("#@." equivalence)] + [number + ["n" nat]] [collection ["." list ("#@." monad)] ["." set]]] @@ -116,12 +118,12 @@ ($_ r.either (r@map product.right _primitive.primitive) (do r.monad - [choice (|> r.nat (:: @ map (n/% (list.size variant-tags)))) + [choice (|> r.nat (:: @ map (n.% (list.size variant-tags)))) #let [choiceT (maybe.assume (list.nth choice variant-tags)) choiceC (maybe.assume (list.nth choice primitivesC))]] (wrap (` ((~ choiceT) (~ choiceC))))) (do r.monad - [size (|> r.nat (:: @ map (n/% 3))) + [size (|> r.nat (:: @ map (n.% 3))) elems (r.list size input)] (wrap (code.tuple elems))) (r@wrap (code.record (list.zip2 record-tags primitivesC))) @@ -137,7 +139,7 @@ [module-name (r.unicode 5) variant-name (r.unicode 5) record-name (|> (r.unicode 5) (r.filter (|>> (text@= variant-name) not))) - size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) + size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) variant-tags (|> (r.set text.hash size (r.unicode 5)) (:: @ map set.to-list)) record-tags (|> (r.set text.hash size (r.unicode 5)) (:: @ map set.to-list)) primitivesTC (r.list size _primitive.primitive) @@ -178,7 +180,7 @@ _structure.check-fails))) (do @ [redundant-patterns (exhaustive-branches false variantTC inputC) - redundancy-idx (|> r.nat (:: @ map (n/% (list.size redundant-patterns)))) + redundancy-idx (|> r.nat (:: @ map (n.% (list.size redundant-patterns)))) #let [redundant-branchesC (<| (list@map (branch outputC)) list.concat (list (list.take redundancy-idx redundant-patterns) @@ -190,7 +192,7 @@ (do @ [[heterogeneousT heterogeneousC] (r.filter (|>> product.left (check.checks? outputT) not) _primitive.primitive) - heterogeneous-idx (|> r.nat (:: @ map (n/% (list.size exhaustive-patterns)))) + heterogeneous-idx (|> r.nat (:: @ map (n.% (list.size exhaustive-patterns)))) #let [heterogeneous-branchesC (list.concat (list (list.take heterogeneous-idx exhaustive-branchesC) (list (let [[_pattern _body] (maybe.assume (list.nth heterogeneous-idx exhaustive-branchesC))] [_pattern heterogeneousC])) diff --git a/stdlib/source/test/lux/tool/compiler/phase/analysis/function.lux b/stdlib/source/test/lux/tool/compiler/phase/analysis/function.lux index 7d5046571..721e17b14 100644 --- a/stdlib/source/test/lux/tool/compiler/phase/analysis/function.lux +++ b/stdlib/source/test/lux/tool/compiler/phase/analysis/function.lux @@ -13,6 +13,8 @@ ["." maybe] ["." product] ["." text ("#@." equivalence)] + [number + ["n" nat]] [collection ["." list ("#@." functor)]]] ["." type] @@ -38,7 +40,7 @@ (///.run _primitive.state) (case> (#try.Success applyA) (let [[funcA argsA] (////analysis.application applyA)] - (n/= num-args (list.size argsA))) + (n.= num-args (list.size argsA))) (#try.Failure _) false))) @@ -74,9 +76,9 @@ (def: apply (do r.monad - [full-args (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) - partial-args (|> r.nat (:: @ map (n/% full-args))) - var-idx (|> r.nat (:: @ map (|>> (n/% full-args) (n/max 1)))) + [full-args (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) + partial-args (|> r.nat (:: @ map (n.% full-args))) + var-idx (|> r.nat (:: @ map (|>> (n.% full-args) (n.max 1)))) inputsTC (r.list full-args _primitive.primitive) #let [inputsT (list@map product.left inputsTC) inputsC (list@map product.right inputsTC)] diff --git a/stdlib/source/test/lux/tool/compiler/phase/analysis/reference.lux b/stdlib/source/test/lux/tool/compiler/phase/analysis/reference.lux index 777fe152f..1c23b1c8a 100644 --- a/stdlib/source/test/lux/tool/compiler/phase/analysis/reference.lux +++ b/stdlib/source/test/lux/tool/compiler/phase/analysis/reference.lux @@ -9,7 +9,9 @@ pipe ["." try (#+ Try)]] [data - ["." text ("#@." equivalence)]] + ["." text ("#@." equivalence)] + [number + ["n" nat]]] ["." type ("#@." equivalence)] [macro ["." code]]] @@ -74,7 +76,7 @@ (///.run _primitive.state) (case> (^ (#try.Success [inferredT (#////analysis.Reference (////reference.local var))])) (and (type@= expectedT inferredT) - (n/= 0 var)) + (n.= 0 var)) _ false))) diff --git a/stdlib/source/test/lux/tool/compiler/phase/analysis/structure.lux b/stdlib/source/test/lux/tool/compiler/phase/analysis/structure.lux index 08344f23e..ad2233b26 100644 --- a/stdlib/source/test/lux/tool/compiler/phase/analysis/structure.lux +++ b/stdlib/source/test/lux/tool/compiler/phase/analysis/structure.lux @@ -14,6 +14,8 @@ ["." product] ["." maybe] ["." text] + [number + ["n" nat]] [collection ["." list ("#@." functor)] ["." set]]] @@ -48,13 +50,13 @@ (def: (check-sum' tag size variant) (-> Tag Nat (Variant Analysis) Bit) - (let [expected//right? (n/= (dec size) tag) + (let [expected//right? (n.= (dec size) tag) expected//lefts (if expected//right? (dec tag) tag) actual//right? (get@ #////analysis.right? variant) actual//lefts (get@ #////analysis.lefts variant)] - (and (n/= expected//lefts + (and (n.= expected//lefts actual//lefts) (bit@= expected//right? actual//right?)))) @@ -93,7 +95,7 @@ (|>> (case> (^ (////analysis.tuple elems)) (|> elems list.size - (n/= size)) + (n.= size)) _ false))) @@ -112,10 +114,10 @@ (def: sum (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) - choice (|> r.nat (:: @ map (n/% size))) + [size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) + choice (|> r.nat (:: @ map (n.% size))) primitives (r.list size _primitive.primitive) - +choice (|> r.nat (:: @ map (n/% (inc size)))) + +choice (|> r.nat (:: @ map (n.% (inc size)))) [_ +valueC] _primitive.primitive #let [variantT (type.variant (list@map product.left primitives)) [valueT valueC] (maybe.assume (list.nth choice primitives)) @@ -154,7 +156,7 @@ (/.sum _primitive.phase +choice +valueC)) check-succeeds)) (_.test "Can analyse through universal quantification." - (let [check-outcome (if (not (n/= choice +choice)) + (let [check-outcome (if (not (n.= choice +choice)) check-succeeds check-fails)] (|> (//type.with-type (type.univ-q 1 +variantT) @@ -164,9 +166,9 @@ (def: product (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) + [size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) primitives (r.list size _primitive.primitive) - choice (|> r.nat (:: @ map (n/% size))) + choice (|> r.nat (:: @ map (n.% size))) [_ +valueC] _primitive.primitive #let [tupleT (type.tuple (list@map product.left primitives)) [singletonT singletonC] (|> primitives (list.nth choice) maybe.assume) @@ -224,10 +226,10 @@ (def: variant (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) + [size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) tags (|> (r.set text.hash size (r.unicode 5)) (:: @ map set.to-list)) - choice (|> r.nat (:: @ map (n/% size))) - other-choice (|> r.nat (:: @ map (n/% size)) (r.filter (|>> (n/= choice) not))) + choice (|> r.nat (:: @ map (n.% size))) + other-choice (|> r.nat (:: @ map (n.% size)) (r.filter (|>> (n.= choice) not))) primitives (r.list size _primitive.primitive) module-name (r.unicode 5) type-name (r.unicode 5) @@ -270,12 +272,12 @@ (def: record (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) + [size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) tags (|> (r.set text.hash size (r.unicode 5)) (:: @ map set.to-list)) primitives (r.list size _primitive.primitive) module-name (r.unicode 5) type-name (r.unicode 5) - choice (|> r.nat (:: @ map (n/% size))) + choice (|> r.nat (:: @ map (n.% size))) #let [varT (#.Parameter 1) tagsC (list@map (|>> [module-name] code.tag) tags) primitivesT (list@map product.left primitives) diff --git a/stdlib/source/test/lux/tool/compiler/phase/synthesis/case.lux b/stdlib/source/test/lux/tool/compiler/phase/synthesis/case.lux index d2d310fa1..13418eba0 100644 --- a/stdlib/source/test/lux/tool/compiler/phase/synthesis/case.lux +++ b/stdlib/source/test/lux/tool/compiler/phase/synthesis/case.lux @@ -2,7 +2,9 @@ [lux #* [abstract ["." monad (#+ do)]] [data - ["." name]] + ["." name] + [number + ["n" nat]]] ["r" math/random (#+ Random) ("#@." monad)] ["_" test (#+ Test)] [control @@ -25,7 +27,7 @@ Test (do r.monad [maskedA //primitive.primitive - temp (|> r.nat (:: @ map (n/% 100))) + temp (|> r.nat (:: @ map (n.% 100))) #let [maskA (////analysis.control/case [maskedA [[(#////analysis.Bind temp) @@ -54,7 +56,7 @@ //.phase (///.run [///bundle.empty ////synthesis.init]) (case> (^ (#try.Success (////synthesis.branch/let [inputS registerS outputS]))) - (and (n/= registerA registerS) + (and (n.= registerA registerS) (//primitive.corresponds? inputA inputS) (//primitive.corresponds? outputA outputS)) diff --git a/stdlib/source/test/lux/tool/compiler/phase/synthesis/function.lux b/stdlib/source/test/lux/tool/compiler/phase/synthesis/function.lux index 368b692e9..db6c38eca 100644 --- a/stdlib/source/test/lux/tool/compiler/phase/synthesis/function.lux +++ b/stdlib/source/test/lux/tool/compiler/phase/synthesis/function.lux @@ -12,7 +12,7 @@ ["." product] ["." maybe] [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." functor fold)] ["dict" dictionary (#+ Dictionary)] @@ -48,12 +48,12 @@ (def: (pick scope-size) (-> Nat (Random Nat)) - (|> r.nat (:: r.monad map (n/% scope-size)))) + (|> r.nat (:: r.monad map (n.% scope-size)))) (def: function-with-environment (Random [Arity Analysis Variable]) (do r.monad - [num-locals (|> r.nat (:: @ map (|>> (n/% 100) (n/max 10)))) + [num-locals (|> r.nat (:: @ map (|>> (n.% 100) (n.max 10)))) #let [indices (list.n/range 0 (dec num-locals)) local-env (list@map (|>> #////reference.Local) indices) foreign-env (list@map (|>> #////reference.Foreign) indices)] @@ -64,14 +64,14 @@ resolver (list@fold (function (_ [idx var] resolver) (dict.put idx var resolver)) (: (Dictionary Nat Variable) - (dict.new nat.hash)) + (dict.new n.hash)) (list.enumerate current-env))] (do @ [nest? r.bit] (if nest? (do @ - [num-picks (:: @ map (n/max 1) (pick (inc current-env/size))) - picks (|> (r.set nat.hash num-picks (pick current-env/size)) + [num-picks (:: @ map (n.max 1) (pick (inc current-env/size))) + picks (|> (r.set n.hash num-picks (pick current-env/size)) (:: @ map set.to-list)) [arity bodyA predictionA] (recur (inc arity) (list@map (function (_ pick) @@ -102,10 +102,10 @@ (#////analysis.Function (list) bodyA) predictionA])) (do r.monad - [chosen (|> r.nat (:: @ map (|>> (n/% 100) (n/max 2))))] + [chosen (|> r.nat (:: @ map (|>> (n.% 100) (n.max 2))))] (wrap [arity (#////analysis.Reference (////reference.local chosen)) - (|> chosen (n/+ (dec arity)) #////reference.Local)]))))) + (|> chosen (n.+ (dec arity)) #////reference.Local)]))))) (def: abstraction Test @@ -119,17 +119,17 @@ //.phase (///.run [///bundle.empty ////synthesis.init]) (case> (^ (#try.Success (////synthesis.function/abstraction [environment arity output]))) - (and (n/= arity//constant arity) + (and (n.= arity//constant arity) (//primitive.corresponds? prediction//constant output)) _ - (n/= 0 arity//constant)))) + (n.= 0 arity//constant)))) (_.test "Folded functions provide direct access to environment variables." (|> function//environment //.phase (///.run [///bundle.empty ////synthesis.init]) (case> (^ (#try.Success (////synthesis.function/abstraction [environment arity (#////synthesis.Reference (////reference.variable output))]))) - (and (n/= arity//environment arity) + (and (n.= arity//environment arity) (variable@= prediction//environment output)) _ @@ -139,7 +139,7 @@ //.phase (///.run [///bundle.empty ////synthesis.init]) (case> (^ (#try.Success (////synthesis.function/abstraction [environment arity (#////synthesis.Reference (////reference.variable output))]))) - (and (n/= arity//local arity) + (and (n.= arity//local arity) (variable@= prediction//local output)) _ @@ -149,7 +149,7 @@ (def: application Test (do r.monad - [arity (|> r.nat (:: @ map (|>> (n/% 10) (n/max 1)))) + [arity (|> r.nat (:: @ map (|>> (n.% 10) (n.max 1)))) funcA //primitive.primitive argsA (r.list arity //primitive.primitive)] ($_ _.and diff --git a/stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux b/stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux index 76405c771..087756562 100644 --- a/stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux +++ b/stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux @@ -12,6 +12,8 @@ [data ["." bit ("#@." equivalence)] ["." product] + [number + ["n" nat]] [collection ["." list]]]] ["." // #_ @@ -29,9 +31,9 @@ (def: variant Test (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 10) (n/+ 2)))) - tagA (|> r.nat (:: @ map (n/% size))) - #let [right? (n/= (dec size) tagA) + [size (|> r.nat (:: @ map (|>> (n.% 10) (n.+ 2)))) + tagA (|> r.nat (:: @ map (n.% size))) + #let [right? (n.= (dec size) tagA) lefts (if right? (dec tagA) tagA)] @@ -42,8 +44,8 @@ (///.run [///bundle.empty ////synthesis.init]) (case> (^ (#try.Success (////synthesis.variant [leftsS right?S valueS]))) (let [tagS (if right?S (inc leftsS) leftsS)] - (and (n/= tagA tagS) - (|> tagS (n/= (dec size)) (bit@= right?S)) + (and (n.= tagA tagS) + (|> tagS (n.= (dec size)) (bit@= right?S)) (//primitive.corresponds? memberA valueS))) _ @@ -52,14 +54,14 @@ (def: tuple Test (do r.monad - [size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) + [size (|> r.nat (:: @ map (|>> (n.% 10) (n.max 2)))) membersA (r.list size //primitive.primitive)] (_.test "Can synthesize tuple." (|> (////analysis.tuple membersA) //.phase (///.run [///bundle.empty ////synthesis.init]) (case> (^ (#try.Success (////synthesis.tuple membersS))) - (and (n/= size (list.size membersS)) + (and (n.= size (list.size membersS)) (list.every? (product.uncurry //primitive.corresponds?) (list.zip2 membersA membersS))) diff --git a/stdlib/source/test/lux/type.lux b/stdlib/source/test/lux/type.lux index c3931c331..f129f1c5a 100644 --- a/stdlib/source/test/lux/type.lux +++ b/stdlib/source/test/lux/type.lux @@ -8,6 +8,8 @@ pipe] [data ["." maybe] + [number + ["n" nat]] [collection ["." list]]]] {1 @@ -21,7 +23,7 @@ (def: short (r.Random Text) (do r.monad - [size (|> r.nat (:: @ map (n/% 10)))] + [size (|> r.nat (:: @ map (n.% 10)))] (r.unicode size))) (def: name @@ -82,7 +84,7 @@ (/.un-name base) (/.un-name aliased)))))) (do r.monad - [size (|> r.nat (:: @ map (n/% 3))) + [size (|> r.nat (:: @ map (n.% 3))) members (|> ..type (r.filter (function (_ type) (case type @@ -108,7 +110,7 @@ )) ))) (do r.monad - [size (|> r.nat (:: @ map (n/% 3))) + [size (|> r.nat (:: @ map (n.% 3))) members (M.seq @ (list.repeat size ..type)) extra (|> ..type (r.filter (function (_ type) @@ -128,10 +130,10 @@ (_.test "Can build and tear-down application types." (let [[tfunc tparams] (|> extra (/.application members) /.flatten-application)] - (n/= (list.size members) (list.size tparams)))) + (n.= (list.size members) (list.size tparams)))) )) (do r.monad - [size (|> r.nat (:: @ map (n/% 3))) + [size (|> r.nat (:: @ map (n.% 3))) extra (|> ..type (r.filter (function (_ type) (case type @@ -145,7 +147,7 @@ (~~ (template [<desc> <ctor> <dtor>] [(_.test (format "Can build and tear-down " <desc> " types.") (let [[flat-size flat-body] (|> extra (<ctor> size) <dtor>)] - (and (n/= size flat-size) + (and (n.= size flat-size) (/@= extra flat-body))))] ["universally-quantified" /.univ-q /.flatten-univ-q] diff --git a/stdlib/source/test/lux/type/check.lux b/stdlib/source/test/lux/type/check.lux index d3d0570a1..2184de475 100644 --- a/stdlib/source/test/lux/type/check.lux +++ b/stdlib/source/test/lux/type/check.lux @@ -12,7 +12,7 @@ ["." maybe] ["." text ("#@." equivalence)] [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." functor)] ["." set]]] @@ -189,7 +189,7 @@ (/.check .Bit var)))) ) (do r.monad - [num-connections (|> r.nat (:: @ map (n/% 100))) + [num-connections (|> r.nat (:: @ map (n.% 100))) boundT (|> ..type (r.filter (|>> (case> (#.Var _) #0 _ #1)))) pick-pcg (r.and r.nat r.nat)] ($_ _.and @@ -201,10 +201,10 @@ tailR (/.ring tail-id)] (/.assert "" (let [same-rings? (:: set.equivalence = headR tailR) - expected-size? (n/= (inc num-connections) (set.size headR)) + expected-size? (n.= (inc num-connections) (set.size headR)) same-vars? (|> (set.to-list headR) - (list.sort n/<) - (:: (list.equivalence nat.equivalence) = (list.sort n/< (#.Cons head-id ids))))] + (list.sort n.<) + (:: (list.equivalence n.equivalence) = (list.sort n.< (#.Cons head-id ids))))] (and same-rings? expected-size? same-vars?)))))) @@ -237,7 +237,7 @@ headRR-post (/.ring head-idR)] (/.assert "" (let [same-rings? (:: set.equivalence = headRL-post headRR-post) - expected-size? (n/= (n/* 2 (inc num-connections)) + expected-size? (n.= (n.* 2 (inc num-connections)) (set.size headRL-post)) union? (:: set.equivalence = headRL-post (set.union headRL-pre headRR-pre))] (and same-rings? diff --git a/stdlib/source/test/lux/type/dynamic.lux b/stdlib/source/test/lux/type/dynamic.lux index b84a6f0a3..960a8ab9d 100644 --- a/stdlib/source/test/lux/type/dynamic.lux +++ b/stdlib/source/test/lux/type/dynamic.lux @@ -5,7 +5,10 @@ ["r" math/random (#+ Random)] ["_" test (#+ Test)] [control - ["." try]]] + ["." try]] + [data + [number + ["n" nat]]]] {1 ["." / (#+ Dynamic :dynamic :check)]}) @@ -19,7 +22,7 @@ (_.test "Can check dynamic values." (case (:check Nat value) (#try.Success actual) - (n/= expected actual) + (n.= expected actual) (#try.Failure _) false)) diff --git a/stdlib/source/test/lux/type/implicit.lux b/stdlib/source/test/lux/type/implicit.lux index 34b8b68c9..14b7c9524 100644 --- a/stdlib/source/test/lux/type/implicit.lux +++ b/stdlib/source/test/lux/type/implicit.lux @@ -10,7 +10,7 @@ [data ["." bit ("#@." equivalence)] [number - ["." nat]] + ["n" nat]] [collection ["." list]]]] {1 @@ -24,8 +24,8 @@ y r.nat] ($_ _.and (_.test "Can automatically select first-order structures." - (let [(^open "list@.") (list.equivalence nat.equivalence)] - (and (bit@= (:: nat.equivalence = x y) + (let [(^open "list@.") (list.equivalence n.equivalence)] + (and (bit@= (:: n.equivalence = x y) (/.::: = x y)) (list@= (list.n/range 1 10) (/.::: map inc (list.n/range 0 9))) diff --git a/stdlib/source/test/lux/type/resource.lux b/stdlib/source/test/lux/type/resource.lux index 637f0a564..298b95ad7 100644 --- a/stdlib/source/test/lux/type/resource.lux +++ b/stdlib/source/test/lux/type/resource.lux @@ -7,7 +7,10 @@ [monad [indexed (#+ do)]]] [control - ["." io]]] + ["." io]] + [data + [number + ["n" nat]]]] {1 ["." / (#+ Res)]}) @@ -16,7 +19,7 @@ (<| (_.context (%.name (name-of /._))) ($_ _.and (_.test "Can produce and consume keys in an ordered manner." - (<| (n/= (n/+ 123 456)) + (<| (n.= (n.+ 123 456)) io.run /.run-sync (do /.sync @@ -24,9 +27,9 @@ res|right (/.ordered-sync 456) right (/.read-sync res|right) left (/.read-sync res|left)] - (wrap (n/+ left right))))) + (wrap (n.+ left right))))) (_.test "Can exchange commutative keys." - (<| (n/= (n/+ 123 456)) + (<| (n.= (n.+ 123 456)) io.run /.run-sync (do /.sync @@ -35,9 +38,9 @@ _ (/.exchange-sync [1 0]) left (/.read-sync res|left) right (/.read-sync res|right)] - (wrap (n/+ left right))))) + (wrap (n.+ left right))))) (_.test "Can group and un-group keys." - (<| (n/= (n/+ 123 456)) + (<| (n.= (n.+ 123 456)) io.run /.run-sync (do /.sync @@ -47,5 +50,5 @@ _ (/.un-group-sync 2) right (/.read-sync res|right) left (/.read-sync res|left)] - (wrap (n/+ left right))))) + (wrap (n.+ left right))))) ))) diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux index 91f7ba0be..d13a024e7 100644 --- a/stdlib/source/test/lux/world/file.lux +++ b/stdlib/source/test/lux/world/file.lux @@ -15,6 +15,7 @@ ["." binary (#+ Binary)] ["." text] [number + ["n" nat] ["i" int]] [collection ["." list]]] @@ -68,7 +69,7 @@ Test (<| (_.context (%.name (name-of /._))) (do r.monad - [file-size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 10)))) + [file-size (|> r.nat (:: @ map (|>> (n.% 100) (n.max 10)))) dataL (_binary.binary file-size) dataR (_binary.binary file-size) new-modified (|> r.int (:: @ map (|>> i.abs @@ -86,7 +87,7 @@ _ (!.use (:: file over-write) dataL) read-size (!.use (:: file size) []) _ (!.use (:: file delete) [])] - (wrap (n/= file-size read-size))))] + (wrap (n.= file-size read-size))))] (_.assert "Can read file size." (try.default #0 result)))) (wrap (do promise.monad @@ -99,7 +100,7 @@ content (!.use (:: file content) []) read-size (!.use (:: file size) []) _ (!.use (:: file delete) [])] - (wrap (and (n/= (n/* 2 file-size) read-size) + (wrap (and (n.= (n.* 2 file-size) read-size) (:: binary.equivalence = dataL (try.assume (binary.slice 0 (dec file-size) content))) @@ -135,7 +136,7 @@ read-size (!.use (:: file size) []) _ (!.use (:: file delete) []) _ (!.use (:: dir discard) [])] - (wrap (n/= file-size read-size))))] + (wrap (n.= file-size read-size))))] (_.assert "Can create files inside of directories." (try.default #0 result)))) (wrap (do promise.monad @@ -156,10 +157,10 @@ _ (!.use (:: file delete) []) _ (!.use (:: inner-dir discard) []) _ (!.use (:: dir discard) [])] - (wrap (and (and (n/= 0 (list.size pre-files)) - (n/= 0 (list.size pre-directories))) - (and (n/= 1 (list.size post-files)) - (n/= 1 (list.size post-directories)))))))] + (wrap (and (and (n.= 0 (list.size pre-files)) + (n.= 0 (list.size pre-directories))) + (and (n.= 1 (list.size post-files)) + (n.= 1 (list.size post-directories)))))))] (_.assert "Can list files/directories inside a directory." (try.default #0 result)))) (wrap (do promise.monad |