From babfed1bb763ab189cf743f514d3014265a55516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Wed, 23 Sep 2026 11:03:23 -0600 Subject: [PATCH] --- src/expand.clj | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/expand.clj b/src/expand.clj index 6f07e4c..7ca9946 100644 --- a/src/expand.clj +++ b/src/expand.clj @@ -7,6 +7,13 @@ [spec-dict.main :refer [dict]] [scm])) +(defmacro inherit [& syms] + (let [f (if (<= 8 (count syms)) + `hash-map + `array-map)] + `(~f ~@(mapcat #(list (keyword %) %) + syms)))) + (s/def ::scope symbol?) (s/def ::binding @@ -143,8 +150,7 @@ store-atom {:x [:var]} (fn [ident* env*] - (tap> {:ident* ident* - :env* env*}) + (tap> (inherit ident* env*)) (list (scm/datum->syntax 'x ident*)))))) @@ -182,16 +188,11 @@ (fn [_datum prim-name _env _store-atom] prim-name)) -#_ (defmethod expand-primitive 'lambda [stx _ env symtable-ref] - (let [{:keys [formals body]} (->> stx - scm/syntax-e - (s/conform ::prim-lambda))] - (concat (list 'lambda - (throw (Exception. "todo2"))) - (for [e body] - (expand e env* symtable-ref))))) + (let [{:keys [formals body]} (s/conform ::prim-lambda stx)] + (tap> (inherit formals body)) + (throw (Exception. "todo2")))) (defn expand [stx env store-atom] (match (scm/syntax-e stx) @@ -210,3 +211,12 @@ (map #(expand % env store-atom) xs))))) (defn expand-library [lib]) + +(comment + (let [env {[:global 'lambda] [:primitive 'lambda]} + store-atom (atom {['lambda #{}] [:global 'lambda]})] + (expand #scm/stx [(#scm/stx [lambda #{}] + #scm/stx [(#scm/stx [x #{}]) #{}] + #scm/stx [x #{}]) + #{}] + env store-atom)))