diff options
Diffstat (limited to 'stdlib/source/lux')
-rw-r--r-- | stdlib/source/lux/control/interval.lux | 1 | ||||
-rw-r--r-- | stdlib/source/lux/data/bit.lux | 4 | ||||
-rw-r--r-- | stdlib/source/lux/data/number/frac.lux | 2 | ||||
-rw-r--r-- | stdlib/source/lux/data/number/i64.lux | 29 | ||||
-rw-r--r-- | stdlib/source/lux/data/number/nat.lux | 2 | ||||
-rw-r--r-- | stdlib/source/lux/data/number/ratio.lux | 142 |
6 files changed, 93 insertions, 87 deletions
diff --git a/stdlib/source/lux/control/interval.lux b/stdlib/source/lux/control/interval.lux index a001e3a44..60e452c54 100644 --- a/stdlib/source/lux/control/interval.lux +++ b/stdlib/source/lux/control/interval.lux @@ -5,7 +5,6 @@ ["." order] [enum (#+ Enum)]]]) -## Signatures (signature: #export (Interval a) {#.doc "A representation of top and bottom boundaries for an ordered type."} (: (Enum a) diff --git a/stdlib/source/lux/data/bit.lux b/stdlib/source/lux/data/bit.lux index 613d923b3..ab8c24a8e 100644 --- a/stdlib/source/lux/data/bit.lux +++ b/stdlib/source/lux/data/bit.lux @@ -25,8 +25,8 @@ (def: identity <identity>) (def: (compose x y) (<op> x y)))] - [ or-monoid #0 or] - [and-monoid #1 and] + [disjunction #0 or] + [conjunction #1 and] ) (structure: #export codec (Codec Text Bit) diff --git a/stdlib/source/lux/data/number/frac.lux b/stdlib/source/lux/data/number/frac.lux index 284576264..6847d4a59 100644 --- a/stdlib/source/lux/data/number/frac.lux +++ b/stdlib/source/lux/data/number/frac.lux @@ -126,7 +126,7 @@ (let [whole-part ("lux text clip" repr 0 split-index) decimal-part ("lux text clip" repr (inc split-index) ("lux text size" repr))] (case [(:: <int> decode whole-part) - (:: <int> decode decimal-part)] + (:: <int> decode ("lux text concat" "+" decimal-part))] (^multi [(#error.Success whole) (#error.Success decimal)] (i/>= +0 decimal)) (let [sign (if (i/< +0 whole) diff --git a/stdlib/source/lux/data/number/i64.lux b/stdlib/source/lux/data/number/i64.lux index 93d95f02c..6f30bcb44 100644 --- a/stdlib/source/lux/data/number/i64.lux +++ b/stdlib/source/lux/data/number/i64.lux @@ -1,4 +1,7 @@ -(.module: [lux (#- and or not)]) +(.module: + [lux (#- and or not) + [control + [monoid (#+ Monoid)]]]) (def: #export bits-per-byte 8) @@ -20,6 +23,25 @@ [xor "lux i64 xor" "Bitwise xor."] ) +(def: #export not + {#.doc "Bitwise negation."} + (All [s] (-> (I64 s) (I64 s))) + (xor (:coerce I64 -1))) + +(structure: #export disjunction + (All [a] (Monoid (I64 a))) + + (def: identity (.i64 0)) + (def: compose ..or) + ) + +(structure: #export conjunction + (All [a] (Monoid (I64 a))) + + (def: identity (.i64 (..not 0))) + (def: compose ..and) + ) + (do-template [<name> <op> <doc>] [(def: #export (<name> param subject) {#.doc <doc>} @@ -52,11 +74,6 @@ (add-shift 32) (..and 127)))) -(def: #export not - {#.doc "Bitwise negation."} - (All [s] (-> (I64 s) (I64 s))) - (xor (:coerce I64 -1))) - (def: (flag idx) (-> Nat I64) (|> 1 (:coerce I64) (left-shift idx))) diff --git a/stdlib/source/lux/data/number/nat.lux b/stdlib/source/lux/data/number/nat.lux index bd3c4d9b5..8126bc0c3 100644 --- a/stdlib/source/lux/data/number/nat.lux +++ b/stdlib/source/lux/data/number/nat.lux @@ -55,8 +55,8 @@ [addition n/+ 0] [multiplication n/* 1] - [maximum n/max (:: ..interval bottom)] [minimum n/min (:: ..interval top)] + [maximum n/max (:: ..interval bottom)] ) (def: #export (binary-character value) diff --git a/stdlib/source/lux/data/number/ratio.lux b/stdlib/source/lux/data/number/ratio.lux index 907cb950f..21176e998 100644 --- a/stdlib/source/lux/data/number/ratio.lux +++ b/stdlib/source/lux/data/number/ratio.lux @@ -31,72 +31,34 @@ {#numerator (n// common numerator) #denominator (n// common denominator)})) -(def: #export (* param input) - (-> Ratio Ratio Ratio) - (normalize [(n/* (get@ #numerator param) - (get@ #numerator input)) - (n/* (get@ #denominator param) - (get@ #denominator input))])) - -(def: #export (/ param input) - (-> Ratio Ratio Ratio) - (normalize [(n/* (get@ #denominator param) - (get@ #numerator input)) - (n/* (get@ #numerator param) - (get@ #denominator input))])) - -(def: #export (+ param input) - (-> Ratio Ratio Ratio) - (normalize [(n/+ (n/* (get@ #denominator input) - (get@ #numerator param)) - (n/* (get@ #denominator param) - (get@ #numerator input))) - (n/* (get@ #denominator param) - (get@ #denominator input))])) - -(def: #export (- param input) - (-> Ratio Ratio Ratio) - (normalize [(n/- (n/* (get@ #denominator input) - (get@ #numerator param)) - (n/* (get@ #denominator param) - (get@ #numerator input))) - (n/* (get@ #denominator param) - (get@ #denominator input))])) - -(def: #export (% param input) - (-> Ratio Ratio Ratio) - (let [quot (n// (n/* (get@ #denominator input) - (get@ #numerator param)) - (n/* (get@ #denominator param) - (get@ #numerator input)))] - (- (update@ #numerator (n/* quot) param) - input))) - -(def: #export (= param input) - (-> Ratio Ratio Bit) - (and (n/= (get@ #numerator param) - (get@ #numerator input)) - (n/= (get@ #denominator param) - (get@ #denominator input)))) - -(do-template [<name> <op>] - [(def: #export (<name> param input) - (-> Ratio Ratio Bit) - (and (<op> (n/* (get@ #denominator input) - (get@ #numerator param)) - (n/* (get@ #denominator param) - (get@ #numerator input)))))] - - [< n/<] - [<= n/<=] - [> n/>] - [>= n/>=] - ) +(structure: #export equivalence (Equivalence Ratio) + (def: (= param input) + (and (n/= (get@ #numerator param) + (get@ #numerator input)) + (n/= (get@ #denominator param) + (get@ #denominator input))))) + +(`` (structure: #export order (Order Ratio) + (def: &equivalence ..equivalence) + + (~~ (do-template [<name> <op>] + [(def: (<name> param input) + (and (<op> (n/* (get@ #denominator input) + (get@ #numerator param)) + (n/* (get@ #denominator param) + (get@ #numerator input)))))] + + [< n/<] + [<= n/<=] + [> n/>] + [>= n/>=] + )) + )) (do-template [<name> <comp>] [(def: #export (<name> left right) (-> Ratio Ratio Ratio) - (if (<comp> left right) + (if (:: ..order <comp> left right) right left))] @@ -104,29 +66,57 @@ [max >] ) -(structure: #export equivalence (Equivalence Ratio) - (def: = ..=)) +(def: (- param input) + (normalize [(n/- (n/* (get@ #denominator input) + (get@ #numerator param)) + (n/* (get@ #denominator param) + (get@ #numerator input))) + (n/* (get@ #denominator param) + (get@ #denominator input))])) -(structure: #export order (Order Ratio) - (def: &equivalence ..equivalence) - (def: < ..<) - (def: <= ..<=) - (def: > ..>) - (def: >= ..>=)) +(structure: #export number + (Number Ratio) + + (def: (+ param input) + (normalize [(n/+ (n/* (get@ #denominator input) + (get@ #numerator param)) + (n/* (get@ #denominator param) + (get@ #numerator input))) + (n/* (get@ #denominator param) + (get@ #denominator input))])) -(structure: #export number (Number Ratio) - (def: + ..+) (def: - ..-) - (def: * ..*) - (def: / ../) - (def: % ..%) + + (def: (* param input) + (normalize [(n/* (get@ #numerator param) + (get@ #numerator input)) + (n/* (get@ #denominator param) + (get@ #denominator input))])) + + (def: (/ param input) + (normalize [(n/* (get@ #denominator param) + (get@ #numerator input)) + (n/* (get@ #numerator param) + (get@ #denominator input))])) + + (def: (% param input) + (let [quot (n// (n/* (get@ #denominator input) + (get@ #numerator param)) + (n/* (get@ #denominator param) + (get@ #numerator input)))] + (..- (update@ #numerator (n/* quot) param) + input))) + (def: (negate (^slots [#numerator #denominator])) {#numerator denominator #denominator numerator}) + (def: abs function.identity) + (def: (signum x) {#numerator 1 - #denominator 1})) + #denominator 1}) + ) (def: separator Text ":") |