From f505b42847bd7ba54b14d4b593b883c1bb25501d Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 3 Jul 2018 22:20:22 -0400 Subject: - Re-named "sequence" to "row". --- lux-mode/lux-mode.el | 2 +- stdlib/source/lux/data/coll/row.lux | 437 +++++++++++++++++++++++ stdlib/source/lux/data/coll/sequence.lux | 438 ------------------------ stdlib/source/lux/data/format/json.lux | 22 +- stdlib/source/lux/lang/compiler/translation.lux | 8 +- stdlib/source/lux/lang/syntax.lux | 18 +- stdlib/source/lux/macro/poly/equality.lux | 4 +- stdlib/source/lux/macro/poly/json.lux | 8 +- stdlib/source/lux/math/random.lux | 20 +- stdlib/source/lux/time/date.lux | 18 +- stdlib/source/lux/time/instant.lux | 50 +-- stdlib/source/lux/type/resource.lux | 8 +- stdlib/test/test/lux/data/coll/row.lux | 73 ++++ stdlib/test/test/lux/data/coll/sequence.lux | 73 ---- stdlib/test/test/lux/data/format/json.lux | 4 +- stdlib/test/test/lux/math/random.lux | 22 +- 16 files changed, 602 insertions(+), 603 deletions(-) create mode 100644 stdlib/source/lux/data/coll/row.lux delete mode 100644 stdlib/source/lux/data/coll/sequence.lux create mode 100644 stdlib/test/test/lux/data/coll/row.lux delete mode 100644 stdlib/test/test/lux/data/coll/sequence.lux diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index fe56e7e45..dc780b364 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -230,7 +230,7 @@ Called by `imenu--generic-function'." "and" "or" "char" "exec" "let" "if" "cond" "do" "be" "open:" "loop" "recur" "comment" "for" - "list" "list&" "io" "sequence" "tree" + "list" "list&" "io" "row" "tree" "get@" "set@" "update@" "|>" "|>>" "<|" "<<|" "_$" "$_" "~" "~+" "~!" "~'" "::" ":::" "|" "&" "->" "All" "Ex" "Rec" "primitive" "$" "type" "^" "^or" "^slots" "^multi" "^@" "^template" "^open" "^|>" "^code" "^stream&" "^regex" diff --git a/stdlib/source/lux/data/coll/row.lux b/stdlib/source/lux/data/coll/row.lux new file mode 100644 index 000000000..0b258a2ec --- /dev/null +++ b/stdlib/source/lux/data/coll/row.lux @@ -0,0 +1,437 @@ +(.module: + lux + (lux (control [functor #+ Functor] + [apply #+ Apply] + [monad #+ do Monad] + [equality #+ Eq] + monoid + fold + ["p" parser]) + (data [maybe] + (coll [list "list/" Fold Functor Monoid] + [array "array/" Functor Fold]) + [bit] + [product]) + [macro #+ with-gensyms] + (macro [code] + ["s" syntax #+ syntax: Syntax]) + )) + +## [Utils] +(type: (Node a) + (#Base (Array a)) + (#Hierarchy (Array (Node a)))) + +(type: (Base a) (Array a)) +(type: (Hierarchy a) (Array (Node a))) + +(type: Level Nat) + +(type: Index Nat) + +(def: branching-exponent + Nat + +5) + +(def: root-level + Level + +0) + +(do-template [ ] + [(def: + (-> Level Level) + ( branching-exponent))] + + [level-up n/+] + [level-down n/-] + ) + +(def: full-node-size + Nat + (bit.left-shift branching-exponent +1)) + +(def: branch-idx-mask + Nat + (dec full-node-size)) + +(def: branch-idx + (-> Index Index) + (bit.and branch-idx-mask)) + +(def: (new-hierarchy _) + (All [a] (-> Any (Hierarchy a))) + (array.new full-node-size)) + +(def: (tail-off vec-size) + (-> Nat Nat) + (if (n/< full-node-size vec-size) + +0 + (|> (dec vec-size) + (bit.logical-right-shift branching-exponent) + (bit.left-shift branching-exponent)))) + +(def: (new-path level tail) + (All [a] (-> Level (Base a) (Node a))) + (if (n/= +0 level) + (#Base tail) + (|> (new-hierarchy []) + (array.write +0 (new-path (level-down level) tail)) + #Hierarchy))) + +(def: (new-tail singleton) + (All [a] (-> a (Base a))) + (|> (array.new +1) + (array.write +0 singleton))) + +(def: (push-tail size level tail parent) + (All [a] (-> Nat Level (Base a) (Hierarchy a) (Hierarchy a))) + (let [sub-idx (branch-idx (bit.logical-right-shift level (dec size))) + ## If we're currently on a bottom node + sub-node (if (n/= branching-exponent level) + ## Just add the tail to it + (#Base tail) + ## Otherwise, check whether there's a vacant spot + (case (array.read sub-idx parent) + ## If so, set the path to the tail + #.None + (new-path (level-down level) tail) + ## If not, push the tail onto the sub-node. + (#.Some (#Hierarchy sub-node)) + (#Hierarchy (push-tail size (level-down level) tail sub-node)) + + _ + (undefined)) + )] + (|> (array.clone parent) + (array.write sub-idx sub-node)))) + +(def: (expand-tail val tail) + (All [a] (-> a (Base a) (Base a))) + (let [tail-size (array.size tail)] + (|> (array.new (inc tail-size)) + (array.copy tail-size +0 tail +0) + (array.write tail-size val)))) + +(def: (put' level idx val hierarchy) + (All [a] (-> Level Index a (Hierarchy a) (Hierarchy a))) + (let [sub-idx (branch-idx (bit.logical-right-shift level idx))] + (case (array.read sub-idx hierarchy) + (#.Some (#Hierarchy sub-node)) + (|> (array.clone hierarchy) + (array.write sub-idx (#Hierarchy (put' (level-down level) idx val sub-node)))) + + (^multi (#.Some (#Base base)) + (n/= +0 (level-down level))) + (|> (array.clone hierarchy) + (array.write sub-idx (|> (array.clone base) + (array.write (branch-idx idx) val) + #Base))) + + _ + (undefined)))) + +(def: (pop-tail size level hierarchy) + (All [a] (-> Nat Level (Hierarchy a) (Maybe (Hierarchy a)))) + (let [sub-idx (branch-idx (bit.logical-right-shift level (n/- +2 size)))] + (cond (n/= +0 sub-idx) + #.None + + (n/> branching-exponent level) + (do maybe.Monad + [base|hierarchy (array.read sub-idx hierarchy) + sub (case base|hierarchy + (#Hierarchy sub) + (pop-tail size (level-down level) sub) + + (#Base _) + (undefined))] + (|> (array.clone hierarchy) + (array.write sub-idx (#Hierarchy sub)) + #.Some)) + + ## Else... + (|> (array.clone hierarchy) + (array.delete sub-idx) + #.Some) + ))) + +(def: (to-list' node) + (All [a] (-> (Node a) (List a))) + (case node + (#Base base) + (array.to-list base) + + (#Hierarchy hierarchy) + (|> hierarchy + array.to-list + list.reverse + (list/fold (function (_ sub acc) (list/compose (to-list' sub) acc)) + #.Nil)))) + +## [Types] +(type: #export (Row a) + {#level Level + #size Nat + #root (Hierarchy a) + #tail (Base a)}) + +## [Exports] +(def: #export empty + Row + {#level (level-up root-level) + #size +0 + #root (array.new full-node-size) + #tail (array.new +0)}) + +(def: #export (size row) + (All [a] (-> (Row a) Nat)) + (get@ #size row)) + +(def: #export (add val vec) + (All [a] (-> a (Row a) (Row a))) + ## Check if there is room in the tail. + (let [vec-size (get@ #size vec)] + (if (|> vec-size (n/- (tail-off vec-size)) (n/< full-node-size)) + ## If so, append to it. + (|> vec + (update@ #size inc) + (update@ #tail (expand-tail val))) + ## Otherwise, push tail into the tree + ## -------------------------------------------------------- + ## Will the root experience an overflow with this addition? + (|> (if (n/> (bit.left-shift (get@ #level vec) +1) + (bit.logical-right-shift branching-exponent vec-size)) + ## If so, a brand-new root must be established, that is + ## 1-level taller. + (|> vec + (set@ #root (|> (: (Hierarchy ($ +0)) + (new-hierarchy [])) + ## TODO: Remove version above once new-luxc becomes the standard compiler. + ## (new-hierarchy []) + (array.write +0 (#Hierarchy (get@ #root vec))) + (array.write +1 (new-path (get@ #level vec) (get@ #tail vec))))) + (update@ #level level-up)) + ## Otherwise, just push the current tail onto the root. + (|> vec + (update@ #root (push-tail vec-size (get@ #level vec) (get@ #tail vec))))) + ## Finally, update the size of the row and grow a new + ## tail with the new element as it's sole member. + (update@ #size inc) + (set@ #tail (new-tail val))) + ))) + +(def: (base-for idx vec) + (All [a] (-> Index (Row a) (Maybe (Base a)))) + (let [vec-size (get@ #size vec)] + (if (and (n/>= +0 idx) + (n/< vec-size idx)) + (if (n/>= (tail-off vec-size) idx) + (#.Some (get@ #tail vec)) + (loop [level (get@ #level vec) + hierarchy (get@ #root vec)] + (case [(n/> branching-exponent level) + (array.read (branch-idx (bit.logical-right-shift level idx)) hierarchy)] + [true (#.Some (#Hierarchy sub))] + (recur (level-down level) sub) + + [false (#.Some (#Base base))] + (#.Some base) + + [_ #.None] + #.None + + _ + (error! "Incorrect row structure.")))) + #.None))) + +(def: #export (nth idx vec) + (All [a] (-> Nat (Row a) (Maybe a))) + (do maybe.Monad + [base (base-for idx vec)] + (array.read (branch-idx idx) base))) + +(def: #export (put idx val vec) + (All [a] (-> Nat a (Row a) (Row a))) + (let [vec-size (get@ #size vec)] + (if (and (n/>= +0 idx) + (n/< vec-size idx)) + (if (n/>= (tail-off vec-size) idx) + (|> vec + ## (update@ #tail (|>> array.clone (array.write (branch-idx idx) val))) + ## TODO: Remove once new-luxc becomes the standard compiler. + (update@ #tail (: (-> (Base ($ +0)) (Base ($ +0))) + (|>> array.clone (array.write (branch-idx idx) val)))) + ) + (|> vec + (update@ #root (put' (get@ #level vec) idx val)))) + vec))) + +(def: #export (update idx f vec) + (All [a] (-> Nat (-> a a) (Row a) (Row a))) + (case (nth idx vec) + (#.Some val) + (put idx (f val) vec) + + #.None + vec)) + +(def: #export (pop vec) + (All [a] (-> (Row a) (Row a))) + (case (get@ #size vec) + +0 + empty + + +1 + empty + + vec-size + (if (|> vec-size (n/- (tail-off vec-size)) (n/> +1)) + (let [old-tail (get@ #tail vec) + new-tail-size (dec (array.size old-tail))] + (|> vec + (update@ #size dec) + (set@ #tail (|> (array.new new-tail-size) + (array.copy new-tail-size +0 old-tail +0))))) + (maybe.assume + (do maybe.Monad + [new-tail (base-for (n/- +2 vec-size) vec) + #let [[level' root'] (let [init-level (get@ #level vec)] + (loop [level init-level + root (maybe.default (new-hierarchy []) + (pop-tail vec-size init-level (get@ #root vec)))] + (if (n/> branching-exponent level) + (case [(array.read +1 root) (array.read +0 root)] + [#.None (#.Some (#Hierarchy sub-node))] + (recur (level-down level) sub-node) + + ## [#.None (#.Some (#Base _))] + ## (undefined) + + _ + [level root]) + [level root])))]] + (wrap (|> vec + (update@ #size dec) + (set@ #level level') + (set@ #root root') + (set@ #tail new-tail)))))) + )) + +(def: #export (to-list vec) + (All [a] (-> (Row a) (List a))) + (list/compose (to-list' (#Hierarchy (get@ #root vec))) + (to-list' (#Base (get@ #tail vec))))) + +(def: #export (from-list list) + (All [a] (-> (List a) (Row a))) + (list/fold add + empty + list)) + +(def: #export (member? a/Eq vec val) + (All [a] (-> (Eq a) (Row a) a Bool)) + (list.member? a/Eq (to-list vec) val)) + +(def: #export empty? + (All [a] (-> (Row a) Bool)) + (|>> (get@ #size) (n/= +0))) + +## [Syntax] +(syntax: #export (row {elems (p.some s.any)}) + {#.doc (doc "Row literals." + (row 10 20 30 40))} + (wrap (list (` (from-list (list (~+ elems))))))) + +## [Structures] +(struct: #export (Eq Eq) (All [a] (-> (Eq a) (Eq (Node a)))) + (def: (= v1 v2) + (case [v1 v2] + [(#Base b1) (#Base b2)] + (:: (array.Eq Eq) = b1 b2) + + [(#Hierarchy h1) (#Hierarchy h2)] + (:: (array.Eq (Eq Eq)) = h1 h2) + + _ + false))) + +(struct: #export (Eq Eq) (All [a] (-> (Eq a) (Eq (Row a)))) + (def: (= v1 v2) + (and (n/= (get@ #size v1) (get@ #size v2)) + (let [(^open "Node/") (Eq Eq)] + (and (Node/= (#Base (get@ #tail v1)) + (#Base (get@ #tail v2))) + (Node/= (#Hierarchy (get@ #root v1)) + (#Hierarchy (get@ #root v2)))))))) + +(struct: _ (Fold Node) + (def: (fold f init xs) + (case xs + (#Base base) + (array/fold f init base) + + (#Hierarchy hierarchy) + (array/fold (function (_ node init') (fold f init' node)) + init + hierarchy)) + )) + +(struct: #export _ (Fold Row) + (def: (fold f init xs) + (let [(^open) Fold] + (fold f + (fold f + init + (#Hierarchy (get@ #root xs))) + (#Base (get@ #tail xs)))) + )) + +(struct: #export Monoid (All [a] (Monoid (Row a))) + (def: identity empty) + (def: (compose xs ys) + (list/fold add xs (to-list ys)))) + +(struct: _ (Functor Node) + (def: (map f xs) + (case xs + (#Base base) + (#Base (array/map f base)) + + (#Hierarchy hierarchy) + (#Hierarchy (array/map (map f) hierarchy))) + )) + +(struct: #export _ (Functor Row) + (def: (map f xs) + {#level (get@ #level xs) + #size (get@ #size xs) + #root (|> xs (get@ #root) (array/map (:: Functor map f))) + #tail (|> xs (get@ #tail) (array/map f)) + })) + +(struct: #export _ (Apply Row) + (def: functor Functor) + + (def: (apply ff fa) + (let [(^open) Functor + (^open) Fold + (^open) Monoid + results (map (function (_ f) (map f fa)) + ff)] + (fold compose identity results)))) + +(struct: #export _ (Monad Row) + (def: functor Functor) + + (def: wrap (|>> row)) + + (def: join + (let [(^open) Fold + (^open) Monoid] + (fold (function (_ post pre) (compose pre post)) identity)))) + +(def: #export (reverse xs) + (All [a] (-> (Row a) (Row a))) + (let [(^open) Fold + (^open) Monoid] + (fold add identity xs))) diff --git a/stdlib/source/lux/data/coll/sequence.lux b/stdlib/source/lux/data/coll/sequence.lux deleted file mode 100644 index 4e6226dcd..000000000 --- a/stdlib/source/lux/data/coll/sequence.lux +++ /dev/null @@ -1,438 +0,0 @@ -(.module: - lux - (lux (control [functor #+ Functor] - [apply #+ Apply] - [monad #+ do Monad] - [equality #+ Eq] - monoid - fold - ["p" parser]) - (data [maybe] - (coll [list "list/" Fold Functor Monoid] - [array "array/" Functor Fold]) - [bit] - [product]) - [macro #+ with-gensyms] - (macro [code] - ["s" syntax #+ syntax: Syntax]) - )) - -## [Utils] -(type: (Node a) - (#Base (Array a)) - (#Hierarchy (Array (Node a)))) - -(type: (Base a) (Array a)) -(type: (Hierarchy a) (Array (Node a))) - -(type: Level Nat) - -(type: Index Nat) - -(def: branching-exponent - Nat - +5) - -(def: root-level - Level - +0) - -(do-template [ ] - [(def: - (-> Level Level) - ( branching-exponent))] - - [level-up n/+] - [level-down n/-] - ) - -(def: full-node-size - Nat - (bit.left-shift branching-exponent +1)) - -(def: branch-idx-mask - Nat - (dec full-node-size)) - -(def: branch-idx - (-> Index Index) - (bit.and branch-idx-mask)) - -(def: (new-hierarchy _) - (All [a] (-> Any (Hierarchy a))) - (array.new full-node-size)) - -(def: (tail-off vec-size) - (-> Nat Nat) - (if (n/< full-node-size vec-size) - +0 - (|> (dec vec-size) - (bit.logical-right-shift branching-exponent) - (bit.left-shift branching-exponent)))) - -(def: (new-path level tail) - (All [a] (-> Level (Base a) (Node a))) - (if (n/= +0 level) - (#Base tail) - (|> (new-hierarchy []) - (array.write +0 (new-path (level-down level) tail)) - #Hierarchy))) - -(def: (new-tail singleton) - (All [a] (-> a (Base a))) - (|> (array.new +1) - (array.write +0 singleton))) - -(def: (push-tail size level tail parent) - (All [a] (-> Nat Level (Base a) (Hierarchy a) (Hierarchy a))) - (let [sub-idx (branch-idx (bit.logical-right-shift level (dec size))) - ## If we're currently on a bottom node - sub-node (if (n/= branching-exponent level) - ## Just add the tail to it - (#Base tail) - ## Otherwise, check whether there's a vacant spot - (case (array.read sub-idx parent) - ## If so, set the path to the tail - #.None - (new-path (level-down level) tail) - ## If not, push the tail onto the sub-node. - (#.Some (#Hierarchy sub-node)) - (#Hierarchy (push-tail size (level-down level) tail sub-node)) - - _ - (undefined)) - )] - (|> (array.clone parent) - (array.write sub-idx sub-node)))) - -(def: (expand-tail val tail) - (All [a] (-> a (Base a) (Base a))) - (let [tail-size (array.size tail)] - (|> (array.new (inc tail-size)) - (array.copy tail-size +0 tail +0) - (array.write tail-size val)))) - -(def: (put' level idx val hierarchy) - (All [a] (-> Level Index a (Hierarchy a) (Hierarchy a))) - (let [sub-idx (branch-idx (bit.logical-right-shift level idx))] - (case (array.read sub-idx hierarchy) - (#.Some (#Hierarchy sub-node)) - (|> (array.clone hierarchy) - (array.write sub-idx (#Hierarchy (put' (level-down level) idx val sub-node)))) - - (^multi (#.Some (#Base base)) - (n/= +0 (level-down level))) - (|> (array.clone hierarchy) - (array.write sub-idx (|> (array.clone base) - (array.write (branch-idx idx) val) - #Base))) - - _ - (undefined)))) - -(def: (pop-tail size level hierarchy) - (All [a] (-> Nat Level (Hierarchy a) (Maybe (Hierarchy a)))) - (let [sub-idx (branch-idx (bit.logical-right-shift level (n/- +2 size)))] - (cond (n/= +0 sub-idx) - #.None - - (n/> branching-exponent level) - (do maybe.Monad - [base|hierarchy (array.read sub-idx hierarchy) - sub (case base|hierarchy - (#Hierarchy sub) - (pop-tail size (level-down level) sub) - - (#Base _) - (undefined))] - (|> (array.clone hierarchy) - (array.write sub-idx (#Hierarchy sub)) - #.Some)) - - ## Else... - (|> (array.clone hierarchy) - (array.delete sub-idx) - #.Some) - ))) - -(def: (to-list' node) - (All [a] (-> (Node a) (List a))) - (case node - (#Base base) - (array.to-list base) - - (#Hierarchy hierarchy) - (|> hierarchy - array.to-list - list.reverse - (list/fold (function (_ sub acc) (list/compose (to-list' sub) acc)) - #.Nil)))) - -## [Types] -(type: #export (Sequence a) - {#level Level - #size Nat - #root (Hierarchy a) - #tail (Base a)}) - -## [Exports] -(def: #export empty - Sequence - {#level (level-up root-level) - #size +0 - #root (array.new full-node-size) - #tail (array.new +0)}) - -(def: #export (size sequence) - (All [a] (-> (Sequence a) Nat)) - (get@ #size sequence)) - -(def: #export (add val vec) - (All [a] (-> a (Sequence a) (Sequence a))) - ## Check if there is room in the tail. - (let [vec-size (get@ #size vec)] - (if (|> vec-size (n/- (tail-off vec-size)) (n/< full-node-size)) - ## If so, append to it. - (|> vec - (update@ #size inc) - (update@ #tail (expand-tail val))) - ## Otherwise, push tail into the tree - ## -------------------------------------------------------- - ## Will the root experience an overflow with this addition? - (|> (if (n/> (bit.left-shift (get@ #level vec) +1) - (bit.logical-right-shift branching-exponent vec-size)) - ## If so, a brand-new root must be established, that is - ## 1-level taller. - (|> vec - (set@ #root (|> (: (Hierarchy ($ +0)) - (new-hierarchy [])) - ## TODO: Remove version above once new-luxc becomes the standard compiler. - ## (new-hierarchy []) - (array.write +0 (#Hierarchy (get@ #root vec))) - (array.write +1 (new-path (get@ #level vec) (get@ #tail vec))))) - (update@ #level level-up)) - ## Otherwise, just push the current tail onto the root. - (|> vec - (update@ #root (push-tail vec-size (get@ #level vec) (get@ #tail vec))))) - ## Finally, update the size of the Sequence and grow a new - ## tail with the new element as it's sole member. - (update@ #size inc) - (set@ #tail (new-tail val))) - ))) - -(def: (base-for idx vec) - (All [a] (-> Index (Sequence a) (Maybe (Base a)))) - (let [vec-size (get@ #size vec)] - (if (and (n/>= +0 idx) - (n/< vec-size idx)) - (if (n/>= (tail-off vec-size) idx) - (#.Some (get@ #tail vec)) - (loop [level (get@ #level vec) - hierarchy (get@ #root vec)] - (case [(n/> branching-exponent level) - (array.read (branch-idx (bit.logical-right-shift level idx)) hierarchy)] - [true (#.Some (#Hierarchy sub))] - (recur (level-down level) sub) - - [false (#.Some (#Base base))] - (#.Some base) - - [_ #.None] - #.None - - _ - (error! "Incorrect sequence structure.")))) - #.None))) - -(def: #export (nth idx vec) - (All [a] (-> Nat (Sequence a) (Maybe a))) - (do maybe.Monad - [base (base-for idx vec)] - (array.read (branch-idx idx) base))) - -(def: #export (put idx val vec) - (All [a] (-> Nat a (Sequence a) (Sequence a))) - (let [vec-size (get@ #size vec)] - (if (and (n/>= +0 idx) - (n/< vec-size idx)) - (if (n/>= (tail-off vec-size) idx) - (|> vec - ## (update@ #tail (|>> array.clone (array.write (branch-idx idx) val))) - ## TODO: Remove once new-luxc becomes the standard compiler. - (update@ #tail (: (-> (Base ($ +0)) (Base ($ +0))) - (|>> array.clone (array.write (branch-idx idx) val)))) - ) - (|> vec - (update@ #root (put' (get@ #level vec) idx val)))) - vec))) - -(def: #export (update idx f vec) - (All [a] (-> Nat (-> a a) (Sequence a) (Sequence a))) - (case (nth idx vec) - (#.Some val) - (put idx (f val) vec) - - #.None - vec)) - -(def: #export (pop vec) - (All [a] (-> (Sequence a) (Sequence a))) - (case (get@ #size vec) - +0 - empty - - +1 - empty - - vec-size - (if (|> vec-size (n/- (tail-off vec-size)) (n/> +1)) - (let [old-tail (get@ #tail vec) - new-tail-size (dec (array.size old-tail))] - (|> vec - (update@ #size dec) - (set@ #tail (|> (array.new new-tail-size) - (array.copy new-tail-size +0 old-tail +0))))) - (maybe.assume - (do maybe.Monad - [new-tail (base-for (n/- +2 vec-size) vec) - #let [[level' root'] (let [init-level (get@ #level vec)] - (loop [level init-level - root (maybe.default (new-hierarchy []) - (pop-tail vec-size init-level (get@ #root vec)))] - (if (n/> branching-exponent level) - (case [(array.read +1 root) (array.read +0 root)] - [#.None (#.Some (#Hierarchy sub-node))] - (recur (level-down level) sub-node) - - ## [#.None (#.Some (#Base _))] - ## (undefined) - - _ - [level root]) - [level root])))]] - (wrap (|> vec - (update@ #size dec) - (set@ #level level') - (set@ #root root') - (set@ #tail new-tail)))))) - )) - -(def: #export (to-list vec) - (All [a] (-> (Sequence a) (List a))) - (list/compose (to-list' (#Hierarchy (get@ #root vec))) - (to-list' (#Base (get@ #tail vec))))) - -(def: #export (from-list list) - (All [a] (-> (List a) (Sequence a))) - (list/fold add - empty - list)) - -(def: #export (member? a/Eq vec val) - (All [a] (-> (Eq a) (Sequence a) a Bool)) - (list.member? a/Eq (to-list vec) val)) - -(def: #export empty? - (All [a] (-> (Sequence a) Bool)) - (|>> (get@ #size) (n/= +0))) - -## [Syntax] -(syntax: #export (sequence {elems (p.some s.any)}) - {#.doc (doc "Sequence literals." - (sequence 10 20 30 40))} - (wrap (list (` (from-list (list (~+ elems))))))) - -## [Structures] -(struct: #export (Eq Eq) (All [a] (-> (Eq a) (Eq (Node a)))) - (def: (= v1 v2) - (case [v1 v2] - [(#Base b1) (#Base b2)] - (:: (array.Eq Eq) = b1 b2) - - [(#Hierarchy h1) (#Hierarchy h2)] - (:: (array.Eq (Eq Eq)) = h1 h2) - - _ - false))) - -(struct: #export (Eq Eq) (All [a] (-> (Eq a) (Eq (Sequence a)))) - (def: (= v1 v2) - (and (n/= (get@ #size v1) (get@ #size v2)) - (let [(^open "Node/") (Eq Eq)] - (and (Node/= (#Base (get@ #tail v1)) - (#Base (get@ #tail v2))) - (Node/= (#Hierarchy (get@ #root v1)) - (#Hierarchy (get@ #root v2)))))))) - -(struct: _ (Fold Node) - (def: (fold f init xs) - (case xs - (#Base base) - (array/fold f init base) - - (#Hierarchy hierarchy) - (array/fold (function (_ node init') (fold f init' node)) - init - hierarchy)) - )) - -(struct: #export _ (Fold Sequence) - (def: (fold f init xs) - (let [(^open) Fold] - (fold f - (fold f - init - (#Hierarchy (get@ #root xs))) - (#Base (get@ #tail xs)))) - )) - -(struct: #export Monoid (All [a] - (Monoid (Sequence a))) - (def: identity empty) - (def: (compose xs ys) - (list/fold add xs (to-list ys)))) - -(struct: _ (Functor Node) - (def: (map f xs) - (case xs - (#Base base) - (#Base (array/map f base)) - - (#Hierarchy hierarchy) - (#Hierarchy (array/map (map f) hierarchy))) - )) - -(struct: #export _ (Functor Sequence) - (def: (map f xs) - {#level (get@ #level xs) - #size (get@ #size xs) - #root (|> xs (get@ #root) (array/map (:: Functor map f))) - #tail (|> xs (get@ #tail) (array/map f)) - })) - -(struct: #export _ (Apply Sequence) - (def: functor Functor) - - (def: (apply ff fa) - (let [(^open) Functor - (^open) Fold - (^open) Monoid - results (map (function (_ f) (map f fa)) - ff)] - (fold compose identity results)))) - -(struct: #export _ (Monad Sequence) - (def: functor Functor) - - (def: wrap (|>> sequence)) - - (def: join - (let [(^open) Fold - (^open) Monoid] - (fold (function (_ post pre) (compose pre post)) identity)))) - -(def: #export (reverse xs) - (All [a] (-> (Sequence a) (Sequence a))) - (let [(^open) Fold - (^open) Monoid] - (fold add identity xs))) diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 9262c3d70..a5c81ad6b 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -15,7 +15,7 @@ [sum] [product] (coll [list "list/" Fold Monad] - [sequence #+ Sequence sequence "sequence/" Monad] + [row #+ Row row "row/" Monad] (dictionary ["dict" unordered #+ Dict]))) [macro #+ Monad with-gensyms] (macro ["s" syntax #+ syntax:] @@ -35,13 +35,13 @@ (#Boolean Boolean) (#Number Number) (#String String) - (#Array (Sequence JSON)) + (#Array (Row JSON)) (#Object (Dict String JSON))) (do-template [ ] [(type: #export )] - [Array (Sequence JSON)] + [Array (Row JSON)] [Object (Dict String JSON)] ) @@ -72,7 +72,7 @@ (wrap (list (` (: JSON #Null)))) [_ (#.Tuple members)] - (wrap (list (` (: JSON (#Array (sequence (~+ (list/map wrapper members)))))))) + (wrap (list (` (: JSON (#Array (row (~+ (list/map wrapper members)))))))) [_ (#.Record pairs)] (do Monad @@ -161,16 +161,16 @@ [#String text.Eq]) [(#Array xs) (#Array ys)] - (and (n/= (sequence.size xs) (sequence.size ys)) + (and (n/= (row.size xs) (row.size ys)) (list/fold (function (_ idx prev) (and prev (maybe.default false (do maybe.Monad - [x' (sequence.nth idx xs) - y' (sequence.nth idx ys)] + [x' (row.nth idx xs) + y' (row.nth idx ys)] (wrap (= x' y')))))) true - (list.indices (sequence.size xs)))) + (list.indices (row.size xs)))) [(#Object xs) (#Object ys)] (and (n/= (dict.size xs) (dict.size ys)) @@ -285,7 +285,7 @@ [head any] (case head (#Array values) - (case (p.run (sequence.to-list values) parser) + (case (p.run (row.to-list values) parser) (#e.Error error) (fail error) @@ -364,7 +364,7 @@ (def: (show-array show-json elems) (-> (-> JSON Text) (-> Array Text)) ($_ text/compose "[" - (|> elems (sequence/map show-json) sequence.to-list (text.join-with ",")) + (|> elems (row/map show-json) row.to-list (text.join-with ",")) "]")) (def: (show-object show-json object) @@ -487,7 +487,7 @@ _ (l.this )] (wrap ( elems))))] - [array~ Array "[" "]" (json~ []) sequence.from-list] + [array~ Array "[" "]" (json~ []) row.from-list] [object~ Object "{" "}" (kv~ json~) (dict.from-list text.Hash)] ) diff --git a/stdlib/source/lux/lang/compiler/translation.lux b/stdlib/source/lux/lang/compiler/translation.lux index c117bc019..d5a6fb255 100644 --- a/stdlib/source/lux/lang/compiler/translation.lux +++ b/stdlib/source/lux/lang/compiler/translation.lux @@ -6,7 +6,7 @@ [error #+ Error] [text] text/format - (coll [sequence #+ Sequence] + (coll [row #+ Row] (dictionary ["dict" unordered #+ Dict]))) (world [file #+ File])) [//name] @@ -35,7 +35,7 @@ (: (-> code (Error Any)) evaluate!)) -(type: #export (Buffer code) (Sequence [Ident code])) +(type: #export (Buffer code) (Row [Ident code])) (type: #export (Artifacts code) (Dict File (Buffer code))) @@ -117,7 +117,7 @@ with-buffer (-> (Operation (..State anchor code) output) (Operation (..State anchor code) output)) - sequence.empty + row.empty buffer (Buffer code) no-active-buffer] ) @@ -150,7 +150,7 @@ [_ (execute! code)] (function (_ state) (#error.Success [(update@ #buffer - (maybe/map (sequence.add [name code])) + (maybe/map (row.add [name code])) state) []])))) diff --git a/stdlib/source/lux/lang/syntax.lux b/stdlib/source/lux/lang/syntax.lux index 8029b5975..bbbd19232 100644 --- a/stdlib/source/lux/lang/syntax.lux +++ b/stdlib/source/lux/lang/syntax.lux @@ -36,7 +36,7 @@ [text] (text ["l" lexer] format) - (coll [sequence #+ Sequence] + (coll [row #+ Row] (dictionary ["dict" unordered #+ Dict]))))) (type: #export Aliases (Dict Text Text)) @@ -424,14 +424,14 @@ (l.Lexer [Cursor Code])) (do p.Monad [_ (l.this ) - [where' elems] (loop [elems (: (Sequence Code) - sequence.empty) + [where' elems] (loop [elems (: (Row Code) + row.empty) where where] (p.either (do @ [## Must update the cursor as I ## go along, to keep things accurate. [where' elem] (ast where)] - (recur (sequence.add elem elems) + (recur (row.add elem elems) where')) (do @ [## Must take into account any @@ -440,7 +440,7 @@ where' (left-padding^ where) _ (l.this )] (wrap [(update@ #.column inc where') - (sequence.to-list elems)]))))] + (row.to-list elems)]))))] (wrap [where' [where ( elems)]])))] @@ -463,19 +463,19 @@ (l.Lexer [Cursor Code])) (do p.Monad [_ (l.this "{") - [where' elems] (loop [elems (: (Sequence [Code Code]) - sequence.empty) + [where' elems] (loop [elems (: (Row [Code Code]) + row.empty) where where] (p.either (do @ [[where' key] (ast where) [where' val] (ast where')] - (recur (sequence.add [key val] elems) + (recur (row.add [key val] elems) where')) (do @ [where' (left-padding^ where) _ (l.this "}")] (wrap [(update@ #.column inc where') - (sequence.to-list elems)]))))] + (row.to-list elems)]))))] (wrap [where' [where (#.Record elems)]]))) diff --git a/stdlib/source/lux/macro/poly/equality.lux b/stdlib/source/lux/macro/poly/equality.lux index 8df347bba..bdf70d622 100644 --- a/stdlib/source/lux/macro/poly/equality.lux +++ b/stdlib/source/lux/macro/poly/equality.lux @@ -6,7 +6,7 @@ (data [text "text/" Monoid] text/format (coll [list "list/" Monad] - [sequence] + [row] [array] [queue] (set ["set" unordered]) @@ -62,7 +62,7 @@ [.Maybe maybe.Eq] [.List list.Eq] - [sequence.Sequence sequence.Eq] + [row.Row row.Eq] [.Array array.Eq] [queue.Queue queue.Eq] [set.Set set.Eq] diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux index ba20f7627..ba8512835 100644 --- a/stdlib/source/lux/macro/poly/json.lux +++ b/stdlib/source/lux/macro/poly/json.lux @@ -15,7 +15,7 @@ [sum] [product] (coll [list "list/" Fold Monad] - [sequence #+ Sequence sequence "sequence/" Monad] + [row #+ Row row "row/" Monad] (dictionary ["d" unordered])) (format ["//" json #+ JSON])) (time ## ["i" instant] @@ -47,8 +47,8 @@ (def: (encode input) (let [high (|> input (bit.and high-mask) (bit.logical-right-shift +32)) low (bit.and low-mask input)] - (#//.Array (sequence (|> high .int int-to-frac #//.Number) - (|> low .int int-to-frac #//.Number))))) + (#//.Array (row (|> high .int int-to-frac #//.Number) + (|> low .int int-to-frac #//.Number))))) (def: (decode input) (<| (//.run input) //.array @@ -143,7 +143,7 @@ (poly.this .List) Codec//encode))] (wrap (` (: (~ (@JSON//encode inputT)) - (|>> ((~! list/map) (~ =sub=)) sequence.from-list #//.Array))))) + (|>> ((~! list/map) (~ =sub=)) row.from-list #//.Array))))) (do @ [#let [g!_ (code.local-symbol "_______") g!input (code.local-symbol "_______input")] diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index 55c504585..b8db79ccb 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -18,7 +18,7 @@ [queue #+ Queue] (set ["set" unordered #+ Set]) [stack #+ Stack] - [sequence #+ Sequence] + [row #+ Row] (tree [finger #+ Tree]))) )) @@ -194,7 +194,7 @@ (:: Monad wrap )))] [list List (.list) #.Cons] - [sequence Sequence sequence.empty sequence.add] + [row Row row.empty row.add] ) (do-template [ ] @@ -274,21 +274,21 @@ ("lux i64 +" s0 s1)])) (def: (swap from to vec) - (All [a] (-> Nat Nat (Sequence a) (Sequence a))) + (All [a] (-> Nat Nat (Row a) (Row a))) (|> vec - (sequence.put to (maybe.assume (sequence.nth from vec))) - (sequence.put from (maybe.assume (sequence.nth to vec))))) + (row.put to (maybe.assume (row.nth from vec))) + (row.put from (maybe.assume (row.nth to vec))))) -(def: #export (shuffle seed sequence) - {#.doc "Shuffle a sequence randomly based on a seed value."} - (All [a] (-> Nat (Sequence a) (Sequence a))) - (let [_size (sequence.size sequence) +(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 (function (_ idx vec) (do Monad [rand nat] (wrap (swap idx (n/% _size rand) vec)))) - sequence + row (list.n/range +0 (dec _size)))] (|> _shuffle (run (pcg-32 [+123 seed])) diff --git a/stdlib/source/lux/time/date.lux b/stdlib/source/lux/time/date.lux index 89f906040..2a937c84d 100644 --- a/stdlib/source/lux/time/date.lux +++ b/stdlib/source/lux/time/date.lux @@ -11,7 +11,7 @@ [number "int/" Codec] [text "text/" Monoid] (text ["l" lexer]) - (coll [sequence #+ Sequence sequence])))) + (coll [row #+ Row row])))) (type: #export Year Int) @@ -252,15 +252,15 @@ (i/+ (i// 400 year)))) (def: normal-months - (Sequence Nat) - (sequence +31 +28 +31 - +30 +31 +30 - +31 +31 +30 - +31 +30 +31)) + (Row Nat) + (row +31 +28 +31 + +30 +31 +30 + +31 +31 +30 + +31 +30 +31)) (def: leap-year-months - (Sequence Nat) - (sequence.update [+1] inc normal-months)) + (Row Nat) + (row.update [+1] inc normal-months)) (def: (divisible? factor input) (-> Int Int Bool) @@ -286,7 +286,7 @@ leap-year-months normal-months) month-days (|> months - (sequence.nth (.nat (dec utc-month))) + (row.nth (.nat (dec utc-month))) maybe.assume)] _ (l.this "-") utc-day lex-section diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index 1a2af827e..68a86bf9d 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -13,7 +13,7 @@ ["e" error] [maybe] (coll [list "L/" Fold Functor] - [sequence #+ Sequence sequence "sequence/" Functor Fold])) + [row #+ Row row "row/" Functor Fold])) (type abstract)) (// [duration "duration/" Order] [date])) @@ -102,33 +102,33 @@ )))) (def: normal-months - (Sequence Nat) - (sequence +31 +28 +31 - +30 +31 +30 - +31 +31 +30 - +31 +30 +31)) + (Row Nat) + (row +31 +28 +31 + +30 +31 +30 + +31 +31 +30 + +31 +30 +31)) (def: leap-year-months - (Sequence Nat) - (sequence.update [+1] inc normal-months)) + (Row Nat) + (row.update [+1] inc normal-months)) (def: (find-month months time) - (-> (Sequence Nat) duration.Duration [Nat duration.Duration]) + (-> (Row Nat) duration.Duration [Nat duration.Duration]) (if (duration/>= duration.empty time) - (sequence/fold (function (_ month-days [current-month time-left]) - (let [month-duration (duration.scale (.int month-days) duration.day)] - (if (i/= 0 (duration.query month-duration time-left)) - [current-month time-left] - [(inc current-month) (duration.merge (duration.scale -1 month-duration) time-left)]))) - [+0 time] - months) - (sequence/fold (function (_ month-days [current-month time-left]) - (let [month-duration (duration.scale (.int month-days) duration.day)] - (if (i/= 0 (duration.query month-duration time-left)) - [current-month time-left] - [(dec current-month) (duration.merge month-duration time-left)]))) - [+11 time] - (sequence.reverse months)))) + (row/fold (function (_ month-days [current-month time-left]) + (let [month-duration (duration.scale (.int month-days) duration.day)] + (if (i/= 0 (duration.query month-duration time-left)) + [current-month time-left] + [(inc current-month) (duration.merge (duration.scale -1 month-duration) time-left)]))) + [+0 time] + months) + (row/fold (function (_ month-days [current-month time-left]) + (let [month-duration (duration.scale (.int month-days) duration.day)] + (if (i/= 0 (duration.query month-duration time-left)) + [current-month time-left] + [(dec current-month) (duration.merge month-duration time-left)]))) + [+11 time] + (row.reverse months)))) (def: (pad value) (-> Int Text) @@ -251,7 +251,7 @@ leap-year-months normal-months) month-days (|> months - (sequence.nth (.nat (dec utc-month))) + (row.nth (.nat (dec utc-month))) maybe.assume)] _ (l.this "-") utc-day lex-section @@ -281,7 +281,7 @@ year-days-so-far (|> (i/* 365 years-since-epoch) (i/+ previous-leap-days)) month-days-so-far (|> months - sequence.to-list + row.to-list (list.take (.nat (dec utc-month))) (L/fold n/+ +0)) total-days (|> year-days-so-far diff --git a/stdlib/source/lux/type/resource.lux b/stdlib/source/lux/type/resource.lux index eafda2092..ea86f45e8 100644 --- a/stdlib/source/lux/type/resource.lux +++ b/stdlib/source/lux/type/resource.lux @@ -11,7 +11,7 @@ text/format (coll (dictionary ["dict" unordered #+ Dict]) (set ["set" unordered]) - [sequence #+ Sequence] + [row #+ Row] [list "list/" Functor Fold])) (concurrency [promise #+ Promise]) [macro] @@ -155,11 +155,11 @@ (function (_ from to) (do maybe.Monad [input (list.nth from g!inputs)] - (wrap (sequence.add input to)))) - (: (Sequence Code) sequence.empty) + (wrap (row.add input to)))) + (: (Row Code) row.empty) swaps) maybe.assume - sequence.to-list) + row.to-list) g!inputsT+ (list/map (|>> (~) ..CK (`)) g!inputs) g!outputsT+ (list/map (|>> (~) ..CK (`)) g!outputs)]] (wrap (list (` (: (All [(~+ g!inputs) (~ g!context)] diff --git a/stdlib/test/test/lux/data/coll/row.lux b/stdlib/test/test/lux/data/coll/row.lux new file mode 100644 index 000000000..3a4da0f42 --- /dev/null +++ b/stdlib/test/test/lux/data/coll/row.lux @@ -0,0 +1,73 @@ +(.module: + lux + (lux [io] + (control [monad #+ do Monad]) + (data (coll ["&" row] + [list "list/" Fold]) + [number] + [maybe]) + ["r" math/random]) + lux/test) + +(context: "Rows" + (<| (times +100) + (do @ + [size (|> r.nat (:: @ map (|>> (n/% +100) (n/max +1)))) + idx (|> r.nat (:: @ map (n/% size))) + sample (r.row size r.nat) + other-sample (r.row size r.nat) + non-member (|> r.nat (r.filter (|>> (&.member? number.Eq sample) not))) + #let [(^open "&/") (&.Eq number.Eq) + (^open "&/") &.Apply + (^open "&/") &.Monad + (^open "&/") &.Fold + (^open "&/") &.Monoid]] + ($_ seq + (test "Can query size of row." + (if (&.empty? sample) + (and (n/= +0 size) + (n/= +0 (&.size sample))) + (n/= size (&.size sample)))) + + (test "Can add and remove elements to rows." + (and (n/= (inc size) (&.size (&.add non-member sample))) + (n/= (dec size) (&.size (&.pop sample))))) + + (test "Can put and get elements into rows." + (|> sample + (&.put idx non-member) + (&.nth idx) + maybe.assume + (is? non-member))) + + (test "Can update elements of rows." + (|> sample + (&.put idx non-member) (&.update idx inc) + (&.nth idx) maybe.assume + (n/= (inc non-member)))) + + (test "Can safely transform to/from lists." + (|> sample &.to-list &.from-list (&/= sample))) + + (test "Can identify members of a row." + (and (not (&.member? number.Eq sample non-member)) + (&.member? number.Eq (&.add non-member sample) non-member))) + + (test "Can fold over elements of row." + (n/= (list/fold n/+ +0 (&.to-list sample)) + (&/fold n/+ +0 sample))) + + (test "Functor goes over every element." + (let [there (&/map inc sample) + back-again (&/map dec there)] + (and (not (&/= sample there)) + (&/= sample back-again)))) + + (test "Apply allows you to create singleton rows, and apply rows of functions to rows of values." + (and (&/= (&.row non-member) (&/wrap non-member)) + (&/= (&/map inc sample) (&/apply (&/wrap inc) sample)))) + + (test "Row concatenation is a monad." + (&/= (&/compose sample other-sample) + (&/join (&.row sample other-sample)))) + )))) diff --git a/stdlib/test/test/lux/data/coll/sequence.lux b/stdlib/test/test/lux/data/coll/sequence.lux deleted file mode 100644 index 024e91c6b..000000000 --- a/stdlib/test/test/lux/data/coll/sequence.lux +++ /dev/null @@ -1,73 +0,0 @@ -(.module: - lux - (lux [io] - (control [monad #+ do Monad]) - (data (coll ["&" sequence] - [list "list/" Fold]) - [number] - [maybe]) - ["r" math/random]) - lux/test) - -(context: "Sequences" - (<| (times +100) - (do @ - [size (|> r.nat (:: @ map (|>> (n/% +100) (n/max +1)))) - idx (|> r.nat (:: @ map (n/% size))) - sample (r.sequence size r.nat) - other-sample (r.sequence size r.nat) - non-member (|> r.nat (r.filter (|>> (&.member? number.Eq sample) not))) - #let [(^open "&/") (&.Eq number.Eq) - (^open "&/") &.Apply - (^open "&/") &.Monad - (^open "&/") &.Fold - (^open "&/") &.Monoid]] - ($_ seq - (test "Can query size of sequence." - (if (&.empty? sample) - (and (n/= +0 size) - (n/= +0 (&.size sample))) - (n/= size (&.size sample)))) - - (test "Can add and remove elements to sequences." - (and (n/= (inc size) (&.size (&.add non-member sample))) - (n/= (dec size) (&.size (&.pop sample))))) - - (test "Can put and get elements into sequences." - (|> sample - (&.put idx non-member) - (&.nth idx) - maybe.assume - (is? non-member))) - - (test "Can update elements of sequences." - (|> sample - (&.put idx non-member) (&.update idx inc) - (&.nth idx) maybe.assume - (n/= (inc non-member)))) - - (test "Can safely transform to/from lists." - (|> sample &.to-list &.from-list (&/= sample))) - - (test "Can identify members of a sequence." - (and (not (&.member? number.Eq sample non-member)) - (&.member? number.Eq (&.add non-member sample) non-member))) - - (test "Can fold over elements of sequence." - (n/= (list/fold n/+ +0 (&.to-list sample)) - (&/fold n/+ +0 sample))) - - (test "Functor goes over every element." - (let [there (&/map inc sample) - back-again (&/map dec there)] - (and (not (&/= sample there)) - (&/= sample back-again)))) - - (test "Apply allows you to create singleton sequences, and apply sequences of functions to sequences of values." - (and (&/= (&.sequence non-member) (&/wrap non-member)) - (&/= (&/map inc sample) (&/apply (&/wrap inc) sample)))) - - (test "Sequence concatenation is a monad." - (&/= (&/compose sample other-sample) - (&/join (&.sequence sample other-sample)))) - )))) diff --git a/stdlib/test/test/lux/data/format/json.lux b/stdlib/test/test/lux/data/format/json.lux index a8a117a04..b3196e1e6 100644 --- a/stdlib/test/test/lux/data/format/json.lux +++ b/stdlib/test/test/lux/data/format/json.lux @@ -13,7 +13,7 @@ [maybe] [number] (format ["@" json]) - (coll [sequence #+ sequence] + (coll [row #+ row] (dictionary ["d" unordered]) [list])) [macro #+ with-gensyms] @@ -43,7 +43,7 @@ r.bool (|> r.frac (:: @ map (f/* 1_000_000.0))) (r.unicode size) - (r.sequence size gen-json) + (r.row size gen-json) (r.dict text.Hash size (r.unicode size) gen-json) ))))) diff --git a/stdlib/test/test/lux/math/random.lux b/stdlib/test/test/lux/math/random.lux index 4230f27b1..b2f4fe6ca 100644 --- a/stdlib/test/test/lux/math/random.lux +++ b/stdlib/test/test/lux/math/random.lux @@ -5,7 +5,7 @@ (data [number] text/format (coll [list] - [sequence] + [row] [array] [queue] [stack] @@ -19,7 +19,7 @@ (do @ [size (|> r.nat (:: @ map (|>> (n/% +100) (n/max +10)))) _list (r.list size r.nat) - _sequence (r.sequence size r.nat) + _row (r.row size r.nat) _array (r.array size r.nat) _queue (r.queue size r.nat) _stack (r.stack size r.nat) @@ -28,14 +28,14 @@ top r.nat filtered (|> r.nat (r.filter (n/<= top))) shuffle-seed r.nat - #let [sorted (|> _sequence sequence.to-list (list.sort n/<)) - shuffled (|> sorted sequence.from-list (r.shuffle shuffle-seed)) - re-sorted (|> shuffled sequence.to-list (list.sort n/<))]] + #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/<))]] ($_ seq (test "Can produce lists." (n/= size (list.size _list))) - (test "Can produce sequences." - (n/= size (sequence.size _sequence))) + (test "Can produce rows." + (n/= size (row.size _row))) (test "Can produce arrays." (n/= size (array.size _array))) (test "Can produce queues." @@ -48,9 +48,9 @@ (n/= size (dict.size _dict))) (test "Can filter values." (n/<= top filtered)) - (test "Can shuffle sequences." - (let [(^open "v/") (sequence.Eq number.Eq) - sorted (sequence.from-list sorted)] + (test "Can shuffle rows." + (let [(^open "v/") (row.Eq number.Eq) + sorted (row.from-list sorted)] (and (not (v/= sorted shuffled)) - (v/= sorted (sequence.from-list re-sorted))))) + (v/= sorted (row.from-list re-sorted))))) )))) -- cgit v1.2.3