From c75abeb76fd77e301ded99ba4b8737f53953b43a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 26 Jan 2017 18:50:34 -0400 Subject: - Renamed Bounded to Interval. --- stdlib/source/lux/control/bounded.lux | 15 ------------- stdlib/source/lux/control/interval.lux | 32 ++++++++++++++++++++++++++ stdlib/source/lux/data/number.lux | 35 +++++++++++++++-------------- stdlib/source/lux/math/logic/continuous.lux | 6 ++--- stdlib/test/test/lux/data/number.lux | 16 ++++++------- 5 files changed, 61 insertions(+), 43 deletions(-) delete mode 100644 stdlib/source/lux/control/bounded.lux create mode 100644 stdlib/source/lux/control/interval.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/control/bounded.lux b/stdlib/source/lux/control/bounded.lux deleted file mode 100644 index a81135261..000000000 --- a/stdlib/source/lux/control/bounded.lux +++ /dev/null @@ -1,15 +0,0 @@ -## Copyright (c) Eduardo Julian. All rights reserved. -## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -## 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) - -## Signatures -(sig: #export (Bounded a) - {#;doc "A representation of top and bottom boundaries for an ordered type."} - (: a - top) - - (: a - bottom)) diff --git a/stdlib/source/lux/control/interval.lux b/stdlib/source/lux/control/interval.lux new file mode 100644 index 000000000..511195c93 --- /dev/null +++ b/stdlib/source/lux/control/interval.lux @@ -0,0 +1,32 @@ +## Copyright (c) Eduardo Julian. All rights reserved. +## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +## 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 + (lux (control ord))) + +## Signatures +(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 elem) + (All [a] (-> (Interval a) a Bool)) + (let [(^open) Interval] + (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 i.inc i.dec] ) -(do-template [ ] - [(struct: #export _ (Bounded ) +(do-template [ ] + [(struct: #export _ (Interval ) + (def: ord ) (def: top ) (def: 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 (_lux_proc ["nat" "max-value"] []) (_lux_proc ["nat" "min-value"] [])] + [ Int Ord (_lux_proc ["jvm" "getstatic:java.lang.Long:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Long:MIN_VALUE"] [])] + [Real Ord (_lux_proc ["jvm" "getstatic:java.lang.Double:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Double:MIN_VALUE"] [])] + [Deg Ord (_lux_proc ["deg" "max-value"] []) (_lux_proc ["deg" "min-value"] [])]) (do-template [ ] [(struct: #export (Monoid ) @@ -119,20 +120,20 @@ [ Add@Monoid Nat +0 n.+] [ Mul@Monoid Nat +1 n.*] - [ Max@Monoid Nat (:: Bounded bottom) n.max] - [ Min@Monoid Nat (:: Bounded top) n.min] + [ Max@Monoid Nat (:: Interval bottom) n.max] + [ Min@Monoid Nat (:: Interval top) n.min] [ Add@Monoid Int 0 i.+] [ Mul@Monoid Int 1 i.*] - [ Max@Monoid Int (:: Bounded bottom) i.max] - [ Min@Monoid Int (:: Bounded top) i.min] + [ Max@Monoid Int (:: Interval bottom) i.max] + [ Min@Monoid Int (:: Interval top) i.min] [Add@Monoid Real 0.0 r.+] [Mul@Monoid Real 1.0 r.*] - [Max@Monoid Real (:: Bounded bottom) r.max] - [Min@Monoid Real (:: Bounded top) r.min] - [Add@Monoid Deg (:: Bounded bottom) d.+] - [Mul@Monoid Deg (:: Bounded top) d.*] - [Max@Monoid Deg (:: Bounded bottom) d.max] - [Min@Monoid Deg (:: Bounded top) d.min] + [Max@Monoid Real (:: Interval bottom) r.max] + [Min@Monoid Real (:: Interval top) r.min] + [Add@Monoid Deg (:: Interval bottom) d.+] + [Mul@Monoid Deg (:: Interval top) d.*] + [Max@Monoid Deg (:: Interval bottom) d.max] + [Min@Monoid Deg (:: Interval 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 Number]))) + (lux (data [number "Deg/" Interval]))) (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 Number] ) -(do-template [category rand-gen ] - [(test: (format "[" category "] " "Bounded") +(do-template [category rand-gen ] + [(test: (format "[" category "] " "Interval") [x (|> rand-gen (R;filter )) #let [(^open) ]] - (assert "" (and (<= x (:: bottom)) - (>= x (:: top)))))] + (assert "" (and (<= x (:: bottom)) + (>= x (:: top)))))] - ["Nat" R;nat Number Bounded (lambda [_] true)] - ["Int" R;int Number Bounded (lambda [_] true)] + ["Nat" R;nat Number Interval (lambda [_] true)] + ["Int" R;int Number Interval (lambda [_] true)] ## Both min and max values will be positive (thus, greater than zero) - ["Real" R;real Number Bounded (r.> 0.0)] - ["Deg" R;deg Number Bounded (lambda [_] true)] + ["Real" R;real Number Interval (r.> 0.0)] + ["Deg" R;deg Number Interval (lambda [_] true)] ) (do-template [category rand-gen ] -- cgit v1.2.3