diff options
author | Eduardo Julian | 2018-07-03 22:20:22 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-03 22:20:22 -0400 |
commit | f505b42847bd7ba54b14d4b593b883c1bb25501d (patch) | |
tree | eb017a0f3db7d4cd7dee260dd5eb437ad74f327a /stdlib/source | |
parent | 371a407a49ddf0f2fe1d977018fcd0a009c86043 (diff) |
- Re-named "sequence" to "row".
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/data/coll/row.lux (renamed from stdlib/source/lux/data/coll/sequence.lux) | 75 | ||||
-rw-r--r-- | stdlib/source/lux/data/format/json.lux | 22 | ||||
-rw-r--r-- | stdlib/source/lux/lang/compiler/translation.lux | 8 | ||||
-rw-r--r-- | stdlib/source/lux/lang/syntax.lux | 18 | ||||
-rw-r--r-- | stdlib/source/lux/macro/poly/equality.lux | 4 | ||||
-rw-r--r-- | stdlib/source/lux/macro/poly/json.lux | 8 | ||||
-rw-r--r-- | stdlib/source/lux/math/random.lux | 20 | ||||
-rw-r--r-- | stdlib/source/lux/time/date.lux | 18 | ||||
-rw-r--r-- | stdlib/source/lux/time/instant.lux | 50 | ||||
-rw-r--r-- | stdlib/source/lux/type/resource.lux | 8 |
10 files changed, 115 insertions, 116 deletions
diff --git a/stdlib/source/lux/data/coll/sequence.lux b/stdlib/source/lux/data/coll/row.lux index 4e6226dcd..0b258a2ec 100644 --- a/stdlib/source/lux/data/coll/sequence.lux +++ b/stdlib/source/lux/data/coll/row.lux @@ -169,7 +169,7 @@ #.Nil)))) ## [Types] -(type: #export (Sequence a) +(type: #export (Row a) {#level Level #size Nat #root (Hierarchy a) @@ -177,18 +177,18 @@ ## [Exports] (def: #export empty - Sequence + Row {#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 (size row) + (All [a] (-> (Row a) Nat)) + (get@ #size row)) (def: #export (add val vec) - (All [a] (-> a (Sequence a) (Sequence a))) + (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)) @@ -214,14 +214,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 Sequence and grow a new + ## 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 (Sequence a) (Maybe (Base a)))) + (All [a] (-> Index (Row a) (Maybe (Base a)))) (let [vec-size (get@ #size vec)] (if (and (n/>= +0 idx) (n/< vec-size idx)) @@ -241,17 +241,17 @@ #.None _ - (error! "Incorrect sequence structure.")))) + (error! "Incorrect row structure.")))) #.None))) (def: #export (nth idx vec) - (All [a] (-> Nat (Sequence a) (Maybe a))) + (All [a] (-> Nat (Row 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 (Sequence a) (Sequence a))) + (All [a] (-> Nat a (Row a) (Row a))) (let [vec-size (get@ #size vec)] (if (and (n/>= +0 idx) (n/< vec-size idx)) @@ -267,7 +267,7 @@ vec))) (def: #export (update idx f vec) - (All [a] (-> Nat (-> a a) (Sequence a) (Sequence a))) + (All [a] (-> Nat (-> a a) (Row a) (Row a))) (case (nth idx vec) (#.Some val) (put idx (f val) vec) @@ -276,7 +276,7 @@ vec)) (def: #export (pop vec) - (All [a] (-> (Sequence a) (Sequence a))) + (All [a] (-> (Row a) (Row a))) (case (get@ #size vec) +0 empty @@ -318,28 +318,28 @@ )) (def: #export (to-list vec) - (All [a] (-> (Sequence a) (List a))) + (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) (Sequence a))) + (All [a] (-> (List a) (Row a))) (list/fold add empty list)) (def: #export (member? a/Eq vec val) - (All [a] (-> (Eq a) (Sequence a) a Bool)) + (All [a] (-> (Eq a) (Row a) a Bool)) (list.member? a/Eq (to-list vec) val)) (def: #export empty? - (All [a] (-> (Sequence a) Bool)) + (All [a] (-> (Row a) Bool)) (|>> (get@ #size) (n/= +0))) ## [Syntax] -(syntax: #export (sequence {elems (p.some s.any)}) - {#.doc (doc "Sequence literals." - (sequence 10 20 30 40))} +(syntax: #export (row {elems (p.some s.any)}) + {#.doc (doc "Row literals." + (row 10 20 30 40))} (wrap (list (` (from-list (list (~+ elems))))))) ## [Structures] @@ -355,7 +355,7 @@ _ false))) -(struct: #export (Eq<Sequence> Eq<a>) (All [a] (-> (Eq a) (Eq (Sequence a)))) +(struct: #export (Eq<Row> Eq<a>) (All [a] (-> (Eq a) (Eq (Row a)))) (def: (= v1 v2) (and (n/= (get@ #size v1) (get@ #size v2)) (let [(^open "Node/") (Eq<Node> Eq<a>)] @@ -376,7 +376,7 @@ hierarchy)) )) -(struct: #export _ (Fold Sequence) +(struct: #export _ (Fold Row) (def: (fold f init xs) (let [(^open) Fold<Node>] (fold f @@ -386,8 +386,7 @@ (#Base (get@ #tail xs)))) )) -(struct: #export Monoid<Sequence> (All [a] - (Monoid (Sequence a))) +(struct: #export Monoid<Row> (All [a] (Monoid (Row a))) (def: identity empty) (def: (compose xs ys) (list/fold add xs (to-list ys)))) @@ -402,7 +401,7 @@ (#Hierarchy (array/map (map f) hierarchy))) )) -(struct: #export _ (Functor Sequence) +(struct: #export _ (Functor Row) (def: (map f xs) {#level (get@ #level xs) #size (get@ #size xs) @@ -410,29 +409,29 @@ #tail (|> xs (get@ #tail) (array/map f)) })) -(struct: #export _ (Apply Sequence) - (def: functor Functor<Sequence>) +(struct: #export _ (Apply Row) + (def: functor Functor<Row>) (def: (apply ff fa) - (let [(^open) Functor<Sequence> - (^open) Fold<Sequence> - (^open) Monoid<Sequence> + (let [(^open) Functor<Row> + (^open) Fold<Row> + (^open) Monoid<Row> results (map (function (_ f) (map f fa)) ff)] (fold compose identity results)))) -(struct: #export _ (Monad Sequence) - (def: functor Functor<Sequence>) +(struct: #export _ (Monad Row) + (def: functor Functor<Row>) - (def: wrap (|>> sequence)) + (def: wrap (|>> row)) (def: join - (let [(^open) Fold<Sequence> - (^open) Monoid<Sequence>] + (let [(^open) Fold<Row> + (^open) Monoid<Row>] (fold (function (_ post pre) (compose pre post)) identity)))) (def: #export (reverse xs) - (All [a] (-> (Sequence a) (Sequence a))) - (let [(^open) Fold<Sequence> - (^open) Monoid<Sequence>] + (All [a] (-> (Row a) (Row a))) + (let [(^open) Fold<Row> + (^open) Monoid<Row>] (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<List> Monad<List>] - [sequence #+ Sequence sequence "sequence/" Monad<Sequence>] + [row #+ Row row "row/" Monad<Row>] (dictionary ["dict" unordered #+ Dict]))) [macro #+ Monad<Meta> 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 [<name> <type>] [(type: #export <name> <type>)] - [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<Meta> @@ -161,16 +161,16 @@ [#String text.Eq<Text>]) [(#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<Maybe> - [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 <close>)] (wrap (<prep> elems))))] - [array~ Array "[" "]" (json~ []) sequence.from-list] + [array~ Array "[" "]" (json~ []) row.from-list] [object~ Object "{" "}" (kv~ json~) (dict.from-list text.Hash<Text>)] ) 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<Parser> [_ (l.this <open>) - [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 <close>)] (wrap [(update@ #.column inc where') - (sequence.to-list elems)]))))] + (row.to-list elems)]))))] (wrap [where' [where (<tag> elems)]])))] @@ -463,19 +463,19 @@ (l.Lexer [Cursor Code])) (do p.Monad<Parser> [_ (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>] text/format (coll [list "list/" Monad<List>] - [sequence] + [row] [array] [queue] (set ["set" unordered]) @@ -62,7 +62,7 @@ [.Maybe maybe.Eq<Maybe>] [.List list.Eq<List>] - [sequence.Sequence sequence.Eq<Sequence>] + [row.Row row.Eq<Row>] [.Array array.Eq<Array>] [queue.Queue queue.Eq<Queue>] [set.Set set.Eq<Set>] 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<List> Monad<List>] - [sequence #+ Sequence sequence "sequence/" Monad<Sequence>] + [row #+ Row row "row/" Monad<Row>] (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<JSON,?>//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<Random> wrap <zero>)))] [list List (.list) #.Cons] - [sequence Sequence sequence.empty sequence.add] + [row Row row.empty row.add] ) (do-template [<name> <type> <ctor>] @@ -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<Random> (function (_ idx vec) (do Monad<Random> [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,Int>] [text "text/" Monoid<Text>] (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<List> Functor<List>] - [sequence #+ Sequence sequence "sequence/" Functor<Sequence> Fold<Sequence>])) + [row #+ Row row "row/" Functor<Row> Fold<Row>])) (type abstract)) (// [duration "duration/" Order<Duration>] [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<List> Fold<List>])) (concurrency [promise #+ Promise]) [macro] @@ -155,11 +155,11 @@ (function (_ from to) (do maybe.Monad<Maybe> [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)] |