From ee73994bf7733971561e32a28ac06141dbe0134b Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 28 Aug 2018 22:04:12 -0400 Subject: Small additions to stdlib. --- stdlib/source/lux.lux | 10 +++++++++- stdlib/source/lux/data/collection/array.lux | 10 ++++++++++ stdlib/source/lux/time/duration.lux | 15 ++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 916b77797..1fb0afe19 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -2228,7 +2228,7 @@ subjectH (high-bits subject)] (if ("lux int <" subjectH testH) #1 - (if ("lux i64 =" testH subjectH) + (if ("lux i64 =" subjectH testH) ("lux int <" (low-bits subject) (low-bits test)) @@ -6206,3 +6206,11 @@ [no yes] [off on] ) + +(def: #export nat-to-frac + (-> Nat Frac) + (|>> ..int ..int-to-frac)) + +(def: #export frac-to-nat + (-> Frac Nat) + (|>> ..frac-to-int ..nat)) diff --git a/stdlib/source/lux/data/collection/array.lux b/stdlib/source/lux/data/collection/array.lux index 6036d96ae..2e92ec64b 100644 --- a/stdlib/source/lux/data/collection/array.lux +++ b/stdlib/source/lux/data/collection/array.lux @@ -40,6 +40,16 @@ (#.Some value)))})) #.None)) +(def: #export (contains? index array) + (All [a] + (-> Nat (Array a) Bit)) + (case (..read index array) + (#.Some _) + #1 + + _ + #0)) + (def: #export (write i x xs) (All [a] (-> Nat a (Array a) (Array a))) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 91f262fe4..20ef20c8c 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -2,7 +2,7 @@ [lux #* [control equivalence - order + [order (#+ Order)] codec [monoid (#+ Monoid)] ["p" parser] @@ -71,6 +71,19 @@ [>= i/>=] )) + (open: "duration/." Order) + + (do-template [ ] + [(def: #export ( left right) + (-> Duration Duration Duration) + (if ( left right) + right + left))] + + [max duration/>] + [min duration/<] + ) + (do-template [ ] [(def: #export (-> Duration Bit) -- cgit v1.2.3