Add hash patterns; add hashmap data tag & update show
This commit is contained in:
parent
9984a6c8ec
commit
bd9a408e07
|
@ -65,6 +65,16 @@
|
||||||
(recur (dec i) (merge ctx (:ctx match?)))
|
(recur (dec i) (merge ctx (:ctx match?)))
|
||||||
{:success false :reason (str "Could not match " pattern " with " value)})))))))
|
{: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]
|
(defn- match [pattern value ctx-vol]
|
||||||
(let [ctx @ctx-vol]
|
(let [ctx @ctx-vol]
|
||||||
(case (::ast/type pattern)
|
(case (::ast/type pattern)
|
||||||
|
@ -406,7 +416,7 @@
|
||||||
|
|
||||||
::ast/hash
|
::ast/hash
|
||||||
(let [members (:members ast)]
|
(let [members (:members ast)]
|
||||||
(into {} (map-values #(interpret-ast % ctx)) members))
|
(into {::data/hashmap true} (map-values #(interpret-ast % ctx)) members))
|
||||||
|
|
||||||
::ast/struct
|
::ast/struct
|
||||||
(let [members (:members ast)]
|
(let [members (:members ast)]
|
||||||
|
@ -435,9 +445,7 @@
|
||||||
|
|
||||||
(def source "
|
(def source "
|
||||||
|
|
||||||
let [1, 2, x] = [1, 2, 3]
|
|
||||||
|
|
||||||
x
|
|
||||||
|
|
||||||
")
|
")
|
||||||
|
|
||||||
|
@ -451,7 +459,8 @@
|
||||||
(parser/parse)
|
(parser/parse)
|
||||||
(interpret-safe)
|
(interpret-safe)
|
||||||
(show/show)
|
(show/show)
|
||||||
(println)))
|
;;(println)
|
||||||
|
))
|
||||||
|
|
||||||
(comment "
|
(comment "
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,11 @@
|
||||||
(::data/ref v) ;; TODO: reconsider this
|
(::data/ref v) ;; TODO: reconsider this
|
||||||
(str "ref:" (::data/name v) " <" (deref (::data/value v))">")
|
(str "ref:" (::data/name v) " <" (deref (::data/value v))">")
|
||||||
|
|
||||||
|
(::data/hashmap v)
|
||||||
|
(str "#{" (apply str (into [] show-keyed (dissoc v ::data/hashmap))) "}")
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(str "#{" (apply str (into [] show-keyed v)) "}")
|
(pp/pprint v)
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user