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
|
|
@ -23,6 +23,13 @@
|
|||
["set as fn present" "2" "(#{1 2 3} 2)"]
|
||||
["set as fn missing" "nil" "(#{1 2 3} 9)"])
|
||||
|
||||
(defspec "set / literals & value elements"
|
||||
["literal evaluates elements" "#{2 4}" "#{(inc 1) (* 2 2)}"]
|
||||
["map elements by value" "true" "(= #{{:a 1}} #{(hash-map :a 1)})"]
|
||||
["contains? map by value" "true" "(contains? #{(hash-map :x 1)} {:x 1})"]
|
||||
["dedup equal maps" "1" "(count (set [{:a 1} (hash-map :a 1)]))"]
|
||||
["vector elements" "true" "(contains? #{[1 2]} (vec [1 2]))"])
|
||||
|
||||
(defspec "clojure.set"
|
||||
["union" "#{1 2 3 4}" "(do (require (quote [clojure.set :as s])) (s/union #{1 2} #{3 4}))"]
|
||||
["intersection" "#{2}" "(do (require (quote [clojure.set :as s])) (s/intersection #{1 2} #{2 3}))"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue