diff options
author | Eduardo Julian | 2017-01-26 18:50:34 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-01-26 18:50:34 -0400 |
commit | c75abeb76fd77e301ded99ba4b8737f53953b43a (patch) | |
tree | edc15e6f3f0f3cb16041d9c61f95f1e4e2fbea2e | |
parent | 75111332a9d1f3038dd686ca7f7ba75300ea1022 (diff) |
- Renamed Bounded to Interval.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/interval.lux (renamed from stdlib/source/lux/control/bounded.lux) | 21 | ||||
-rw-r--r-- | stdlib/source/lux/data/number.lux | 35 | ||||
-rw-r--r-- | stdlib/source/lux/math/logic/continuous.lux | 6 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/number.lux | 16 |
4 files changed, 48 insertions, 30 deletions
diff --git a/stdlib/source/lux/control/bounded.lux b/stdlib/source/lux/control/interval.lux index a81135261..511195c93 100644 --- a/stdlib/source/lux/control/bounded.lux +++ b/stdlib/source/lux/control/interval.lux @@ -3,13 +3,30 @@ ## If a copy of the MPL was not distributed with this file, ## You can obtain one at http://mozilla.org/MPL/2.0/. -(;module: lux) +(;module: + lux + (lux (control ord))) ## Signatures -(sig: #export (Bounded a) +(sig: #export (Interval a) {#;doc "A representation of top and bottom boundaries for an ordered type."} + (: (Ord a) + ord) + (: a top) (: a bottom)) + +(def: #export (within? Interval<a> elem) + (All [a] (-> (Interval a) a Bool)) + (let [(^open) Interval<a>] + (if (>= bottom top) + ## Inside order + (and (>= bottom elem) + (<= top elem)) + ## Outside order + (and (<= bottom elem) + (>= top elem)) + ))) diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux index 695f9c7b9..e9c49b38e 100644 --- a/stdlib/source/lux/data/number.lux +++ b/stdlib/source/lux/data/number.lux @@ -11,7 +11,7 @@ hash [ord] enum - bounded + interval codec) (data error))) @@ -102,15 +102,16 @@ [Int Ord<Int> i.inc i.dec] ) -(do-template [<type> <top> <bottom>] - [(struct: #export _ (Bounded <type>) +(do-template [<type> <ord> <top> <bottom>] + [(struct: #export _ (Interval <type>) + (def: ord <ord>) (def: top <top>) (def: bottom <bottom>))] - [ Nat (_lux_proc ["nat" "max-value"] []) (_lux_proc ["nat" "min-value"] [])] - [ Int (_lux_proc ["jvm" "getstatic:java.lang.Long:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Long:MIN_VALUE"] [])] - [Real (_lux_proc ["jvm" "getstatic:java.lang.Double:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Double:MIN_VALUE"] [])] - [Deg (_lux_proc ["deg" "max-value"] []) (_lux_proc ["deg" "min-value"] [])]) + [ Nat Ord<Nat> (_lux_proc ["nat" "max-value"] []) (_lux_proc ["nat" "min-value"] [])] + [ Int Ord<Int> (_lux_proc ["jvm" "getstatic:java.lang.Long:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Long:MIN_VALUE"] [])] + [Real Ord<Real> (_lux_proc ["jvm" "getstatic:java.lang.Double:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Double:MIN_VALUE"] [])] + [Deg Ord<Deg> (_lux_proc ["deg" "max-value"] []) (_lux_proc ["deg" "min-value"] [])]) (do-template [<name> <type> <unit> <append>] [(struct: #export <name> (Monoid <type>) @@ -119,20 +120,20 @@ [ Add@Monoid<Nat> Nat +0 n.+] [ Mul@Monoid<Nat> Nat +1 n.*] - [ Max@Monoid<Nat> Nat (:: Bounded<Nat> bottom) n.max] - [ Min@Monoid<Nat> Nat (:: Bounded<Nat> top) n.min] + [ Max@Monoid<Nat> Nat (:: Interval<Nat> bottom) n.max] + [ Min@Monoid<Nat> Nat (:: Interval<Nat> top) n.min] [ Add@Monoid<Int> Int 0 i.+] [ Mul@Monoid<Int> Int 1 i.*] - [ Max@Monoid<Int> Int (:: Bounded<Int> bottom) i.max] - [ Min@Monoid<Int> Int (:: Bounded<Int> top) i.min] + [ Max@Monoid<Int> Int (:: Interval<Int> bottom) i.max] + [ Min@Monoid<Int> Int (:: Interval<Int> top) i.min] [Add@Monoid<Real> Real 0.0 r.+] [Mul@Monoid<Real> Real 1.0 r.*] - [Max@Monoid<Real> Real (:: Bounded<Real> bottom) r.max] - [Min@Monoid<Real> Real (:: Bounded<Real> top) r.min] - [Add@Monoid<Deg> Deg (:: Bounded<Deg> bottom) d.+] - [Mul@Monoid<Deg> Deg (:: Bounded<Deg> top) d.*] - [Max@Monoid<Deg> Deg (:: Bounded<Deg> bottom) d.max] - [Min@Monoid<Deg> Deg (:: Bounded<Deg> top) d.min] + [Max@Monoid<Real> Real (:: Interval<Real> bottom) r.max] + [Min@Monoid<Real> Real (:: Interval<Real> top) r.min] + [Add@Monoid<Deg> Deg (:: Interval<Deg> bottom) d.+] + [Mul@Monoid<Deg> Deg (:: Interval<Deg> top) d.*] + [Max@Monoid<Deg> Deg (:: Interval<Deg> bottom) d.max] + [Min@Monoid<Deg> Deg (:: Interval<Deg> top) d.min] ) (def: (text.replace pattern value template) diff --git a/stdlib/source/lux/math/logic/continuous.lux b/stdlib/source/lux/math/logic/continuous.lux index ccd5795d7..0e7e0de9b 100644 --- a/stdlib/source/lux/math/logic/continuous.lux +++ b/stdlib/source/lux/math/logic/continuous.lux @@ -5,7 +5,7 @@ (;module: lux - (lux (data [number "Deg/" Bounded<Deg> Number<Deg>]))) + (lux (data [number "Deg/" Interval<Deg>]))) (def: #export TRUE Deg Deg/top) (def: #export FALSE Deg Deg/bottom) @@ -19,9 +19,9 @@ [or~ d.max] ) -(def: #export not~ +(def: #export (not~ input) (-> Deg Deg) - Deg/negate) + (d.- input TRUE)) (def: #export (implies~ consequent antecedent) (-> Deg Deg Deg) diff --git a/stdlib/test/test/lux/data/number.lux b/stdlib/test/test/lux/data/number.lux index 4de7d4c14..3ac5f0bf3 100644 --- a/stdlib/test/test/lux/data/number.lux +++ b/stdlib/test/test/lux/data/number.lux @@ -68,18 +68,18 @@ ["Int" R;int Enum<Int> Number<Int>] ) -(do-template [category rand-gen <Number> <Bounded> <test>] - [(test: (format "[" category "] " "Bounded") +(do-template [category rand-gen <Number> <Interval> <test>] + [(test: (format "[" category "] " "Interval") [x (|> rand-gen (R;filter <test>)) #let [(^open) <Number>]] - (assert "" (and (<= x (:: <Bounded> bottom)) - (>= x (:: <Bounded> top)))))] + (assert "" (and (<= x (:: <Interval> bottom)) + (>= x (:: <Interval> top)))))] - ["Nat" R;nat Number<Nat> Bounded<Nat> (lambda [_] true)] - ["Int" R;int Number<Int> Bounded<Int> (lambda [_] true)] + ["Nat" R;nat Number<Nat> Interval<Nat> (lambda [_] true)] + ["Int" R;int Number<Int> Interval<Int> (lambda [_] true)] ## Both min and max values will be positive (thus, greater than zero) - ["Real" R;real Number<Real> Bounded<Real> (r.> 0.0)] - ["Deg" R;deg Number<Deg> Bounded<Deg> (lambda [_] true)] + ["Real" R;real Number<Real> Interval<Real> (r.> 0.0)] + ["Deg" R;deg Number<Deg> Interval<Deg> (lambda [_] true)] ) (do-template [category rand-gen <Number> <Monoid> <cap> <test>] |