From 46fd3005312405929d71807efee0f14f0ade53bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Fri, 18 Sep 2026 08:54:42 -0600 Subject: [PATCH] --- src/expand.clj | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/expand.clj b/src/expand.clj index 625230b..5726a0f 100644 --- a/src/expand.clj +++ b/src/expand.clj @@ -171,6 +171,38 @@ (swap! symtable-ref #(assoc-in % [sym scopes] bind)) {bind denot})) +(defn symtable [[sym scopes] bind] + {sym {scopes bind}}) + + + +(defn- merge-unify-with + ([f] {}) + ([f a] a) + ([f a b] (and a b (merge-with f a b))) + ([f a b & xs] (reduce #(merge-unify-with f %1 %2) (cons a (cons b xs))))) + +(defn- merge-unify [& xs] + (apply merge-unify-with (fn [_ x] x) xs)) + +(defn- unify* [pattern datum env symtable-ref scopes] + (match [pattern datum] + [[:wildcard _] _] {} + + [[:var x] _] (symtable [x scopes] ))) + +(defn unify + ([pattern datum] + (unify* (s/conform ::pattern pattern) datum + scheme-base-env + (symtable-for-env scheme-base-env) + #{})) + ([pattern datum env symtable-ref scopes] + (unify* (s/conform ::pattern pattern) datum env symtable-ref scopes))) + + +;;; expand + (declare expand) (defmethod expand-primitive 'lambda