From bd9a408e074b8fb15e77e78b4da3d01e20337b79 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Thu, 19 May 2022 19:59:20 -0400 Subject: [PATCH] Add hash patterns; add hashmap data tag & update show --- src/ludus/interpreter.clj | 17 +++++++++++++---- src/ludus/show.clj | 5 ++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ludus/interpreter.clj b/src/ludus/interpreter.clj index 725139a..e71a231 100644 --- a/src/ludus/interpreter.clj +++ b/src/ludus/interpreter.clj @@ -65,6 +65,16 @@ (recur (dec i) (merge ctx (:ctx match?))) {:success false :reason (str "Could not match " pattern " with " value)}))))))) +(defn- match-hashmap [pattern value ctx-vol] + (cond + (not (map? value)) + {:success false :reason "Could not match non-hashmap value to hashmap pattern"} + + (not) + + ) + ) + (defn- match [pattern value ctx-vol] (let [ctx @ctx-vol] (case (::ast/type pattern) @@ -406,7 +416,7 @@ ::ast/hash (let [members (:members ast)] - (into {} (map-values #(interpret-ast % ctx)) members)) + (into {::data/hashmap true} (map-values #(interpret-ast % ctx)) members)) ::ast/struct (let [members (:members ast)] @@ -435,9 +445,7 @@ (def source " - let [1, 2, x] = [1, 2, 3] - x ") @@ -451,7 +459,8 @@ (parser/parse) (interpret-safe) (show/show) - (println))) + ;;(println) + )) (comment " diff --git a/src/ludus/show.clj b/src/ludus/show.clj index 040a903..c8ae5a2 100644 --- a/src/ludus/show.clj +++ b/src/ludus/show.clj @@ -27,8 +27,11 @@ (::data/ref v) ;; TODO: reconsider this (str "ref:" (::data/name v) " <" (deref (::data/value v))">") + (::data/hashmap v) + (str "#{" (apply str (into [] show-keyed (dissoc v ::data/hashmap))) "}") + :else - (str "#{" (apply str (into [] show-keyed v)) "}") + (pp/pprint v) ))