From 6c9e0c922d46aa7ccf6b1ea5e2f07e90c3245240 Mon Sep 17 00:00:00 2001 From: Yogthos Date: Tue, 2 Jun 2026 23:29:58 -0400 Subject: [PATCH] Phase 7 followup: set equality in core-= + phs-to-struct - phm.janet: add phs-to-struct (converts set to struct via phm-to-struct) - core.janet: core-= now handles set? with phs-to-struct normalization - test/phase7-test.janet: add (= #{1 2 3} #{3 2 1}) assertion - 315 ok, 2 fail (pre-existing, unchanged) --- src/jolt/core.janet | 5 ++++- src/jolt/phm.janet | 3 +++ test/phase7-test.janet | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/jolt/core.janet b/src/jolt/core.janet index 9f44e18..90eebf1 100644 --- a/src/jolt/core.janet +++ b/src/jolt/core.janet @@ -87,7 +87,10 @@ (set ok (if (phm? a) (deep= (phm-to-struct a) (if (phm? b) (phm-to-struct b) b)) - (if (phm? b) (deep= a (phm-to-struct b)) (deep= a b))))) + (if (phm? b) (deep= a (phm-to-struct b)) + (if (set? a) + (deep= (phs-to-struct a) (if (set? b) (phs-to-struct b) b)) + (if (set? b) (deep= a (phs-to-struct b)) (deep= a b))))))) (++ i)) ok))) diff --git a/src/jolt/phm.janet b/src/jolt/phm.janet index ee8fca0..13c29f1 100644 --- a/src/jolt/phm.janet +++ b/src/jolt/phm.janet @@ -194,3 +194,6 @@ (defn phs-get [s x &opt default] (default default nil) (if (phm-contains? (s :phm) x) x default)) + +(defn phs-to-struct [s] + (phm-to-struct (s :phm))) diff --git a/test/phase7-test.janet b/test/phase7-test.janet index d715674..ba01edc 100644 --- a/test/phase7-test.janet +++ b/test/phase7-test.janet @@ -19,7 +19,7 @@ (assert (= false (ct-eval ctx "(set? [1 2 3])")) "set? false") (assert (= 4 (ct-eval ctx "(count (conj #{1 2 3} 4))")) "conj add") (assert (= 2 (ct-eval ctx "(count (disj #{1 2 3} 3))")) "disj") - (assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "count")) -(print " passed") + (assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "count") + (assert (= true (ct-eval ctx "(= #{1 2 3} #{3 2 1})")) "= order-independent")) (print "\nAll Phase 7 tests passed!")