diff options
Diffstat (limited to '')
10 files changed, 95 insertions, 95 deletions
diff --git a/stdlib/source/library/lux/data/collection/dictionary.lux b/stdlib/source/library/lux/data/collection/dictionary.lux index e86eb437b..3d0e729ce 100644 --- a/stdlib/source/library/lux/data/collection/dictionary.lux +++ b/stdlib/source/library/lux/data/collection/dictionary.lux @@ -139,7 +139,7 @@ (array.copy! (n.- idx old_size) idx old_array (inc idx))))) ... Creates a copy of an array with an index set to a particular value. -(def: (update! idx value array) +(def: (revised! idx value array) (All [a] (-> Index a (Array a) (Array a))) (|> array array.clone (array.write! idx value))) @@ -149,7 +149,7 @@ (|> array array.clone (array.delete! idx))) ... Shrinks a copy of the array by removing the space at index. -(def: (remove! idx array) +(def: (lacks! idx array) (All [a] (-> Index (Array a) (Array a))) (let [new_size (dec (array.size array))] (|> (array.empty new_size) @@ -254,7 +254,7 @@ (List Index) (list.indices hierarchy_nodes_size)) -(def: (promotion put' key_hash level bitmap base) +(def: (promotion has' key_hash level bitmap base) (All [k v] (-> (-> Level Hash_Code k v (Hash k) (Node k v) (Node k v)) (Hash k) Level @@ -270,7 +270,7 @@ (#.Some (#.Right [key' val'])) (array.write! hierarchy_idx - (put' (level_up level) (\ key_hash hash key') key' val' key_hash empty_node) + (has' (level_up level) (\ key_hash hash key') key' val' key_hash empty_node) h_array) #.None @@ -292,7 +292,7 @@ _ #0))) -(def: (put' level hash key val key_hash node) +(def: (has' level hash key val key_hash node) (All [k v] (-> Level Hash_Code k v (Hash k) (Node k v) (Node k v))) (case node ... For #Hierarchy nodes, check whether one can add the element to @@ -306,8 +306,8 @@ _ [(inc _size) empty_node])] (#Hierarchy _size' - (update! idx (put' (level_up level) hash key val key_hash sub_node) - hierarchy))) + (revised! idx (has' (level_up level) hash key val key_hash sub_node) + hierarchy))) ... For #Base nodes, check if the corresponding Bit_Position has ... already been used. @@ -319,35 +319,35 @@ (case (array.read idx base) ... If it's being used by a node, add the KV to it. (#.Some (#.Left sub_node)) - (let [sub_node' (put' (level_up level) hash key val key_hash sub_node)] - (#Base bitmap (update! idx (#.Left sub_node') base))) + (let [sub_node' (has' (level_up level) hash key val key_hash sub_node)] + (#Base bitmap (revised! idx (#.Left sub_node') base))) ... Otherwise, if it's being used by a KV, compare the keys. (#.Some (#.Right key' val')) (if (\ key_hash = key key') ... If the same key is found, replace the value. - (#Base bitmap (update! idx (#.Right key val) base)) + (#Base bitmap (revised! idx (#.Right key val) base)) ... Otherwise, compare the hashes of the keys. - (#Base bitmap (update! idx - (#.Left (let [hash' (\ key_hash hash key')] - (if (n.= hash hash') - ... If the hashes are - ... the same, a new - ... #Collisions node - ... is added. - (#Collisions hash (|> (array.empty 2) - (array.write! 0 [key' val']) - (array.write! 1 [key val]))) - ... Otherwise, one can - ... just keep using - ... #Base nodes, so - ... add both KV-pairs - ... to the empty one. - (let [next_level (level_up level)] - (|> empty_node - (put' next_level hash' key' val' key_hash) - (put' next_level hash key val key_hash)))))) - base))) + (#Base bitmap (revised! idx + (#.Left (let [hash' (\ key_hash hash key')] + (if (n.= hash hash') + ... If the hashes are + ... the same, a new + ... #Collisions node + ... is added. + (#Collisions hash (|> (array.empty 2) + (array.write! 0 [key' val']) + (array.write! 1 [key val]))) + ... Otherwise, one can + ... just keep using + ... #Base nodes, so + ... add both KV-pairs + ... to the empty one. + (let [next_level (level_up level)] + (|> empty_node + (has' next_level hash' key' val' key_hash) + (has' next_level hash key val key_hash)))))) + base))) #.None (undefined))) @@ -359,9 +359,9 @@ ... KV-pair as a singleton node to it. (#Hierarchy (inc base_count) (|> base - (promotion put' key_hash level bitmap) + (promotion has' key_hash level bitmap) (array.write! (level_index level hash) - (put' (level_up level) hash key val key_hash empty_node)))) + (has' (level_up level) hash key val key_hash empty_node)))) ... Otherwise, just resize the #Base node to accommodate the ... new KV-pair. (#Base (with_bit_position bit bitmap) @@ -376,7 +376,7 @@ ... If the key was already present in the collisions-list, its ... value gets updated. (#.Some coll_idx) - (#Collisions _hash (update! coll_idx [key val] _colls)) + (#Collisions _hash (revised! coll_idx [key val] _colls)) ... Otherwise, the KV-pair is added to the collisions-list. #.None @@ -386,10 +386,10 @@ (|> (#Base (level_bit_position level _hash) (|> (array.empty 1) (array.write! 0 (#.Left node)))) - (put' level hash key val key_hash))) + (has' level hash key val key_hash))) )) -(def: (remove' level hash key key_hash node) +(def: (lacks' level hash key key_hash node) (All [k v] (-> Level Hash_Code k (Hash k) (Node k v) (Node k v))) (case node ... For #Hierarchy nodes, find out if there's a valid sub-node for @@ -403,7 +403,7 @@ ... But if there is, try to remove the key from the sub-node. (#.Some sub_node) - (let [sub_node' (remove' (level_up level) hash key key_hash sub_node)] + (let [sub_node' (lacks' (level_up level) hash key key_hash sub_node)] ... Then check if a removal was actually done. (if (is? sub_node sub_node') ... If not, then there's nothing to change here either. @@ -418,7 +418,7 @@ (#Hierarchy (dec h_size) (vacant! idx h_array))) ... But if the sub_removal yielded a non_empty node, then ... just update the hiearchy branch. - (#Hierarchy h_size (update! idx sub_node' h_array))))))) + (#Hierarchy h_size (revised! idx sub_node' h_array))))))) ... For #Base nodes, check whether the Bit_Position is set. (#Base bitmap base) @@ -429,7 +429,7 @@ ... If set, check if it's a sub_node, and remove the KV ... from it. (#.Some (#.Left sub_node)) - (let [sub_node' (remove' (level_up level) hash key key_hash sub_node)] + (let [sub_node' (lacks' (level_up level) hash key key_hash sub_node)] ... Verify that it was removed. (if (is? sub_node sub_node') ... If not, there's also nothing to change here. @@ -443,11 +443,11 @@ ... But if not, then just unset the position and ... remove the node. (#Base (without_bit_position bit bitmap) - (remove! idx base))) + (lacks! idx base))) ... But, if it did not come out empty, then the ... position is kept, and the node gets updated. (#Base bitmap - (update! idx (#.Left sub_node') base))))) + (revised! idx (#.Left sub_node') base))))) ... If, however, there was a KV-pair instead of a sub-node. (#.Some (#.Right [key' val'])) @@ -455,7 +455,7 @@ (if (\ key_hash = key key') ... If so, remove the KV-pair and unset the Bit_Position. (#Base (without_bit_position bit bitmap) - (remove! idx base)) + (lacks! idx base)) ... Otherwise, there's nothing to remove. node) @@ -478,7 +478,7 @@ ... an empty node. empty_node ... Otherwise, just shrink the array by removing the KV-pair. - (#Collisions _hash (remove! idx _colls)))) + (#Collisions _hash (lacks! idx _colls)))) )) (def: (get' level hash key key_hash node) @@ -570,15 +570,15 @@ {#hash key_hash #root empty_node}) -(def: .public (put key val dict) +(def: .public (has key val dict) (All [k v] (-> k v (Dictionary k v) (Dictionary k v))) (let [[key_hash node] dict] - [key_hash (put' root_level (\ key_hash hash key) key val key_hash node)])) + [key_hash (has' root_level (\ key_hash hash key) key val key_hash node)])) -(def: .public (remove key dict) +(def: .public (lacks key dict) (All [k v] (-> k (Dictionary k v) (Dictionary k v))) (let [[key_hash node] dict] - [key_hash (remove' root_level (\ key_hash hash key) key key_hash node)])) + [key_hash (lacks' root_level (\ key_hash hash key) key key_hash node)])) (def: .public (get key dict) (All [k v] (-> k (Dictionary k v) (Maybe v))) @@ -597,10 +597,10 @@ {#.doc "Only puts the KV-pair if the key is not already present."} (All [k v] (-> k v (Dictionary k v) (Try (Dictionary k v)))) (case (get key dict) - #.None (#try.Success (put key val dict)) + #.None (#try.Success (has key val dict)) (#.Some _) (exception.except ..key_already_exists []))) -(def: .public (update key f dict) +(def: .public (revised key f dict) {#.doc "Transforms the value located at key (if available), using the given function."} (All [k v] (-> k (-> v v) (Dictionary k v) (Dictionary k v))) (case (get key dict) @@ -608,13 +608,13 @@ dict (#.Some val) - (put key (f val) dict))) + (has key (f val) dict))) (def: .public (upsert key default f dict) {#.doc (example "Updates the value at the key; if it exists." "Otherwise, puts a value by applying the function to a default.")} (All [k v] (-> k v (-> v v) (Dictionary k v) (Dictionary k v))) - (..put key + (..has key (f (maybe.else default (..get key dict))) dict)) @@ -634,7 +634,7 @@ (def: .public (of_list key_hash kvs) (All [k v] (-> (Hash k) (List [k v]) (Dictionary k v))) (list\fold (function (_ [k v] dict) - (..put k v dict)) + (..has k v dict)) (empty key_hash) kvs)) @@ -654,7 +654,7 @@ {#.doc (example "Merges 2 dictionaries." "If any collisions with keys occur, the values of dict2 will overwrite those of dict1.")} (All [k v] (-> (Dictionary k v) (Dictionary k v) (Dictionary k v))) - (list\fold (function (_ [key val] dict) (put key val dict)) + (list\fold (function (_ [key val] dict) (has key val dict)) dict1 (entries dict2))) @@ -665,10 +665,10 @@ (list\fold (function (_ [key val2] dict) (case (get key dict) #.None - (put key val2 dict) + (has key val2 dict) (#.Some val1) - (put key (f val2 val1) dict))) + (has key (f val2 val1) dict))) dict1 (entries dict2))) @@ -681,8 +681,8 @@ (#.Some val) (|> dict - (remove from_key) - (put to_key val)))) + (lacks from_key) + (has to_key val)))) (def: .public (sub keys dict) {#.doc "A sub-dictionary, with only the specified keys."} @@ -691,7 +691,7 @@ (list\fold (function (_ key new_dict) (case (get key dict) #.None new_dict - (#.Some val) (put key val new_dict))) + (#.Some val) (has key val new_dict))) (empty key_hash) keys))) diff --git a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux index 6d343f573..d4516f8d1 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux @@ -250,7 +250,7 @@ #Black <default_behavior>)))) -(def: .public (put key value dict) +(def: .public (has key value dict) (All [k v] (-> k v (Dictionary k v) (Dictionary k v))) (let [(^open "_\.") (get@ #&order dict) root' (loop [?root (get@ #root dict)] @@ -473,7 +473,7 @@ _ (undefined))) -(def: .public (remove key dict) +(def: .public (lacks key dict) (All [k v] (-> k (Dictionary k v) (Dictionary k v))) (let [(^open "_\.") (get@ #&order dict) [?root found?] (loop [?root (get@ #root dict)] @@ -528,11 +528,11 @@ (set@ #root (#.Some (blackened root)) dict) ))) -(def: .public (update key transform dict) +(def: .public (revised key transform dict) (All [k v] (-> k (-> v v) (Dictionary k v) (Dictionary k v))) (case (..get key dict) (#.Some old) - (..put key (transform old) dict) + (..has key (transform old) dict) #.None dict)) @@ -540,7 +540,7 @@ (def: .public (of_list order list) (All [k v] (-> (Order k) (List [k v]) (Dictionary k v))) (list\fold (function (_ [key value] dict) - (put key value dict)) + (has key value dict)) (empty order) list)) diff --git a/stdlib/source/library/lux/data/collection/dictionary/plist.lux b/stdlib/source/library/lux/data/collection/dictionary/plist.lux index a251109f4..88ea21f79 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/plist.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/plist.lux @@ -59,7 +59,7 @@ #.None false)) -(def: .public (put key val properties) +(def: .public (has key val properties) (All [a] (-> Text a (PList a) (PList a))) (case properties #.End @@ -70,9 +70,9 @@ (#.Item [key val] properties') (#.Item [k' v'] - (put key val properties'))))) + (has key val properties'))))) -(def: .public (update key f properties) +(def: .public (revised key f properties) (All [a] (-> Text (-> a a) (PList a) (PList a))) (case properties #.End @@ -81,9 +81,9 @@ (#.Item [k' v'] properties') (if (text\= key k') (#.Item [k' (f v')] properties') - (#.Item [k' v'] (update key f properties'))))) + (#.Item [k' v'] (revised key f properties'))))) -(def: .public (remove key properties) +(def: .public (lacks key properties) (All [a] (-> Text (PList a) (PList a))) (case properties #.End @@ -93,7 +93,7 @@ (if (text\= key k') properties' (#.Item [k' v'] - (remove key properties'))))) + (lacks key properties'))))) (def: .public equivalence (All [a] (-> (Equivalence a) (Equivalence (PList a)))) diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index fc57c691a..6174f1ea6 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -583,7 +583,7 @@ (#.Some (#.Item x tail))) )) -(def: .public concat +(def: .public joined {#.doc (example "The sequential combination of all the lists.")} (All [a] (-> (List (List a)) (List a))) (\ ..monad join)) @@ -604,7 +604,7 @@ (: ((:parameter 0) (List (List (:parameter 1)))) (monad.seq ! lMla))} (monad.seq ! lMla))] - (in (concat lla))))) + (in (..joined lla))))) (def: .public (lift monad) {#.doc (example "Wraps a monadic value with List machinery.")} diff --git a/stdlib/source/library/lux/data/collection/row.lux b/stdlib/source/library/lux/data/collection/row.lux index 2a6a1020d..c36a5377e 100644 --- a/stdlib/source/library/lux/data/collection/row.lux +++ b/stdlib/source/library/lux/data/collection/row.lux @@ -293,7 +293,7 @@ row))) (exception.except ..index_out_of_bounds [row idx])))) -(def: .public (update idx f row) +(def: .public (revised idx f row) (All [a] (-> Nat (-> a a) (Row a) (Try (Row a)))) (do try.monad [val (..item idx row)] @@ -358,7 +358,7 @@ (All [a] (-> (Row a) Bit)) (|>> (get@ #size) (n.= 0))) -(syntax: .public (row {elems (p.some s.any)}) +(syntax: .public (row [elems (p.some s.any)]) {#.doc (example "Row literals." (row 12 34 56 78 90))} (in (.list (` (..of_list (.list (~+ elems))))))) diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux index f26f57d97..c8049c3b3 100644 --- a/stdlib/source/library/lux/data/collection/sequence.lux +++ b/stdlib/source/library/lux/data/collection/sequence.lux @@ -137,9 +137,9 @@ (let [[head tail] (//.result wa)] (//.pending [wa (split tail)])))) -(syntax: .public (^sequence& {patterns (<code>.form (<>.many <code>.any))} - body - {branches (<>.some <code>.any)}) +(syntax: .public (^sequence& [patterns (<code>.form (<>.many <code>.any)) + body <code>.any + branches (<>.some <code>.any)]) {#.doc (example "Allows destructuring of sequences in pattern-matching expressions." "Caveat emptor: Only use it for destructuring, and not for testing values within the sequences." (let [(^sequence& x y z _tail) (some_sequence_func +1 +2 +3)] diff --git a/stdlib/source/library/lux/data/collection/set.lux b/stdlib/source/library/lux/data/collection/set.lux index f3ccdc7fb..bd18afe96 100644 --- a/stdlib/source/library/lux/data/collection/set.lux +++ b/stdlib/source/library/lux/data/collection/set.lux @@ -32,13 +32,13 @@ (All [a] (-> (Set a) Nat)) //.size) -(def: .public (add elem set) +(def: .public (has elem set) (All [a] (-> a (Set a) (Set a))) - (|> set (//.put elem []))) + (|> set (//.has elem []))) -(def: .public remove +(def: .public lacks (All [a] (-> a (Set a) (Set a))) - //.remove) + //.lacks) (def: .public member? (All [a] (-> (Set a) a Bit)) @@ -54,7 +54,7 @@ (def: .public (difference sub base) (All [a] (-> (Set a) (Set a) (Set a))) - (list\fold ..remove base (..list sub))) + (list\fold ..lacks base (..list sub))) (def: .public (intersection filter base) (All [a] (-> (Set a) (Set a) (Set a))) @@ -92,7 +92,7 @@ (def: .public (of_list hash elements) (All [a] (-> (Hash a) (List a) (Set a))) - (list\fold ..add (..empty hash) elements)) + (list\fold ..has (..empty hash) elements)) (def: .public (sub? super sub) (All [a] (-> (Set a) (Set a) Bit)) diff --git a/stdlib/source/library/lux/data/collection/set/multi.lux b/stdlib/source/library/lux/data/collection/set/multi.lux index 4131578c1..8211134e1 100644 --- a/stdlib/source/library/lux/data/collection/set/multi.lux +++ b/stdlib/source/library/lux/data/collection/set/multi.lux @@ -31,7 +31,7 @@ (All [a] (-> (Set a) Nat)) (|>> :representation dictionary.values (list\fold n.+ 0))) - (def: .public (add multiplicity elem set) + (def: .public (has multiplicity elem set) (All [a] (-> Nat a (Set a) (Set a))) (case multiplicity 0 set @@ -40,7 +40,7 @@ (dictionary.upsert elem 0 (n.+ multiplicity)) :abstraction))) - (def: .public (remove multiplicity elem set) + (def: .public (lacks multiplicity elem set) (All [a] (-> Nat a (Set a) (Set a))) (case multiplicity 0 set @@ -48,8 +48,8 @@ (#.Some current) (:abstraction (if (n.> multiplicity current) - (dictionary.update elem (n.- multiplicity) (:representation set)) - (dictionary.remove elem (:representation set)))) + (dictionary.revised elem (n.- multiplicity) (:representation set)) + (dictionary.lacks elem (:representation set)))) #.None set))) @@ -78,7 +78,7 @@ (def: .public (intersection parameter (^:representation subject)) (All [a] (-> (Set a) (Set a) (Set a))) (list\fold (function (_ [elem multiplicity] output) - (..add (n.min (..multiplicity parameter elem) + (..has (n.min (..multiplicity parameter elem) multiplicity) elem output)) @@ -91,7 +91,7 @@ :representation dictionary.entries (list\fold (function (_ [elem multiplicity] output) - (..remove multiplicity elem output)) + (..lacks multiplicity elem output)) subject))) (def: .public (sub? reference subject) @@ -149,7 +149,7 @@ (def: .public (of_list hash subject) (All [a] (-> (Hash a) (List a) (Set a))) - (list\fold (..add 1) (..empty hash) subject)) + (list\fold (..has 1) (..empty hash) subject)) (def: .public (of_set subject) (All [a] (-> (//.Set a) (Set a))) diff --git a/stdlib/source/library/lux/data/collection/set/ordered.lux b/stdlib/source/library/lux/data/collection/set/ordered.lux index e69dba5fe..6ef570c31 100644 --- a/stdlib/source/library/lux/data/collection/set/ordered.lux +++ b/stdlib/source/library/lux/data/collection/set/ordered.lux @@ -36,13 +36,13 @@ [Bit empty? /.empty?] ) - (def: .public (add elem set) + (def: .public (has elem set) (All [a] (-> a (Set a) (Set a))) - (|> set :representation (/.put elem elem) :abstraction)) + (|> set :representation (/.has elem elem) :abstraction)) - (def: .public (remove elem set) + (def: .public (lacks elem set) (All [a] (-> a (Set a) (Set a))) - (|> set :representation (/.remove elem) :abstraction)) + (|> set :representation (/.lacks elem) :abstraction)) (def: .public list (All [a] (-> (Set a) (List a))) @@ -50,11 +50,11 @@ (def: .public (of_list &order list) (All [a] (-> (Order a) (List a) (Set a))) - (list\fold add (..empty &order) list)) + (list\fold has (..empty &order) list)) (def: .public (union left right) (All [a] (-> (Set a) (Set a) (Set a))) - (list\fold ..add right (..list left))) + (list\fold ..has right (..list left))) (def: .public (intersection left right) (All [a] (-> (Set a) (Set a) (Set a))) diff --git a/stdlib/source/library/lux/data/collection/tree.lux b/stdlib/source/library/lux/data/collection/tree.lux index 69043cb63..451fc6143 100644 --- a/stdlib/source/library/lux/data/collection/tree.lux +++ b/stdlib/source/library/lux/data/collection/tree.lux @@ -54,7 +54,7 @@ (<>.else (list)) (<>.and <code>.any))) -(syntax: .public (tree {root tree^}) +(syntax: .public (tree [root tree^]) {#.doc (example "Tree literals." (: (Tree Nat) (tree 12 |