diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux.lux | 194 |
1 files changed, 95 insertions, 99 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 2c550ebd9..412169967 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1086,10 +1086,10 @@ #Nil} [xs ys])) -(def:'' (text@= x y) +(def:'' (text@= reference sample) #Nil (#Function Text (#Function Text Bit)) - ("lux text =" x y)) + ("lux text =" reference sample)) (def:'' (get-rep key env) #Nil @@ -1140,14 +1140,14 @@ (#.Cons export-meta #.Nil)) (#Function Nat (#Function Nat Nat)) - ("lux i64 +" param subject)) + ("lux i64 +" subject param)) (def:'' (n/- param subject) (#.Cons (doc-meta "Nat(ural) substraction.") (#.Cons export-meta #.Nil)) (#Function Nat (#Function Nat Nat)) - ("lux i64 -" subject param)) + ("lux i64 -" param subject)) (def:'' (n/* param subject) (#.Cons (doc-meta "Nat(ural) multiplication.") @@ -1156,8 +1156,8 @@ (#Function Nat (#Function Nat Nat)) ("lux coerce" Nat ("lux int *" - ("lux coerce" Int subject) - ("lux coerce" Int param)))) + ("lux coerce" Int param) + ("lux coerce" Int subject)))) (def:'' (update-parameters code) #Nil @@ -2206,11 +2206,11 @@ (-> (-> a Bit) ($' List a) Bit)) (list@fold (function' [_2 _1] (if _1 (p _2) #0)) #1 xs)) -(def:''' #export (n/= test subject) +(def:''' #export (n/= reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Nat(ural) equivalence.")]) (-> Nat Nat Bit) - ("lux i64 =" test subject)) + ("lux i64 =" reference sample)) (def:''' (high-bits value) (list) @@ -2220,48 +2220,48 @@ (def:''' low-mask (list) I64 - ("lux i64 -" ("lux i64 left-shift" 32 1) 1)) + (|> 1 ("lux i64 left-shift" 32) ("lux i64 -" 1))) (def:''' (low-bits value) (list) (-> ($' I64 Any) I64) ("lux i64 and" low-mask value)) -(def:''' #export (n/< test subject) +(def:''' #export (n/< reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Nat(ural) less-than.")]) (-> Nat Nat Bit) - (let' [testH (high-bits test) - subjectH (high-bits subject)] - (if ("lux int <" subjectH testH) + (let' [referenceH (high-bits reference) + sampleH (high-bits sample)] + (if ("lux int <" referenceH sampleH) #1 - (if ("lux i64 =" subjectH testH) + (if ("lux i64 =" referenceH sampleH) ("lux int <" - (low-bits subject) - (low-bits test)) + (low-bits reference) + (low-bits sample)) #0)))) -(def:''' #export (n/<= test subject) +(def:''' #export (n/<= reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Nat(ural) less-than-equal.")]) (-> Nat Nat Bit) - (if (n/< test subject) + (if (n/< reference sample) #1 - ("lux i64 =" test subject))) + ("lux i64 =" reference sample))) -(def:''' #export (n/> test subject) +(def:''' #export (n/> reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Nat(ural) greater-than.")]) (-> Nat Nat Bit) - (n/< subject test)) + (n/< sample reference)) -(def:''' #export (n/>= test subject) +(def:''' #export (n/>= reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Nat(ural) greater-than-equal.")]) (-> Nat Nat Bit) - (if (n/< subject test) + (if (n/< sample reference) #1 - ("lux i64 =" test subject))) + ("lux i64 =" reference sample))) (macro:' #export (template tokens) (list [(tag$ ["lux" "doc"]) @@ -2292,78 +2292,78 @@ (fail "Wrong syntax for template")} tokens)) -(def:''' #export (r/= test subject) +(def:''' #export (r/= reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) equivalence.")]) (-> Rev Rev Bit) - ("lux i64 =" test subject)) + ("lux i64 =" reference sample)) -(def:''' #export (r/< test subject) +(def:''' #export (r/< reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) less-than.")]) (-> Rev Rev Bit) - (n/< ("lux coerce" Nat test) - ("lux coerce" Nat subject))) + (n/< ("lux coerce" Nat reference) + ("lux coerce" Nat sample))) -(def:''' #export (r/<= test subject) +(def:''' #export (r/<= reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) less-than-equal.")]) (-> Rev Rev Bit) - (if (n/< ("lux coerce" Nat test) - ("lux coerce" Nat subject)) + (if (n/< ("lux coerce" Nat reference) + ("lux coerce" Nat sample)) #1 - ("lux i64 =" test subject))) + ("lux i64 =" reference sample))) -(def:''' #export (r/> test subject) +(def:''' #export (r/> reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) greater-than.")]) (-> Rev Rev Bit) - (r/< subject test)) + (r/< sample reference)) -(def:''' #export (r/>= test subject) +(def:''' #export (r/>= reference sample) (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) greater-than-equal.")]) (-> Rev Rev Bit) - (if (r/< subject test) + (if (r/< sample reference) #1 - ("lux i64 =" test subject))) + ("lux i64 =" reference sample))) (template [<type> - <eq-proc> <lt-proc> <eq-name> <lt-name> <lte-name> <gt-name> <gte-name> - <eq-doc> <<-doc> <<=-doc> <>-doc> <>=-doc>] - [(def:''' #export (<eq-name> test subject) + <eq-proc> <lt-proc> <eq-name> <lt-name> <lte-name> <gt-name> <gte-name> + <eq-doc> <<-doc> <<=-doc> <>-doc> <>=-doc>] + [(def:''' #export (<eq-name> reference sample) (list [(tag$ ["lux" "doc"]) (text$ <eq-doc>)]) (-> <type> <type> Bit) - (<eq-proc> subject test)) + (<eq-proc> reference sample)) - (def:''' #export (<lt-name> test subject) + (def:''' #export (<lt-name> reference sample) (list [(tag$ ["lux" "doc"]) (text$ <<-doc>)]) (-> <type> <type> Bit) - (<lt-proc> subject test)) + (<lt-proc> reference sample)) - (def:''' #export (<lte-name> test subject) + (def:''' #export (<lte-name> reference sample) (list [(tag$ ["lux" "doc"]) (text$ <<=-doc>)]) (-> <type> <type> Bit) - (if (<lt-proc> subject test) + (if (<lt-proc> reference sample) #1 - (<eq-proc> subject test))) + (<eq-proc> reference sample))) - (def:''' #export (<gt-name> test subject) + (def:''' #export (<gt-name> reference sample) (list [(tag$ ["lux" "doc"]) (text$ <>-doc>)]) (-> <type> <type> Bit) - (<lt-proc> test subject)) + (<lt-proc> sample reference)) - (def:''' #export (<gte-name> test subject) + (def:''' #export (<gte-name> reference sample) (list [(tag$ ["lux" "doc"]) (text$ <>=-doc>)]) (-> <type> <type> Bit) - (if (<lt-proc> test subject) + (if (<lt-proc> sample reference) #1 - (<eq-proc> subject test)))] + (<eq-proc> reference sample)))] [ Int "lux i64 =" "lux int <" i/= i/< i/<= i/> i/>= "Int(eger) equivalence." "Int(eger) less-than." "Int(eger) less-than-equal." "Int(eger) greater-than." "Int(eger) greater-than-equal."] @@ -2376,19 +2376,18 @@ (list [(tag$ ["lux" "doc"]) (text$ "Nat(ural) division.")]) (-> Nat Nat Nat) - (if ("lux int <" ("lux coerce" Int param) +0) + (if ("lux int <" +0 ("lux coerce" Int param)) (if (n/< param subject) 0 1) - (let' [quotient ("lux i64 left-shift" - 1 - ("lux int /" - ("lux i64 logical-right-shift" 1 subject) - ("lux coerce" Int param))) + (let' [quotient (|> subject + ("lux i64 logical-right-shift" 1) + ("lux int /" ("lux coerce" Int param)) + ("lux i64 left-shift" 1)) flat ("lux int *" - ("lux coerce" Int quotient) - ("lux coerce" Int param)) - remainder ("lux i64 -" subject flat)] + ("lux coerce" Int param) + ("lux coerce" Int quotient)) + remainder ("lux i64 -" flat subject)] (if (n/< param remainder) quotient ("lux i64 +" 1 quotient))))) @@ -2399,25 +2398,25 @@ (-> Nat Nat (#Product Nat Nat)) (let' [div (n// param subject) flat ("lux int *" - ("lux coerce" Int div) - ("lux coerce" Int param))] - [div ("lux i64 -" subject flat)])) + ("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.")]) (-> Nat Nat Nat) (let' [flat ("lux int *" - ("lux coerce" Int (n// param subject)) - ("lux coerce" Int param))] - ("lux i64 -" subject flat))) + ("lux coerce" Int param) + ("lux coerce" Int (n// param subject)))] + ("lux i64 -" flat subject))) (template [<type> <name> <op> <doc>] [(def:''' #export (<name> param subject) (list [(tag$ ["lux" "doc"]) (text$ <doc>)]) (-> <type> <type> <type>) - (<op> subject param))] + (<op> param subject))] [ Int i/+ "lux i64 +" "Int(eger) addition."] [ Int i/- "lux i64 -" "Int(eger) substraction."] @@ -2431,7 +2430,7 @@ (list [(tag$ ["lux" "doc"]) (text$ <doc>)]) (-> <type> <type> <type>) - (<op> subject param))] + (<op> param subject))] [ Int i/* "lux int *" "Int(eger) multiplication."] [ Int i// "lux int /" "Int(eger) division."] @@ -2456,8 +2455,8 @@ ("lux int *" paramL) ("lux i64 logical-right-shift" 32)) middle ("lux i64 +" - ("lux int *" subjectH paramL) - ("lux int *" subjectL paramH)) + ("lux int *" paramL subjectH) + ("lux int *" paramH subjectL)) top ("lux int *" subjectH paramH)] (|> bottom ("lux i64 +" middle) @@ -2488,31 +2487,28 @@ (if ("lux i64 =" +0 trailing-zeroes) [1 ("lux i64 logical-right-shift" 1 remaining)] [trailing-zeroes remaining])) - shift ("lux i64 -" 64 trailing-zeroes) + shift ("lux i64 -" trailing-zeroes 64) numerator ("lux i64 left-shift" shift 1)] - ("lux coerce" Rev - ("lux int *" - ("lux coerce" Int subject) - ("lux int /" - ("lux coerce" Int numerator) - ("lux coerce" Int denominator))))))) + (|> ("lux coerce" Int numerator) + ("lux int /" ("lux coerce" Int denominator)) + ("lux int *" ("lux coerce" Int subject)) + ("lux coerce" Rev))))) (def:''' #export (r/% param subject) (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) remainder.")]) (-> Rev Rev Rev) - ("lux coerce" Rev - (n/% ("lux coerce" Nat param) - ("lux coerce" Nat subject)))) + (|> ("lux coerce" Nat subject) + (n/% ("lux coerce" Nat param)) + ("lux coerce" Rev))) (def:''' #export (r/scale param subject) (list [(tag$ ["lux" "doc"]) (text$ "Rev(olution) scale.")]) (-> Nat Rev Rev) - ("lux coerce" Rev - ("lux int *" - ("lux coerce" Int subject) - ("lux coerce" Int param)))) + (|> ("lux coerce" Int subject) + ("lux int *" ("lux coerce" Int param)) + ("lux coerce" Rev))) (def:''' #export (r/reciprocal numerator) (list [(tag$ ["lux" "doc"]) @@ -3587,11 +3583,11 @@ (def: (index-of part text) (-> Text Text (Maybe Nat)) - ("lux text index" text part 0)) + ("lux text index" 0 part text)) (def: (last-index-of' part part-size since text) (-> Text Nat Nat Text (Maybe Nat)) - (case ("lux text index" text part (n/+ part-size since)) + (case ("lux text index" (n/+ part-size since) part text) #None (#Some since) @@ -3600,7 +3596,7 @@ (def: (last-index-of part text) (-> Text Text (Maybe Nat)) - (case ("lux text index" text part 0) + (case ("lux text index" 0 part text) (#Some since) (last-index-of' part ("lux text size" part) since text) @@ -3611,14 +3607,14 @@ (-> Nat Text (Maybe Text)) (let [size ("lux text size" text)] (if (n/<= size from) - (#.Some ("lux text clip" text from size)) + (#.Some ("lux text clip" from size text)) #.None))) (def: (clip/2 from to text) (-> Nat Nat Text (Maybe Text)) (if (and (n/<= to from) (n/<= ("lux text size" text) to)) - (#.Some ("lux text clip" text from to)) + (#.Some ("lux text clip" from to text)) #.None)) (def: #export (error! message) @@ -3657,9 +3653,9 @@ (list input) (#Some idx) - (list& ("lux text clip" input 0 idx) + (list& ("lux text clip" 0 idx input) (text@split-all-with splitter - ("lux text clip" input (n/+ 1 idx) ("lux text size" input)))))) + ("lux text clip" (n/+ 1 idx) ("lux text size" input) input))))) (def: (nth idx xs) (All [a] @@ -4142,8 +4138,8 @@ (def: (split! at x) (-> Nat Text [Text Text]) - [("lux text clip" x 0 at) - ("lux text clip" x at ("lux text size" x))]) + [("lux text clip" 0 at x) + ("lux text clip" at ("lux text size" x) x)]) (def: (split-with token sample) (-> Text Text (Maybe [Text Text])) @@ -4175,7 +4171,7 @@ (def: (count-relatives relatives input) (-> Nat Text Nat) - (case ("lux text index" input ..module-separator relatives) + (case ("lux text index" relatives ..module-separator input) #None relatives @@ -4220,7 +4216,7 @@ list@reverse (interpose ..module-separator) (text@join-with "")) - clean ("lux text clip" module relatives ("lux text size" module)) + clean ("lux text clip" relatives ("lux text size" module) module) output (case ("lux text size" clean) 0 prefix _ ($_ text@compose prefix ..module-separator clean))] @@ -5170,7 +5166,7 @@ (template [<name> <from> <to> <proc>] [(def: #export (<name> n) (-> <from> <to>) - (<proc> [n]))] + (<proc> n))] [frac-to-int Frac Int "lux frac int"] [int-to-frac Int Frac "lux int frac"] @@ -5221,10 +5217,10 @@ ($_ text@compose ..double-quote original ..double-quote)) (template [<name> <extension> <doc>] - [(def: #export (<name> value) + [(def: #export <name> {#.doc <doc>} (All [s] (-> (I64 s) (I64 s))) - (<extension> value 1))] + (|>> (<extension> 1)))] [inc "lux i64 +" "Increment function."] [dec "lux i64 -" "Decrement function."] |