diff options
Diffstat (limited to 'stdlib/source/lux/abstract/interval.lux')
-rw-r--r-- | stdlib/source/lux/abstract/interval.lux | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/stdlib/source/lux/abstract/interval.lux b/stdlib/source/lux/abstract/interval.lux index efb131843..f5c3ce656 100644 --- a/stdlib/source/lux/abstract/interval.lux +++ b/stdlib/source/lux/abstract/interval.lux @@ -18,41 +18,43 @@ (def: #export (between enum bottom top) (All [a] (-> (Enum a) a a (Interval a))) - (structure (def: &enum enum) - (def: bottom bottom) - (def: top top))) + (structure + (def: &enum enum) + (def: bottom bottom) + (def: top top))) (def: #export (singleton enum elem) (All [a] (-> (Enum a) a (Interval a))) - (structure (def: &enum enum) - (def: bottom elem) - (def: top elem))) + (structure + (def: &enum enum) + (def: bottom elem) + (def: top elem))) (template [<name> <comp>] [(def: #export (<name> interval) (All [a] (-> (Interval a) Bit)) - (let [(^open ".") interval] - (<comp> bottom top)))] + (let [(^open ",@.") interval] + (<comp> ,@bottom ,@top)))] - [inner? >] - [outer? <] - [singleton? =] + [inner? (order.> ,@&order)] + [outer? ,@<] + [singleton? ,@=] ) (def: #export (within? interval elem) (All [a] (-> (Interval a) a Bit)) - (let [(^open ".") interval] + (let [(^open ",@.") interval] (cond (inner? interval) - (and (>= bottom elem) - (<= top elem)) + (and (order.>= ,@&order ,@bottom elem) + (order.<= ,@&order ,@top elem)) (outer? interval) - (or (>= bottom elem) - (<= top elem)) + (or (order.>= ,@&order ,@bottom elem) + (order.<= ,@&order ,@top elem)) ## singleton - (and (= bottom elem) - (= top elem))))) + (and (,@= ,@bottom elem) + (,@= ,@top elem))))) (template [<name> <limit>] [(def: #export (<name> elem interval) @@ -101,10 +103,10 @@ (def: #export (meets? reference sample) (All [a] (-> (Interval a) (Interval a) Bit)) - (let [(^open ".") reference - limit (:: reference bottom)] - (and (<= limit (:: sample bottom)) - (= limit (:: sample top))))) + (let [(^open ",@.") reference + limit (:: reference ,@bottom)] + (and (order.<= ,@&order limit (:: sample ,@bottom)) + (,@= limit (:: sample ,@top))))) (def: #export (touches? reference sample) (All [a] (-> (Interval a) (Interval a) Bit)) @@ -114,55 +116,58 @@ (template [<name> <eq-side> <ineq> <ineq-side>] [(def: #export (<name> reference sample) (All [a] (-> (Interval a) (Interval a) Bit)) - (let [(^open ".") reference] - (and (= (:: reference <eq-side>) (:: sample <eq-side>)) - (<ineq> (:: reference <ineq-side>) (:: sample <ineq-side>)))))] - - [starts? bottom <= top] - [finishes? top >= bottom] + (let [(^open ",@.") reference] + (and (,@= (:: reference <eq-side>) + (:: sample <eq-side>)) + (<ineq> ,@&order + (:: reference <ineq-side>) + (:: sample <ineq-side>)))))] + + [starts? ,@bottom order.<= ,@top] + [finishes? ,@top order.>= ,@bottom] ) (template [<name> <comp>] [(def: #export (<name> reference sample) (All [a] (-> a (Interval a) Bit)) - (let [(^open ".") sample] - (and (<comp> reference bottom) - (<comp> reference top))))] + (let [(^open ",@.") sample] + (and (<comp> reference ,@bottom) + (<comp> reference ,@top))))] - [before? <] - [after? >] + [before? ,@<] + [after? (order.> ,@&order)] ) (structure: #export equivalence (All [a] (Equivalence (Interval a))) (def: (= reference sample) - (let [(^open "_;.") reference] - (and (_;= _;bottom (:: sample bottom)) - (_;= _;top (:: sample top)))))) + (let [(^open ",@.") reference] + (and (,@= ,@bottom (:: sample bottom)) + (,@= ,@top (:: sample top)))))) (def: #export (nested? reference sample) (All [a] (-> (Interval a) (Interval a) Bit)) (cond (or (singleton? sample) (and (inner? reference) (inner? sample)) (and (outer? reference) (outer? sample))) - (let [(^open ".") reference] - (and (>= (:: reference bottom) (:: sample bottom)) - (<= (:: reference top) (:: sample top)))) + (let [(^open ",@.") reference] + (and (order.>= ,@&order (:: reference bottom) (:: sample bottom)) + (order.<= ,@&order (:: reference top) (:: sample top)))) (or (singleton? reference) (and (inner? reference) (outer? sample))) #0 ## (and (outer? reference) (inner? sample)) - (let [(^open ".") reference] - (or (and (>= (:: reference bottom) (:: sample bottom)) - (> (:: reference bottom) (:: sample top))) - (and (< (:: reference top) (:: sample bottom)) - (<= (:: reference top) (:: sample top))))) + (let [(^open ",@.") reference] + (or (and (order.>= ,@&order (:: reference bottom) (:: sample bottom)) + (order.> ,@&order (:: reference bottom) (:: sample top))) + (and (,@< (:: reference top) (:: sample bottom)) + (order.<= ,@&order (:: reference top) (:: sample top))))) )) (def: #export (overlaps? reference sample) (All [a] (-> (Interval a) (Interval a) Bit)) - (let [(^open ".") reference] + (let [(^open ",@.") reference] (and (not (:: ..equivalence = reference sample)) (cond (singleton? sample) #0 @@ -172,8 +177,8 @@ (or (and (inner? sample) (outer? reference)) (and (outer? sample) (inner? reference))) - (or (>= (:: reference bottom) (:: sample top)) - (<= (:: reference top) (:: sample bottom))) + (or (order.>= ,@&order (:: reference bottom) (:: sample top)) + (order.<= ,@&order (:: reference top) (:: sample bottom))) ## both inner (inner? sample) |