fix: value-semantics for collection keys/elements; set literals evaluate
Close jolt-do7. Maps/sets keyed by a collection (a map, vector, ...) now compare
by value instead of Janet identity:
- PHM/PHS hash and compare keys through an injected canonicalizer (collection
keys -> value-hashable struct/tuple); keys are still stored as-is
- map literals and core-assoc promote to a phm when a key is a collection
- frequencies/group-by use a phm base so collection elements/keys dedup by value
- set equality is value-based (from earlier)
Real bugs found and fixed along the way:
- set literals #{(inc 1)} did not evaluate their elements (stored raw forms!)
- the REPL printer rendered phm maps as {} (they hit the deftype branch); now a
phm branch prints entries
Added spec cases (maps/collection-keys, sets/literals & value elements).
conformance 218/218, jpm test green.
This commit is contained in:
parent
ad5539b0de
commit
0db7eb6ac8
6 changed files with 102 additions and 17 deletions
|
|
@ -54,3 +54,11 @@
|
|||
["count of nil map" "0" "(count nil)"]
|
||||
["get from nil" "nil" "(get nil :a)"]
|
||||
["immutability" "true" "(let [m {:a 1} n (assoc m :b 2)] (and (= m {:a 1}) (= n {:a 1 :b 2})))"])
|
||||
|
||||
(defspec "map / collection keys (by value)"
|
||||
["vector key literal" ":v" "(get {[1 2] :v} [1 2])"]
|
||||
["map key literal" ":v" "(get {(hash-map :a 1) :v} {:a 1})"]
|
||||
["assoc vector key" ":v" "(get (assoc {} [1 2] :v) [1 2])"]
|
||||
["key across repr" ":v" "(get (assoc {} (vec [1 2]) :v) [1 2])"]
|
||||
["frequencies of maps" "2" "(get (frequencies [{:a 1} (hash-map :a 1)]) {:a 1})"]
|
||||
["group-by collection key" "1" "(count (group-by identity [{:a 1} (hash-map :a 1)]))"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue