Complete if-let
This commit is contained in:
parent
689f3f23bc
commit
4254359934
|
@ -136,7 +136,7 @@
|
||||||
::ast/word
|
::ast/word
|
||||||
(let [word (:word pattern)]
|
(let [word (:word pattern)]
|
||||||
(if (contains? ctx word)
|
(if (contains? ctx word)
|
||||||
{:success false :reason (str "Name " word " is already bound")}
|
{:success false :reason (str "Name " word " is already bound") :code :name-error}
|
||||||
{:success true :ctx {word value}}))
|
{:success true :ctx {word value}}))
|
||||||
|
|
||||||
::ast/tuple (match-tuple pattern value ctx-vol)
|
::ast/tuple (match-tuple pattern value ctx-vol)
|
||||||
|
@ -165,7 +165,19 @@
|
||||||
(throw (ex-info (:reason match) {:ast ast})))
|
(throw (ex-info (:reason match) {:ast ast})))
|
||||||
value))
|
value))
|
||||||
|
|
||||||
(defn- interpret-if-let [ast ctx])
|
(defn- interpret-if-let [ast ctx]
|
||||||
|
(let [pattern (:pattern ast)
|
||||||
|
expr (:expr ast)
|
||||||
|
value (interpret-ast expr ctx)
|
||||||
|
match (match pattern value ctx)
|
||||||
|
success (:success match)]
|
||||||
|
(if success
|
||||||
|
(do
|
||||||
|
(vswap! ctx update-ctx (:ctx match))
|
||||||
|
value)
|
||||||
|
(if (:code match)
|
||||||
|
(throw (ex-info (:reason match) {:ast ast}))
|
||||||
|
false))))
|
||||||
|
|
||||||
(defn- interpret-if [ast ctx]
|
(defn- interpret-if [ast ctx]
|
||||||
(let [if-expr (:if ast)
|
(let [if-expr (:if ast)
|
||||||
|
@ -649,12 +661,14 @@
|
||||||
)))))
|
)))))
|
||||||
|
|
||||||
|
|
||||||
(do
|
(comment
|
||||||
(process/start-vm)
|
(process/start-vm)
|
||||||
(def source "
|
(def source "
|
||||||
let foo = 3
|
let foo = (:a, :b)
|
||||||
|
|
||||||
if let 3 = foo then :foo else :bar
|
if let (x, y) = foo then :foo else :bar
|
||||||
|
|
||||||
|
y
|
||||||
|
|
||||||
")
|
")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user