From 689f3f23bcf0e898d2b11e953dea96372999ab47 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 19 Jun 2022 13:46:11 -0400 Subject: [PATCH] Add interpret-if-let --- src/ludus/interpreter.clj | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/ludus/interpreter.clj b/src/ludus/interpreter.clj index 573f4f4..ba6157d 100644 --- a/src/ludus/interpreter.clj +++ b/src/ludus/interpreter.clj @@ -165,11 +165,15 @@ (throw (ex-info (:reason match) {:ast ast}))) value)) +(defn- interpret-if-let [ast ctx]) + (defn- interpret-if [ast ctx] (let [if-expr (:if ast) then-expr (:then ast) else-expr (:else ast) - if-value (interpret-ast if-expr ctx)] + if-value (if (= (::ast/type if-expr) ::ast/let) + (interpret-if-let if-expr ctx) + (interpret-ast if-expr ctx))] (if if-value (interpret-ast then-expr ctx) (interpret-ast else-expr ctx)))) @@ -608,8 +612,8 @@ (with-bindings {#'self (:pid @process)} (let [result (interpret-ast (::parser/ast parsed) base-ctx)] (swap! process #(assoc % :status :dead)) - result)) - (process/stop-vm)) + (process/stop-vm) + result))) (catch clojure.lang.ExceptionInfo e (process/stop-vm) (println "Ludus panicked!") @@ -645,30 +649,12 @@ ))))) -(comment +(do (process/start-vm) (def source " - fn echo () -> { - & print (self, :echoing) - loop () with () -> { - & print (self, :looping) - receive { - msg -> { - print (\"from \", self, \": \", msg) - recur () - } - } - } - } + let foo = 3 - let echoer = spawn echo () - - send :hello to echoer - send :foo to echoer - send :bar to echoer - send :baz to echoer - - sleep (1000) + if let 3 = foo then :foo else :bar ")