diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/project.clj | 1 | ||||
-rw-r--r-- | stdlib/source/lux/math/random.lux | 21 | ||||
-rw-r--r-- | stdlib/source/lux/time/duration.lux | 73 | ||||
-rw-r--r-- | stdlib/test/test/lux/math/random.lux | 11 | ||||
-rw-r--r-- | stdlib/test/test/lux/time/duration.lux | 28 |
5 files changed, 2 insertions, 132 deletions
diff --git a/stdlib/project.clj b/stdlib/project.clj index 4d01ffed4..53ad8718c 100644 --- a/stdlib/project.clj +++ b/stdlib/project.clj @@ -16,7 +16,6 @@ :scm {:name "git" :url "https://github.com/LuxLang/lux.git"} - :jvm-opts ["-Xss4m"] :dependencies [] :source-paths ["source"] diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index ffb7bc592..b73e7df02 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -293,24 +293,3 @@ (i64.xor (i64.left-shift 14 s01))) (i64.rotate-left 36 s01)])) ("lux i64 +" s0 s1)])) - -(def: (swap from to vec) - (All [a] (-> Nat Nat (Row a) (Row a))) - (|> vec - (row.put to (maybe.assume (row.nth from vec))) - (row.put from (maybe.assume (row.nth to vec))))) - -(def: #export (shuffle seed row) - {#.doc "Shuffle a row randomly based on a seed value."} - (All [a] (-> Nat (Row a) (Row a))) - (let [_size (row.size row) - _shuffle (monad.fold Monad<Random> - (function (_ idx vec) - (do Monad<Random> - [rand nat] - (wrap (swap idx (n/% _size rand) vec)))) - row - (list.indices _size))] - (|> _shuffle - (run (pcg-32 [123 seed])) - product.right))) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 20ef20c8c..a39e6f9ed 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -108,76 +108,3 @@ (structure: #export _ (Monoid Duration) (def: identity empty) (def: compose merge)) - -(def: (encode duration) - (-> Duration Text) - (if (:: Equivalence<Duration> = empty duration) - "+0ms" - (let [signed? (negative? duration) - [days time-left] [(query day duration) (frame day duration)] - days (if signed? - (int/abs days) - days) - time-left (if signed? - (scale-up -1 time-left) - time-left) - [hours time-left] [(query hour time-left) (frame hour time-left)] - [minutes time-left] [(query minute time-left) (frame minute time-left)] - [seconds time-left] [(query second time-left) (frame second time-left)] - millis (to-millis time-left)] - ($_ text/compose - (if signed? "-" "+") - (if (i/= +0 days) "" (text/compose (nat/encode (.nat days)) "D")) - (if (i/= +0 hours) "" (text/compose (nat/encode (.nat hours)) "h")) - (if (i/= +0 minutes) "" (text/compose (nat/encode (.nat minutes)) "m")) - (if (i/= +0 seconds) "" (text/compose (nat/encode (.nat seconds)) "s")) - (if (i/= +0 millis) "" (text/compose (nat/encode (.nat millis)) "ms")) - )))) - -(def: (lex-section suffix) - (-> Text (l.Lexer Int)) - (|> (p.codec number.Codec<Text,Int> (l.many l.decimal)) - (p.before (p.and (l.this suffix) (p.not l.alpha))) - (p.default +0))) - -(def: lex-duration - (l.Lexer Duration) - (do p.Monad<Parser> - [signed? (p.or (l.this? "-") (l.this? "+")) - #let [sign (function (_ raw) - (case signed? - (#.Left _) - (i/* -1 raw) - - (#.Right _) - raw))] - utc-day (lex-section "D") - utc-hour (lex-section "h") - utc-minute (lex-section "m") - _ (p.assert "Invalid minute." - (and (i/>= +0 utc-minute) - (i/<= +59 utc-minute))) - utc-second (lex-section "s") - _ (p.assert "Invalid second." - (and (i/>= +0 utc-second) - (i/<= +59 utc-second))) - utc-millis (lex-section "ms") - _ (p.assert "Invalid milli-seconds." - (and (i/>= +0 utc-millis) - (i/<= +999 utc-millis)))] - (wrap (|> empty - (merge (scale-up (sign utc-day) day)) - (merge (scale-up (sign utc-hour) hour)) - (merge (scale-up (sign utc-minute) minute)) - (merge (scale-up (sign utc-second) second)) - (merge (scale-up (sign utc-millis) milli)))))) - -(def: (decode input) - (-> Text (e.Error Duration)) - (l.run input lex-duration)) - -(structure: #export _ - {#.doc "For example: +15D21h14m51s827ms"} - (Codec Text Duration) - (def: encode encode) - (def: decode decode)) diff --git a/stdlib/test/test/lux/math/random.lux b/stdlib/test/test/lux/math/random.lux index f3f118c90..a7f126ef3 100644 --- a/stdlib/test/test/lux/math/random.lux +++ b/stdlib/test/test/lux/math/random.lux @@ -28,11 +28,7 @@ _set (r.set number.Hash<Nat> size r.nat) _dict (r.dictionary number.Hash<Nat> size r.nat r.nat) top r.nat - filtered (|> r.nat (r.filter (n/<= top))) - shuffle-seed r.nat - #let [sorted (|> _row row.to-list (list.sort n/<)) - shuffled (|> sorted row.from-list (r.shuffle shuffle-seed)) - re-sorted (|> shuffled row.to-list (list.sort n/<))]] + filtered (|> r.nat (r.filter (n/<= top)))] ($_ seq (test "Can produce lists." (n/= size (list.size _list))) @@ -50,9 +46,4 @@ (n/= size (dict.size _dict))) (test "Can filter values." (n/<= top filtered)) - (test "Can shuffle rows." - (let [(^open "v/.") (row.Equivalence<Row> number.Equivalence<Nat>) - sorted (row.from-list sorted)] - (and (not (v/= sorted shuffled)) - (v/= sorted (row.from-list re-sorted))))) )))) diff --git a/stdlib/test/test/lux/time/duration.lux b/stdlib/test/test/lux/time/duration.lux index 669af6b4c..8bf00b88b 100644 --- a/stdlib/test/test/lux/time/duration.lux +++ b/stdlib/test/test/lux/time/duration.lux @@ -57,30 +57,4 @@ (test "Merging with the empty duration changes nothing." (|> sample (@.merge @.empty) (@/= sample))) (test "Merging a duration with it's opposite yields an empty duration." - (|> sample (@.merge (@.scale-up -1 sample)) (@/= @.empty))) - (test "Can frame a duration in terms of another." - (cond (and (@.positive? frame) (@.positive? sample)) - (|> sample (@.frame frame) (@/< frame)) - - (and (@.negative? frame) (@.negative? sample)) - (|> sample (@.frame frame) (@/> frame)) - - (or (or (@.neutral? frame) (@.neutral? sample)) - (|> sample - (@.frame frame) - (@.scale-up -1) - (@/< (if (@.negative? frame) - (@.scale-up -1 frame) - frame)))))))))) - -(context: "Codec" - (<| (times 100) - (do @ - [sample duration - #let [(^open "@/.") @.Equivalence<Duration> - (^open "@/.") @.Codec<Text,Duration>]] - (test "Can encode/decode durations." - (E.default #0 - (do E.Monad<Error> - [decoded (|> sample @/encode @/decode)] - (wrap (@/= sample decoded)))))))) + (|> sample (@.merge (@.scale-up -1 sample)) (@/= @.empty))))))) |