From 67e230c71466ca595b913b7d2581c367010f1110 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Wed, 31 May 2023 11:51:43 -0400 Subject: [PATCH] Actually save work --- TODO.xit | 10 +++++----- src/ludus/grammar.clj | 2 +- src/ludus/interpreter.clj | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/TODO.xit b/TODO.xit index 15c3284..114eed8 100644 --- a/TODO.xit +++ b/TODO.xit @@ -2,11 +2,11 @@ [x] Fix recursive definition problems in grammar.clj TODOS from interpreter -[ ] implement tuple splat patterns -[ ] update match-list to use new AST representation -[ ] fix length comparison when pattern includes splats -[ ] update match-dict to use new AST representation -[ ] update match-struct to use new AST representation +[x] implement tuple splat patterns +[x] update match-list to use new AST representation +[x] fix length comparison when pattern includes splats +[x] update match-dict to use new AST representation +[x] update match-struct to use new AST representation [ ] update interpret-receive to use new AST representation [ ] Check interpret-fn-inner ctx for cycles/bugs diff --git a/src/ludus/grammar.clj b/src/ludus/grammar.clj index 97634e8..644c71d 100644 --- a/src/ludus/grammar.clj +++ b/src/ludus/grammar.clj @@ -49,7 +49,7 @@ (defp typed group weak-order [:word (quiet :as) :keyword]) -(defp dict-pattern-term flat choice [pair-pattern :word typed splattern]) +(defp dict-pattern-term flat choice [pair-pattern typed :word splattern]) (defp dict-pattern-entry weak-order [dict-pattern-term separators]) diff --git a/src/ludus/interpreter.clj b/src/ludus/interpreter.clj index 4009070..0ff06d1 100644 --- a/src/ludus/interpreter.clj +++ b/src/ludus/interpreter.clj @@ -193,7 +193,7 @@ splat-data (-> splat :data first) splat-type (-> splat-data :type)] (if (= :word splat-type) - (let [unmatched (assoc (apply dissoc dict kws) ::data/dict true) + (let [unmatched (apply dissoc dict kws) match? (match splat-data unmatched ctx-diff)] (if (:success match?) {:success true :ctx (merge @ctx-diff (:ctx match?))} @@ -216,7 +216,7 @@ (not (map? dict)) {:success false :reason "Could not match non-struct value to struct pattern"} - (not (::data/dict dict)) + (not (::data/struct dict)) {:success false :reason "Cannot match non-struct value to struct pattern"} (empty? members) @@ -249,7 +249,7 @@ splat-data (-> splat :data first) splat-type (-> splat-data :type)] (if (= :word splat-type) - (let [unmatched (assoc (apply dissoc dict kws) ::data/dict true) + (let [unmatched (assoc (apply dissoc dict ::data/struct kws) ::data/dict true) match? (match splat-data unmatched ctx-diff)] (if (:success match?) {:success true :ctx (merge @ctx-diff (:ctx match?))} @@ -961,7 +961,7 @@ (do (def source " - let #{...x} = #{:a 1} + let @{...x} = @{:a 1, :b 2, :c 3} x ")