diff options
author | Eduardo Julian | 2017-10-16 19:55:24 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-10-16 19:55:24 -0400 |
commit | 25609806f670b4e6a5ef0b132929c1f4f96ed100 (patch) | |
tree | 50b107d94a9c2109e4589646fa7c8cf2372863d2 | |
parent | f54e6e22e5044a0cdf28e5ee01e90e1866b29dfc (diff) |
- Re-named "Vector" to "Sequence" to avoid confusion with mathematical vectors.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux.lux | 6 | ||||
-rw-r--r-- | stdlib/source/lux/data/coll/sequence.lux (renamed from stdlib/source/lux/data/coll/vector.lux) | 81 | ||||
-rw-r--r-- | stdlib/source/lux/data/format/json.lux | 22 | ||||
-rw-r--r-- | stdlib/source/lux/host.jvm.lux | 10 | ||||
-rw-r--r-- | stdlib/source/lux/macro/poly/eq.lux | 16 | ||||
-rw-r--r-- | stdlib/source/lux/macro/poly/json.lux | 8 | ||||
-rw-r--r-- | stdlib/source/lux/math/random.lux | 22 | ||||
-rw-r--r-- | stdlib/source/lux/time/date.lux | 12 | ||||
-rw-r--r-- | stdlib/source/lux/time/instant.lux | 44 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/coll/sequence.lux (renamed from stdlib/test/test/lux/data/coll/vector.lux) | 36 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/format/json.lux | 4 | ||||
-rw-r--r-- | stdlib/test/test/lux/math/random.lux | 22 | ||||
-rw-r--r-- | stdlib/test/tests.lux | 2 |
13 files changed, 141 insertions, 144 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 7d26ce777..e8bd4d3ea 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -2192,7 +2192,7 @@ (|> data' (join-map (. apply (make-env bindings'))) return) - (fail "Irregular arguments vectors for do-template."))) + (fail "Irregular arguments tuples for do-template."))) _ (fail "Wrong syntax for do-template")) @@ -5625,9 +5625,9 @@ {#;doc (doc "Allows you to refer to the type-variables in a polymorphic function's type, by their index." "In the example below, +0 corresponds to the 'a' variable." (def: #export (from-list list) - (All [a] (-> (List a) (Vector a))) + (All [a] (-> (List a) (Sequence a))) (list/fold add - (: (Vector ($ +0)) + (: (Sequence ($ +0)) empty) list)))} (case tokens diff --git a/stdlib/source/lux/data/coll/vector.lux b/stdlib/source/lux/data/coll/sequence.lux index 956850a87..f85558c5e 100644 --- a/stdlib/source/lux/data/coll/vector.lux +++ b/stdlib/source/lux/data/coll/sequence.lux @@ -17,9 +17,6 @@ ["s" syntax #+ syntax: Syntax]) )) -## This implementation of vectors is based on Clojure's -## PersistentVector implementation. - ## [Utils] (type: (Node a) (#Base (Array a)) @@ -176,7 +173,7 @@ #;Nil)))) ## [Types] -(type: #export (Vector a) +(type: #export (Sequence a) {#level Level #size Nat #root (Hierarchy a) @@ -184,18 +181,18 @@ ## [Exports] (def: #export empty - Vector + Sequence {#level (level-up root-level) #size +0 #root (array;new full-node-size) #tail (array;new +0)}) -(def: #export (size vector) - (All [a] (-> (Vector a) Nat)) - (get@ #size vector)) +(def: #export (size sequence) + (All [a] (-> (Sequence a) Nat)) + (get@ #size sequence)) (def: #export (add val vec) - (All [a] (-> a (Vector a) (Vector a))) + (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)) @@ -219,14 +216,14 @@ ## 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 Vector and grow a new + ## Finally, update the size of the Sequence and grow a new ## tail with the new element as it's sole member. (update@ #size n.inc) (set@ #tail (new-tail val))) ))) (def: (base-for idx vec) - (All [a] (-> Index (Vector a) (Maybe (Base a)))) + (All [a] (-> Index (Sequence a) (Maybe (Base a)))) (let [vec-size (get@ #size vec)] (if (and (n.>= +0 idx) (n.< vec-size idx)) @@ -246,17 +243,17 @@ #;None _ - (error! "Incorrect vector structure.")))) + (error! "Incorrect sequence structure.")))) #;None))) (def: #export (nth idx vec) - (All [a] (-> Nat (Vector a) (Maybe a))) + (All [a] (-> Nat (Sequence a) (Maybe a))) (do maybe;Monad<Maybe> [base (base-for idx vec)] (array;read (branch-idx idx) base))) (def: #export (put idx val vec) - (All [a] (-> Nat a (Vector a) (Vector a))) + (All [a] (-> Nat a (Sequence a) (Sequence a))) (let [vec-size (get@ #size vec)] (if (and (n.>= +0 idx) (n.< vec-size idx)) @@ -269,7 +266,7 @@ vec))) (def: #export (update idx f vec) - (All [a] (-> Nat (-> a a) (Vector a) (Vector a))) + (All [a] (-> Nat (-> a a) (Sequence a) (Sequence a))) (case (nth idx vec) (#;Some val) (put idx (f val) vec) @@ -278,7 +275,7 @@ vec)) (def: #export (pop vec) - (All [a] (-> (Vector a) (Vector a))) + (All [a] (-> (Sequence a) (Sequence a))) (case (get@ #size vec) +0 empty @@ -322,29 +319,29 @@ )) (def: #export (to-list vec) - (All [a] (-> (Vector a) (List a))) + (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) (Vector a))) + (All [a] (-> (List a) (Sequence a))) (list/fold add - (: (Vector ($ +0)) + (: (Sequence ($ +0)) empty) list)) (def: #export (member? a/Eq vec val) - (All [a] (-> (Eq a) (Vector a) a Bool)) + (All [a] (-> (Eq a) (Sequence a) a Bool)) (list;member? a/Eq (to-list vec) val)) (def: #export empty? - (All [a] (-> (Vector a) Bool)) + (All [a] (-> (Sequence a) Bool)) (|>. (get@ #size) (n.= +0))) ## [Syntax] -(syntax: #export (vector [elems (p;some s;any)]) - {#;doc (doc "Vector literals." - (vector 10 20 30 40))} +(syntax: #export (sequence [elems (p;some s;any)]) + {#;doc (doc "Sequence literals." + (sequence 10 20 30 40))} (wrap (list (` (from-list (list (~@ elems))))))) ## [Structures] @@ -358,7 +355,7 @@ (:: (array;Eq<Array> (Eq<Node> Eq<a>)) = h1 h2) ))) -(struct: #export (Eq<Vector> Eq<a>) (All [a] (-> (Eq a) (Eq (Vector a)))) +(struct: #export (Eq<Sequence> Eq<a>) (All [a] (-> (Eq a) (Eq (Sequence a)))) (def: (= v1 v2) (and (n.= (get@ #size v1) (get@ #size v2)) (let [(^open "Node/") (Eq<Node> Eq<a>)] @@ -379,7 +376,7 @@ hierarchy)) )) -(struct: #export _ (Fold Vector) +(struct: #export _ (Fold Sequence) (def: (fold f init xs) (let [(^open) Fold<Node>] (fold f @@ -389,8 +386,8 @@ (#Base (get@ #tail xs)))) )) -(struct: #export Monoid<Vector> (All [a] - (Monoid (Vector a))) +(struct: #export Monoid<Sequence> (All [a] + (Monoid (Sequence a))) (def: identity empty) (def: (compose xs ys) (list/fold add xs (to-list ys)))) @@ -405,7 +402,7 @@ (#Hierarchy (array/map (map f) hierarchy))) )) -(struct: #export _ (Functor Vector) +(struct: #export _ (Functor Sequence) (def: (map f xs) {#level (get@ #level xs) #size (get@ #size xs) @@ -413,32 +410,32 @@ #tail (|> xs (get@ #tail) (array/map f)) })) -(struct: #export _ (Applicative Vector) - (def: functor Functor<Vector>) +(struct: #export _ (Applicative Sequence) + (def: functor Functor<Sequence>) (def: (wrap x) - (vector x)) + (sequence x)) (def: (apply ff fa) - (let [(^open) Functor<Vector> - (^open) Fold<Vector> - (^open) Monoid<Vector> + (let [(^open) Functor<Sequence> + (^open) Fold<Sequence> + (^open) Monoid<Sequence> results (map (function [f] (map f fa)) ff)] (fold compose identity results))) ) -(struct: #export _ (Monad Vector) - (def: applicative Applicative<Vector>) +(struct: #export _ (Monad Sequence) + (def: applicative Applicative<Sequence>) (def: join - (let [(^open) Fold<Vector> - (^open) Monoid<Vector>] + (let [(^open) Fold<Sequence> + (^open) Monoid<Sequence>] (fold (function [post pre] (compose pre post)) identity))) ) (def: #export (reverse xs) - (All [a] (-> (Vector a) (Vector a))) - (let [(^open) Fold<Vector> - (^open) Monoid<Vector>] + (All [a] (-> (Sequence a) (Sequence a))) + (let [(^open) Fold<Sequence> + (^open) Monoid<Sequence>] (fold add identity xs))) diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 7eac167e1..e00783c0b 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<List> Monad<List>] - [vector #+ Vector vector "vector/" Monad<Vector>] + [sequence #+ Sequence sequence "sequence/" Monad<Sequence>] [dict #+ Dict])) [macro #+ Monad<Lux> with-gensyms] (macro ["s" syntax #+ syntax:] @@ -38,13 +38,13 @@ (#Boolean Boolean) (#Number Number) (#String String) - (#Array (Vector JSON)) + (#Array (Sequence JSON)) (#Object (Dict String JSON))) (do-template [<name> <type>] [(type: #export <name> <type>)] - [Array (Vector JSON)] + [Array (Sequence JSON)] [Object (Dict String JSON)] ) @@ -75,7 +75,7 @@ (wrap (list (` (: JSON #Null)))) [_ (#;Tuple members)] - (wrap (list (` (: JSON (#Array (vector (~@ (list/map wrapper members)))))))) + (wrap (list (` (: JSON (#Array (sequence (~@ (list/map wrapper members)))))))) [_ (#;Record pairs)] (do Monad<Lux> @@ -164,16 +164,16 @@ [#String text;Eq<Text>]) [(#Array xs) (#Array ys)] - (and (n.= (vector;size xs) (vector;size ys)) + (and (n.= (sequence;size xs) (sequence;size ys)) (list/fold (function [idx prev] (and prev (maybe;default false (do maybe;Monad<Maybe> - [x' (vector;nth idx xs) - y' (vector;nth idx ys)] + [x' (sequence;nth idx xs) + y' (sequence;nth idx ys)] (wrap (= x' y')))))) true - (list;indices (vector;size xs)))) + (list;indices (sequence;size xs)))) [(#Object xs) (#Object ys)] (and (n.= (dict;size xs) (dict;size ys)) @@ -288,7 +288,7 @@ [head any] (case head (#Array values) - (case (p;run (vector;to-list values) parser) + (case (p;run (sequence;to-list values) parser) (#E;Error error) (fail error) @@ -367,7 +367,7 @@ (def: (show-array show-json elems) (-> (-> JSON Text) (-> Array Text)) ($_ text/compose "[" - (|> elems (vector/map show-json) vector;to-list (text;join-with ",")) + (|> elems (sequence/map show-json) sequence;to-list (text;join-with ",")) "]")) (def: (show-object show-json object) @@ -490,7 +490,7 @@ _ (l;this <close>)] (wrap (<prep> elems))))] - [array~ Array "[" "]" (json~ []) vector;from-list] + [array~ Array "[" "]" (json~ []) sequence;from-list] [object~ Object "{" "}" (kv~ json~) (dict;from-list text;Hash<Text>)] ) diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index d5e9a7837..c4ee39c4b 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -1295,8 +1295,8 @@ []) ) - "The vector corresponds to parent interfaces." - "An optional super-class can be specified before the vector. If not specified, java.lang.Object will be assumed." + "The tuple corresponds to parent interfaces." + "An optional super-class can be specified before the tuple. If not specified, java.lang.Object will be assumed." "Fields and methods defined in the class can be used with special syntax." "For example:" ".resolved, for accessing the \"resolved\" field." @@ -1352,9 +1352,9 @@ [constructor-args (constructor-args^ imports class-vars)] [methods (p;some (overriden-method-def^ imports))]) {#;doc (doc "Allows defining anonymous classes." - "The 1st vector corresponds to parent interfaces." - "The 2nd vector corresponds to arguments to the super class constructor." - "An optional super-class can be specified before the 1st vector. If not specified, java.lang.Object will be assumed." + "The 1st tuple corresponds to parent interfaces." + "The 2nd tuple corresponds to arguments to the super class constructor." + "An optional super-class can be specified before the 1st tuple. If not specified, java.lang.Object will be assumed." (object [Runnable] [] (Runnable [] (run) void diff --git a/stdlib/source/lux/macro/poly/eq.lux b/stdlib/source/lux/macro/poly/eq.lux index 13af05adc..4c376d742 100644 --- a/stdlib/source/lux/macro/poly/eq.lux +++ b/stdlib/source/lux/macro/poly/eq.lux @@ -6,7 +6,7 @@ (data [text "text/" Monoid<Text>] text/format (coll [list "list/" Monad<List>] - [vector] + [sequence] [array] [queue] [set] @@ -62,13 +62,13 @@ (wrap (` (: (~ (@Eq inputT)) (<eq> (~ argC))))))] - [;Maybe maybe;Eq<Maybe>] - [;List list;Eq<List>] - [vector;Vector vector;Eq<Vector>] - [;Array array;Eq<Array>] - [queue;Queue queue;Eq<Queue>] - [set;Set set;Eq<Set>] - [rose;Tree rose;Eq<Tree>] + [;Maybe maybe;Eq<Maybe>] + [;List list;Eq<List>] + [sequence;Sequence sequence;Eq<Sequence>] + [;Array array;Eq<Array>] + [queue;Queue queue;Eq<Queue>] + [set;Set set;Eq<Set>] + [rose;Tree rose;Eq<Tree>] )] (do @ [#let [g!_ (code;local-symbol "\u0000_")] diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux index 1b66e39f5..ab0dab936 100644 --- a/stdlib/source/lux/macro/poly/json.lux +++ b/stdlib/source/lux/macro/poly/json.lux @@ -14,7 +14,7 @@ [sum] [product] (coll [list "list/" Fold<List> Monad<List>] - [vector #+ Vector vector "vector/" Monad<Vector>] + [sequence #+ Sequence sequence "sequence/" Monad<Sequence>] ["d" dict]) (format [".." json #+ JSON])) (time ["i" instant] @@ -50,8 +50,8 @@ (def: (encode input) (let [high (|> input (bit;and high-mask) (bit;shift-right +32)) low (bit;and low-mask input)] - (#..;Array (vector (|> high nat-to-int int-to-frac #..;Number) - (|> low nat-to-int int-to-frac #..;Number))))) + (#..;Array (sequence (|> high nat-to-int int-to-frac #..;Number) + (|> low nat-to-int int-to-frac #..;Number))))) (def: (decode input) (<| (..;run input) (do p;Monad<Parser> @@ -143,7 +143,7 @@ (poly;this ;List) Codec<JSON,?>//encode))] (wrap (` (: (~ (@JSON//encode inputT)) - (|>. (;;_map_ (~ .sub.)) vector;from-list #..;Array))))) + (|>. (;;_map_ (~ .sub.)) sequence;from-list #..;Array))))) (do @ [#let [g!input (code;local-symbol "\u0000input")] members (poly;variant (p;many Codec<JSON,?>//encode))] diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index 00852b46d..138f9723e 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -17,7 +17,7 @@ [queue #+ Queue] [set #+ Set] [stack #+ Stack] - [vector #+ Vector])) + [sequence #+ Sequence])) )) (type: #export #rec PRNG @@ -189,8 +189,8 @@ (wrap (<plus> x xs))) (:: Monad<Random> wrap <zero>)))] - [list List (;list) #;Cons] - [vector Vector vector;empty vector;add] + [list List (;list) #;Cons] + [sequence Sequence sequence;empty sequence;add] ) (do-template [<name> <type> <ctor>] @@ -272,21 +272,21 @@ )) (def: (swap from to vec) - (All [a] (-> Nat Nat (Vector a) (Vector a))) + (All [a] (-> Nat Nat (Sequence a) (Sequence a))) (|> vec - (vector;put to (maybe;assume (vector;nth from vec))) - (vector;put from (maybe;assume (vector;nth to vec))))) + (sequence;put to (maybe;assume (sequence;nth from vec))) + (sequence;put from (maybe;assume (sequence;nth to vec))))) -(def: #export (shuffle seed vector) - {#;doc "Shuffle a vector randomly based on a seed value."} - (All [a] (-> Nat (Vector a) (Vector a))) - (let [_size (vector;size vector) +(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) _shuffle (monad;fold Monad<Random> (function [idx vec] (do Monad<Random> [rand nat] (wrap (swap idx (n.% _size rand) vec)))) - vector + sequence (list;n.range +0 (n.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 b513ef07c..3f2dc7255 100644 --- a/stdlib/source/lux/time/date.lux +++ b/stdlib/source/lux/time/date.lux @@ -11,7 +11,7 @@ [number "int/" Codec<Text,Int>] [text "text/" Monoid<Text>] (text ["l" lexer]) - (coll ["v" vector])))) + (coll [sequence #+ Sequence sequence])))) (type: #export Year Int) @@ -252,15 +252,15 @@ (i.+ (i./ 400 year)))) (def: normal-months - (v;Vector Nat) - (v;vector +31 +28 +31 + (Sequence Nat) + (sequence +31 +28 +31 +30 +31 +30 +31 +31 +30 +31 +30 +31)) (def: leap-year-months - (v;Vector Nat) - (v;update [+1] n.inc normal-months)) + (Sequence Nat) + (sequence;update [+1] n.inc normal-months)) (def: (divisible? factor input) (-> Int Int Bool) @@ -286,7 +286,7 @@ leap-year-months normal-months) month-days (|> months - (v;nth (int-to-nat (i.dec utc-month))) + (sequence;nth (int-to-nat (i.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 31da7dc29..d04b7c845 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<List> Functor<List>] - ["v" vector "v/" Functor<Vector> Fold<Vector>])) + [sequence #+ Sequence sequence "sequence/" Functor<Sequence> Fold<Sequence>])) (type opaque)) (.. [duration "duration/" Order<Duration>] [date])) @@ -102,33 +102,33 @@ )))) (def: normal-months - (v;Vector Nat) - (v;vector +31 +28 +31 + (Sequence Nat) + (sequence +31 +28 +31 +30 +31 +30 +31 +31 +30 +31 +30 +31)) (def: leap-year-months - (v;Vector Nat) - (v;update [+1] n.inc normal-months)) + (Sequence Nat) + (sequence;update [+1] n.inc normal-months)) (def: (find-month months time) - (-> (v;Vector Nat) duration;Duration [Nat duration;Duration]) + (-> (Sequence Nat) duration;Duration [Nat duration;Duration]) (if (duration/>= duration;empty time) - (v/fold (function [month-days [current-month time-left]] - (let [month-duration (duration;scale (nat-to-int month-days) duration;day)] - (if (i.= 0 (duration;query month-duration time-left)) - [current-month time-left] - [(n.inc current-month) (duration;merge (duration;scale -1 month-duration) time-left)]))) - [+0 time] - months) - (v/fold (function [month-days [current-month time-left]] - (let [month-duration (duration;scale (nat-to-int month-days) duration;day)] - (if (i.= 0 (duration;query month-duration time-left)) - [current-month time-left] - [(n.dec current-month) (duration;merge month-duration time-left)]))) - [+11 time] - (v;reverse months)))) + (sequence/fold (function [month-days [current-month time-left]] + (let [month-duration (duration;scale (nat-to-int month-days) duration;day)] + (if (i.= 0 (duration;query month-duration time-left)) + [current-month time-left] + [(n.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 (nat-to-int month-days) duration;day)] + (if (i.= 0 (duration;query month-duration time-left)) + [current-month time-left] + [(n.dec current-month) (duration;merge month-duration time-left)]))) + [+11 time] + (sequence;reverse months)))) (def: (pad value) (-> Int Text) @@ -252,7 +252,7 @@ leap-year-months normal-months) month-days (|> months - (v;nth (int-to-nat (i.dec utc-month))) + (sequence;nth (int-to-nat (i.dec utc-month))) maybe;assume)] _ (l;this "-") utc-day lex-section @@ -282,7 +282,7 @@ year-days-so-far (|> (i.* 365 years-since-epoch) (i.+ previous-leap-days)) month-days-so-far (|> months - v;to-list + sequence;to-list (list;take (int-to-nat (i.dec utc-month))) (L/fold n.+ +0)) total-days (|> year-days-so-far diff --git a/stdlib/test/test/lux/data/coll/vector.lux b/stdlib/test/test/lux/data/coll/sequence.lux index 23fe64464..596805d51 100644 --- a/stdlib/test/test/lux/data/coll/vector.lux +++ b/stdlib/test/test/lux/data/coll/sequence.lux @@ -2,7 +2,7 @@ lux (lux [io] (control [monad #+ do Monad]) - (data (coll ["&" vector] + (data (coll ["&" sequence] [list "List/" Fold<List> Functor<List>]) [text "Text/" Monoid<Text>] text/format @@ -11,35 +11,35 @@ ["r" math/random]) lux/test) -(context: "Vectors" +(context: "Sequences" [size (|> r;nat (:: @ map (|>. (n.% +100) (n.max +1)))) idx (|> r;nat (:: @ map (n.% size))) - sample (r;vector size r;nat) - other-sample (r;vector size r;nat) + sample (r;sequence size r;nat) + other-sample (r;sequence size r;nat) non-member (|> r;nat (r;filter (. not (&;member? number;Eq<Nat> sample)))) - #let [(^open "&/") (&;Eq<Vector> number;Eq<Nat>) - (^open "&/") &;Monad<Vector> - (^open "&/") &;Fold<Vector> - (^open "&/") &;Monoid<Vector>]] + #let [(^open "&/") (&;Eq<Sequence> number;Eq<Nat>) + (^open "&/") &;Monad<Sequence> + (^open "&/") &;Fold<Sequence> + (^open "&/") &;Monoid<Sequence>]] ($_ seq - (test "Can query size of vector." + (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 vectors." + (test "Can add and remove elements to sequences." (and (n.= (n.inc size) (&;size (&;add non-member sample))) (n.= (n.dec size) (&;size (&;pop sample))))) - (test "Can put and get elements into vectors." + (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 vectors." + (test "Can update elements of sequences." (|> sample (&;put idx non-member) (&;update idx n.inc) (&;nth idx) maybe;assume @@ -48,11 +48,11 @@ (test "Can safely transform to/from lists." (|> sample &;to-list &;from-list (&/= sample))) - (test "Can identify members of a vector." + (test "Can identify members of a sequence." (and (not (&;member? number;Eq<Nat> sample non-member)) (&;member? number;Eq<Nat> (&;add non-member sample) non-member))) - (test "Can fold over elements of vector." + (test "Can fold over elements of sequence." (n.= (List/fold n.+ +0 (&;to-list sample)) (&/fold n.+ +0 sample))) @@ -62,11 +62,11 @@ (and (not (&/= sample there)) (&/= sample back-again)))) - (test "Applicative allows you to create singleton vectors, and apply vectors of functions to vectors of values." - (and (&/= (&;vector non-member) (&/wrap non-member)) + (test "Applicative allows you to create singleton sequences, and apply sequences of functions to sequences of values." + (and (&/= (&;sequence non-member) (&/wrap non-member)) (&/= (&/map n.inc sample) (&/apply (&/wrap n.inc) sample)))) - (test "Vector concatenation is a monad." + (test "Sequence concatenation is a monad." (&/= (&/compose sample other-sample) - (&/join (&;vector 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 89244d6fe..67e636d36 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 "i/" Number<Int>] (format ["@" json]) - (coll [vector #+ vector] + (coll [sequence #+ sequence] ["d" dict] [list])) [macro #+ with-gensyms] @@ -43,7 +43,7 @@ r;bool (|> r;frac (:: @ map (f.* 1_000_000.0))) (r;text size) - (r;vector size gen-json) + (r;sequence size gen-json) (r;dict text;Hash<Text> size (r;text size) gen-json) ))))) diff --git a/stdlib/test/test/lux/math/random.lux b/stdlib/test/test/lux/math/random.lux index 003a3a803..c98f75c20 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] - [vector] + [sequence] [array] [queue] [stack] @@ -17,7 +17,7 @@ (context: "Random." [size (|> r;nat (:: @ map (|>. (n.% +100) (n.max +10)))) _list (r;list size r;nat) - _vector (r;vector size r;nat) + _sequence (r;sequence size r;nat) _array (r;array size r;nat) _queue (r;queue size r;nat) _stack (r;stack size r;nat) @@ -26,14 +26,14 @@ top r;nat filtered (|> r;nat (r;filter (n.<= top))) shuffle-seed r;nat - #let [sorted (|> _vector vector;to-list (list;sort n.<)) - shuffled (|> sorted vector;from-list (r;shuffle shuffle-seed)) - re-sorted (|> shuffled vector;to-list (list;sort n.<))]] + #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.<))]] ($_ seq (test "Can produce lists." (n.= size (list;size _list))) - (test "Can produce vectors." - (n.= size (vector;size _vector))) + (test "Can produce sequences." + (n.= size (sequence;size _sequence))) (test "Can produce arrays." (n.= size (array;size _array))) (test "Can produce queues." @@ -46,9 +46,9 @@ (n.= size (dict;size _dict))) (test "Can filter values." (n.<= top filtered)) - (test "Can shuffle vectors." - (let [(^open "v/") (vector;Eq<Vector> number;Eq<Nat>) - sorted (vector;from-list sorted)] + (test "Can shuffle sequences." + (let [(^open "v/") (sequence;Eq<Sequence> number;Eq<Nat>) + sorted (sequence;from-list sorted)] (and (not (v/= sorted shuffled)) - (v/= sorted (vector;from-list re-sorted))))) + (v/= sorted (sequence;from-list re-sorted))))) )) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index b7f097fa2..8d20ef379 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -48,7 +48,7 @@ ["_;" queue] ["_;" set] ["_;" stack] - ["_;" vector] + ["_;" sequence] ["_;" priority-queue] ["_;" stream] (tree ["tree_;" rose] |