diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/collection/dictionary.lux | 314 |
1 files changed, 157 insertions, 157 deletions
diff --git a/stdlib/source/lux/data/collection/dictionary.lux b/stdlib/source/lux/data/collection/dictionary.lux index 8ca61b453..46f299e31 100644 --- a/stdlib/source/lux/data/collection/dictionary.lux +++ b/stdlib/source/lux/data/collection/dictionary.lux @@ -39,7 +39,7 @@ Nat) ## A hash-code derived from a key during tree-traversal. -(type: Hash-Code +(type: Hash_Code Nat) ## Represents the nesting level of a leaf or node, when looking-it-up @@ -47,8 +47,8 @@ ## Changes in levels are done by right-shifting the hashes of keys by ## the appropriate multiple of the branching-exponent. ## A shift of 0 means root level. -## A shift of (* branching-exponent 1) means level 2. -## A shift of (* branching-exponent N) means level N+1. +## A shift of (* branching_exponent 1) means level 2. +## A shift of (* branching_exponent N) means level N+1. (type: Level Nat) @@ -59,7 +59,7 @@ (#Base BitMap (Array (Either (Node k v) [k v]))) - (#Collisions Hash-Code (Array [k v]))) + (#Collisions Hash_Code (Array [k v]))) ## #Hierarchy nodes are meant to point down only to lower-level nodes. (type: (Hierarchy k v) @@ -81,7 +81,7 @@ ## Which is the same as 0000 0000 0000 0000 0000 0000 0000 0000. ## Or 0x00000000. ## Which is 32 zeroes, since the branching factor is 32. -(def: clean-bitmap +(def: clean_bitmap BitMap 0) @@ -94,47 +94,47 @@ ## factor). ## The initial shifting level, though, is 0 (which corresponds to the ## shift in the shallowest node on the tree, which is the root node). -(def: root-level +(def: root_level Level 0) ## The exponent to which 2 must be elevated, to reach the branching ## factor of the data-structure. -(def: branching-exponent +(def: branching_exponent Nat 5) ## The threshold on which #Hierarchy nodes are demoted to #Base nodes, ## which is 1/4 of the branching factor (or a left-shift 2). -(def: demotion-threshold +(def: demotion_threshold Nat - (i64.left-shift (n.- 2 branching-exponent) 1)) + (i64.left_shift (n.- 2 branching_exponent) 1)) ## The threshold on which #Base nodes are promoted to #Hierarchy nodes, ## which is 1/2 of the branching factor (or a left-shift 1). -(def: promotion-threshold +(def: promotion_threshold Nat - (i64.left-shift (n.- 1 branching-exponent) 1)) + (i64.left_shift (n.- 1 branching_exponent) 1)) ## The size of hierarchy-nodes, which is 2^(branching-exponent). -(def: hierarchy-nodes-size +(def: hierarchy_nodes_size Nat - (i64.left-shift branching-exponent 1)) + (i64.left_shift branching_exponent 1)) ## The cannonical empty node, which is just an empty #Base node. (def: empty Node - (#Base clean-bitmap (array.new 0))) + (#Base clean_bitmap (array.new 0))) ## Expands a copy of the array, to have 1 extra slot, which is used ## for storing the value. -(def: (insert! idx value old-array) +(def: (insert! idx value old_array) (All [a] (-> Index a (Array a) (Array a))) - (let [old-size (array.size old-array)] - (|> (array.new (inc old-size)) - (array.copy! idx 0 old-array 0) + (let [old_size (array.size old_array)] + (|> (array.new (inc old_size)) + (array.copy! idx 0 old_array 0) (array.write! idx value) - (array.copy! (n.- idx old-size) idx old-array (inc idx))))) + (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) @@ -149,74 +149,74 @@ ## Shrinks a copy of the array by removing the space at index. (def: (remove! idx array) (All [a] (-> Index (Array a) (Array a))) - (let [new-size (dec (array.size array))] - (|> (array.new new-size) + (let [new_size (dec (array.size array))] + (|> (array.new new_size) (array.copy! idx 0 array 0) - (array.copy! (n.- idx new-size) (inc idx) array idx)))) + (array.copy! (n.- idx new_size) (inc idx) array idx)))) ## Increases the level-shift by the branching-exponent, to explore ## levels further down the tree. -(def: level-up +(def: level_up (-> Level Level) - (n.+ branching-exponent)) + (n.+ branching_exponent)) -(def: hierarchy-mask BitMap (dec hierarchy-nodes-size)) +(def: hierarchy_mask BitMap (dec hierarchy_nodes_size)) ## Gets the branching-factor sized section of the hash corresponding ## to a particular level, and uses that as an index into the array. -(def: (level-index level hash) - (-> Level Hash-Code Index) - (i64.and hierarchy-mask - (i64.logic-right-shift level hash))) +(def: (level_index level hash) + (-> Level Hash_Code Index) + (i64.and hierarchy_mask + (i64.logic_right_shift level hash))) ## A mechanism to go from indices to bit-positions. -(def: (->bit-position index) +(def: (->bit_position index) (-> Index BitPosition) - (i64.left-shift index 1)) + (i64.left_shift index 1)) ## The bit-position within a base that a given hash-code would have. -(def: (bit-position level hash) - (-> Level Hash-Code BitPosition) - (->bit-position (level-index level hash))) +(def: (bit_position level hash) + (-> Level Hash_Code BitPosition) + (->bit_position (level_index level hash))) -(def: (bit-position-is-set? bit bitmap) +(def: (bit_position_is_set? bit bitmap) (-> BitPosition BitMap Bit) - (not (n.= clean-bitmap (i64.and bit bitmap)))) + (not (n.= clean_bitmap (i64.and bit bitmap)))) ## Figures out whether a bitmap only contains a single bit-position. -(def: only-bit-position? +(def: only_bit_position? (-> BitPosition BitMap Bit) n.=) -(def: (set-bit-position bit bitmap) +(def: (set_bit_position bit bitmap) (-> BitPosition BitMap BitMap) (i64.or bit bitmap)) -(def: unset-bit-position +(def: unset_bit_position (-> BitPosition BitMap BitMap) i64.xor) ## Figures out the size of a bitmap-indexed array by counting all the ## 1s within the bitmap. -(def: bitmap-size +(def: bitmap_size (-> BitMap Nat) i64.count) ## A mask that, for a given bit position, only allows all the 1s prior ## to it, which would indicate the bitmap-size (and, thus, index) ## associated with it. -(def: bit-position-mask +(def: bit_position_mask (-> BitPosition BitMap) dec) ## The index on the base array, based on it's bit-position. -(def: (base-index bit-position bitmap) +(def: (base_index bit_position bitmap) (-> BitPosition BitMap Index) - (bitmap-size (i64.and (bit-position-mask bit-position) + (bitmap_size (i64.and (bit_position_mask bit_position) bitmap))) ## Produces the index of a KV-pair within a #Collisions node. -(def: (collision-index Hash<k> key colls) +(def: (collision_index Hash<k> key colls) (All [k v] (-> (Hash k) k (Collisions k v) (Maybe Index))) (\ maybe.monad map product.left (array.find+ (function (_ idx [key' val']) @@ -225,51 +225,51 @@ ## When #Hierarchy nodes grow too small, they're demoted to #Base ## nodes to save space. -(def: (demote-hierarchy except-idx [h-size h-array]) +(def: (demote_hierarchy except_idx [h_size h_array]) (All [k v] (-> Index (Hierarchy k v) [BitMap (Base k v)])) - (product.right (list\fold (function (_ idx [insertion-idx node]) + (product.right (list\fold (function (_ idx [insertion_idx node]) (let [[bitmap base] node] - (case (array.read idx h-array) - #.None [insertion-idx node] - (#.Some sub-node) (if (n.= except-idx idx) - [insertion-idx node] - [(inc insertion-idx) - [(set-bit-position (->bit-position idx) bitmap) - (array.write! insertion-idx (#.Left sub-node) base)]]) + (case (array.read idx h_array) + #.None [insertion_idx node] + (#.Some sub_node) (if (n.= except_idx idx) + [insertion_idx node] + [(inc insertion_idx) + [(set_bit_position (->bit_position idx) bitmap) + (array.write! insertion_idx (#.Left sub_node) base)]]) ))) - [0 [clean-bitmap - (array.new (dec h-size))]] - (list.indices (array.size h-array))))) + [0 [clean_bitmap + (array.new (dec h_size))]] + (list.indices (array.size h_array))))) ## When #Base nodes grow too large, they're promoted to #Hierarchy to ## add some depth to the tree and help keep it's balance. -(def: hierarchy-indices (List Index) (list.indices hierarchy-nodes-size)) +(def: hierarchy_indices (List Index) (list.indices hierarchy_nodes_size)) -(def: (promote-base put' Hash<k> level bitmap base) +(def: (promote_base put' Hash<k> level bitmap base) (All [k v] - (-> (-> Level Hash-Code k v (Hash k) (Node k v) (Node k v)) + (-> (-> Level Hash_Code k v (Hash k) (Node k v) (Node k v)) (Hash k) Level BitMap (Base k v) (Array (Node k v)))) - (product.right (list\fold (function (_ hierarchy-idx (^@ default [base-idx h-array])) - (if (bit-position-is-set? (->bit-position hierarchy-idx) + (product.right (list\fold (function (_ hierarchy_idx (^@ default [base_idx h_array])) + (if (bit_position_is_set? (->bit_position hierarchy_idx) bitmap) - [(inc base-idx) - (case (array.read base-idx base) - (#.Some (#.Left sub-node)) - (array.write! hierarchy-idx sub-node h-array) + [(inc base_idx) + (case (array.read base_idx base) + (#.Some (#.Left sub_node)) + (array.write! hierarchy_idx sub_node h_array) (#.Some (#.Right [key' val'])) - (array.write! hierarchy-idx - (put' (level-up level) (\ Hash<k> hash key') key' val' Hash<k> empty) - h-array) + (array.write! hierarchy_idx + (put' (level_up level) (\ Hash<k> hash key') key' val' Hash<k> empty) + h_array) #.None (undefined))] default)) [0 - (array.new hierarchy-nodes-size)] - hierarchy-indices))) + (array.new hierarchy_nodes_size)] + hierarchy_indices))) ## All empty nodes look the same (a #Base node with clean bitmap is ## used). @@ -277,44 +277,44 @@ (def: (empty?' node) (All [k v] (-> (Node k v) Bit)) (`` (case node - (#Base (~~ (static ..clean-bitmap)) _) + (#Base (~~ (static ..clean_bitmap)) _) #1 _ #0))) (def: (put' level hash key val Hash<k> node) - (All [k v] (-> Level Hash-Code k v (Hash k) (Node k v) (Node k v))) + (All [k v] (-> Level Hash_Code k v (Hash k) (Node k v) (Node k v))) (case node ## For #Hierarchy nodes, I check whether I can add the element to ## a sub-node. If impossible, I introduced a new singleton sub-node. (#Hierarchy _size hierarchy) - (let [idx (level-index level hash) - [_size' sub-node] (case (array.read idx hierarchy) - (#.Some sub-node) - [_size sub-node] + (let [idx (level_index level hash) + [_size' sub_node] (case (array.read idx hierarchy) + (#.Some sub_node) + [_size sub_node] _ [(inc _size) empty])] (#Hierarchy _size' - (update! idx (put' (level-up level) hash key val Hash<k> sub-node) + (update! idx (put' (level_up level) hash key val Hash<k> sub_node) hierarchy))) ## For #Base nodes, I check if the corresponding BitPosition has ## already been used. (#Base bitmap base) - (let [bit (bit-position level hash)] - (if (bit-position-is-set? bit bitmap) + (let [bit (bit_position level hash)] + (if (bit_position_is_set? bit bitmap) ## If so... - (let [idx (base-index bit bitmap)] + (let [idx (base_index bit bitmap)] (case (array.read idx base) #.None (undefined) ## If it's being used by a node, I add the KV to it. - (#.Some (#.Left sub-node)) - (let [sub-node' (put' (level-up level) hash key val Hash<k> sub-node)] - (#Base bitmap (update! idx (#.Left sub-node') base))) + (#.Some (#.Left sub_node)) + (let [sub_node' (put' (level_up level) hash key val Hash<k> sub_node)] + (#Base bitmap (update! idx (#.Left sub_node') base))) ## Otherwise, if it's being used by a KV, I compare the keys. (#.Some (#.Right key' val')) @@ -337,117 +337,117 @@ ## #Base nodes, so I ## add both KV-pairs ## to the empty one. - (let [next-level (level-up level)] + (let [next_level (level_up level)] (|> empty - (put' next-level hash' key' val' Hash<k>) - (put' next-level hash key val Hash<k>)))))) + (put' next_level hash' key' val' Hash<k>) + (put' next_level hash key val Hash<k>)))))) base))))) ## However, if the BitPosition has not been used yet, I check ## whether this #Base node is ready for a promotion. - (let [base-count (bitmap-size bitmap)] - (if (n.>= ..promotion-threshold base-count) + (let [base_count (bitmap_size bitmap)] + (if (n.>= ..promotion_threshold base_count) ## If so, I promote it to a #Hierarchy node, and add the new ## KV-pair as a singleton node to it. - (#Hierarchy (inc base-count) - (|> (promote-base put' Hash<k> level bitmap base) - (array.write! (level-index level hash) - (put' (level-up level) hash key val Hash<k> empty)))) + (#Hierarchy (inc base_count) + (|> (promote_base put' Hash<k> level bitmap base) + (array.write! (level_index level hash) + (put' (level_up level) hash key val Hash<k> empty)))) ## Otherwise, I just resize the #Base node to accommodate the ## new KV-pair. - (#Base (set-bit-position bit bitmap) - (insert! (base-index bit bitmap) (#.Right [key val]) base)))))) + (#Base (set_bit_position bit bitmap) + (insert! (base_index bit bitmap) (#.Right [key val]) base)))))) ## For #Collisions nodes, I compare the hashes. (#Collisions _hash _colls) (if (n.= hash _hash) ## If they're equal, that means the new KV contributes to the ## collisions. - (case (collision-index Hash<k> key _colls) + (case (collision_index Hash<k> key _colls) ## If the key was already present in the collisions-list, it's ## value gets updated. - (#.Some coll-idx) - (#Collisions _hash (update! coll-idx [key val] _colls)) + (#.Some coll_idx) + (#Collisions _hash (update! coll_idx [key val] _colls)) ## Otherwise, the KV-pair is added to the collisions-list. #.None (#Collisions _hash (insert! (array.size _colls) [key val] _colls))) ## If the hashes are not equal, I create a new #Base node that ## contains the old #Collisions node, plus the new KV-pair. - (|> (#Base (bit-position level _hash) + (|> (#Base (bit_position level _hash) (|> (array.new 1) (array.write! 0 (#.Left node)))) (put' level hash key val Hash<k>))) )) (def: (remove' level hash key Hash<k> node) - (All [k v] (-> Level Hash-Code k (Hash k) (Node k v) (Node k v))) + (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 ## the Hash-Code. - (#Hierarchy h-size h-array) - (let [idx (level-index level hash)] - (case (array.read idx h-array) + (#Hierarchy h_size h_array) + (let [idx (level_index level hash)] + (case (array.read idx h_array) ## If not, there's nothing to remove. #.None node ## 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 Hash<k> sub-node)] + (#.Some sub_node) + (let [sub_node' (remove' (level_up level) hash key Hash<k> sub_node)] ## Then check if a removal was actually done. - (if (is? sub-node sub-node') + (if (is? sub_node sub_node') ## If not, then there's nothing to change here either. node - ## But if the sub-removal yielded an empty sub-node... - (if (empty?' sub-node') + ## But if the sub_removal yielded an empty sub_node... + (if (empty?' sub_node') ## Check if it's due time for a demotion. - (if (n.<= demotion-threshold h-size) + (if (n.<= demotion_threshold h_size) ## If so, perform it. - (#Base (demote-hierarchy idx [h-size h-array])) + (#Base (demote_hierarchy idx [h_size h_array])) ## Otherwise, just clear the space. - (#Hierarchy (dec h-size) (vacant! idx h-array))) - ## But if the sub-removal yielded a non-empty node, then + (#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 (update! idx sub_node' h_array))))))) ## For #Base nodes, check whether the BitPosition is set. (#Base bitmap base) - (let [bit (bit-position level hash)] - (if (bit-position-is-set? bit bitmap) - (let [idx (base-index bit bitmap)] + (let [bit (bit_position level hash)] + (if (bit_position_is_set? bit bitmap) + (let [idx (base_index bit bitmap)] (case (array.read idx base) #.None (undefined) - ## If set, check if it's a sub-node, and remove the KV + ## 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 Hash<k> sub-node)] + (#.Some (#.Left sub_node)) + (let [sub_node' (remove' (level_up level) hash key Hash<k> sub_node)] ## Verify that it was removed. - (if (is? sub-node sub-node') + (if (is? sub_node sub_node') ## If not, there's also nothing to change here. node ## But if it came out empty... - (if (empty?' sub-node') + (if (empty?' sub_node') ### ... figure out whether that's the only position left. - (if (only-bit-position? bit bitmap) + (if (only_bit_position? bit bitmap) ## If so, removing it leaves this node empty too. empty ## But if not, then just unset the position and ## remove the node. - (#Base (unset-bit-position bit bitmap) + (#Base (unset_bit_position bit bitmap) (remove! 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))))) + (update! idx (#.Left sub_node') base))))) ## If, however, there was a KV-pair instead of a sub-node. (#.Some (#.Right [key' val'])) ## Check if the keys match. (if (\ Hash<k> = key key') ## If so, remove the KV-pair and unset the BitPosition. - (#Base (unset-bit-position bit bitmap) + (#Base (unset_bit_position bit bitmap) (remove! idx base)) ## Otherwise, there's nothing to remove. node))) @@ -456,7 +456,7 @@ ## For #Collisions nodes, It need to find out if the key already existst. (#Collisions _hash _colls) - (case (collision-index Hash<k> key _colls) + (case (collision_index Hash<k> key _colls) ## If not, then there's nothing to remove. #.None node @@ -472,24 +472,24 @@ )) (def: (get' level hash key Hash<k> node) - (All [k v] (-> Level Hash-Code k (Hash k) (Node k v) (Maybe v))) + (All [k v] (-> Level Hash_Code k (Hash k) (Node k v) (Maybe v))) (case node ## For #Hierarchy nodes, just look-up the key on its children. (#Hierarchy _size hierarchy) - (case (array.read (level-index level hash) hierarchy) + (case (array.read (level_index level hash) hierarchy) #.None #.None - (#.Some sub-node) (get' (level-up level) hash key Hash<k> sub-node)) + (#.Some sub_node) (get' (level_up level) hash key Hash<k> sub_node)) ## For #Base nodes, check the leaves, and recursively check the branches. (#Base bitmap base) - (let [bit (bit-position level hash)] - (if (bit-position-is-set? bit bitmap) - (case (array.read (base-index bit bitmap) base) + (let [bit (bit_position level hash)] + (if (bit_position_is_set? bit bitmap) + (case (array.read (base_index bit bitmap) base) #.None (undefined) - (#.Some (#.Left sub-node)) - (get' (level-up level) hash key Hash<k> sub-node) + (#.Some (#.Left sub_node)) + (get' (level_up level) hash key Hash<k> sub_node) (#.Some (#.Right [key' val'])) (if (\ Hash<k> = key key') @@ -511,9 +511,9 @@ (array\fold n.+ 0 (array\map size' hierarchy)) (#Base _ base) - (array\fold n.+ 0 (array\map (function (_ sub-node') - (case sub-node' - (#.Left sub-node) (size' sub-node) + (array\fold n.+ 0 (array\map (function (_ sub_node') + (case sub_node' + (#.Left sub_node) (size' sub_node) (#.Right _) 1)) base)) @@ -525,15 +525,15 @@ (All [k v] (-> (Node k v) (List [k v]))) (case node (#Hierarchy _size hierarchy) - (array\fold (function (_ sub-node tail) (list\compose (entries' sub-node) tail)) + (array\fold (function (_ sub_node tail) (list\compose (entries' sub_node) tail)) #.Nil hierarchy) (#Base bitmap base) (array\fold (function (_ branch tail) (case branch - (#.Left sub-node) - (list\compose (entries' sub-node) tail) + (#.Left sub_node) + (list\compose (entries' sub_node) tail) (#.Right [key' val']) (#.Cons [key' val'] tail))) @@ -550,7 +550,7 @@ {#hash (Hash k) #root (Node k v)}) -(def: #export key-hash +(def: #export key_hash (All [k v] (-> (Dictionary k v) (Hash k))) (get@ #..hash)) @@ -562,17 +562,17 @@ (def: #export (put key val dict) (All [k v] (-> k v (Dictionary k v) (Dictionary k v))) (let [[Hash<k> node] dict] - [Hash<k> (put' root-level (\ Hash<k> hash key) key val Hash<k> node)])) + [Hash<k> (put' root_level (\ Hash<k> hash key) key val Hash<k> node)])) (def: #export (remove key dict) (All [k v] (-> k (Dictionary k v) (Dictionary k v))) (let [[Hash<k> node] dict] - [Hash<k> (remove' root-level (\ Hash<k> hash key) key Hash<k> node)])) + [Hash<k> (remove' root_level (\ Hash<k> hash key) key Hash<k> node)])) (def: #export (get key dict) (All [k v] (-> k (Dictionary k v) (Maybe v))) (let [[Hash<k> node] dict] - (get' root-level (\ Hash<k> hash key) key Hash<k> node))) + (get' root_level (\ Hash<k> hash key) key Hash<k> node))) (def: #export (key? dict key) (All [k v] (-> (Dictionary k v) k Bit)) @@ -580,14 +580,14 @@ #.None #0 (#.Some _) #1)) -(exception: #export key-already-exists) +(exception: #export key_already_exists) -(def: #export (try-put key val dict) +(def: #export (try_put key val dict) {#.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)) - (#.Some _) (exception.throw ..key-already-exists []))) + (#.Some _) (exception.throw ..key_already_exists []))) (def: #export (update key f dict) {#.doc "Transforms the value located at key (if available), using the given function."} @@ -620,16 +620,16 @@ (All [k v] (-> (Dictionary k v) (List [k v]))) (entries' (product.right dict))) -(def: #export (from-list Hash<k> kvs) +(def: #export (from_list Hash<k> kvs) (All [k v] (-> (Hash k) (List [k v]) (Dictionary k v))) (list\fold (function (_ [k v] dict) (put k v dict)) (new Hash<k>) kvs)) -(template [<name> <elem-type> <side>] +(template [<name> <elem_type> <side>] [(def: #export (<name> dict) - (All [k v] (-> (Dictionary k v) (List <elem-type>))) + (All [k v] (-> (Dictionary k v) (List <elem_type>))) (|> dict entries (list\map <side>)))] [keys k product.left] @@ -644,7 +644,7 @@ dict1 (entries dict2))) -(def: #export (merge-with f dict2 dict1) +(def: #export (merge_with f dict2 dict1) {#.doc (doc "Merges 2 dictionaries." "If any collisions with keys occur, a new value will be computed by applying 'f' to the values of dict2 and dict1.")} (All [k v] (-> (-> v v v) (Dictionary k v) (Dictionary k v) (Dictionary k v))) @@ -658,25 +658,25 @@ dict1 (entries dict2))) -(def: #export (re-bind from-key to-key dict) +(def: #export (re_bind from_key to_key dict) (All [k v] (-> k k (Dictionary k v) (Dictionary k v))) - (case (get from-key dict) + (case (get from_key dict) #.None dict (#.Some val) (|> dict - (remove from-key) - (put to-key val)))) + (remove from_key) + (put to_key val)))) (def: #export (select keys dict) {#.doc "Creates a sub-set of the given dict, with only the specified keys."} (All [k v] (-> (List k) (Dictionary k v) (Dictionary k v))) (let [[Hash<k> _] dict] - (list\fold (function (_ key new-dict) + (list\fold (function (_ key new_dict) (case (get key dict) - #.None new-dict - (#.Some val) (put key val new-dict))) + #.None new_dict + (#.Some val) (put key val new_dict))) (new Hash<k>) keys))) |