From c88a06d447790f9ed159689c2cb2cab7554858b6 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Thu, 7 Dec 2023 12:28:30 -0500 Subject: [PATCH] Start adding repeat form. --- src/ludus/grammar.cljc | 4 +++- src/ludus/interpreter.cljc | 4 ++++ src/ludus/scanner.cljc | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ludus/grammar.cljc b/src/ludus/grammar.cljc index 081af5a..5f2bf9e 100644 --- a/src/ludus/grammar.cljc +++ b/src/ludus/grammar.cljc @@ -228,11 +228,13 @@ (defp loop-expr group order-1 [(quiet :loop) tuple (quiet :with) (flat (choice :loop-body [fn-clause compound-loop]))]) +(defp repeat-expr group order-1 [(quiet :repeat) (choice :word :number) block]) + (defp collection flat choice [struct-literal dict list-literal set-literal tuple]) (defp simple flat choice [literal collection synthetic recur-call lambda]) -(defp compound flat choice [match loop-expr if-expr when-expr do-expr block]) +(defp compound flat choice [match loop-expr if-expr when-expr do-expr block repeat-expr]) (defp binding-expr flat choice [fn-named let-expr ref-expr]) diff --git a/src/ludus/interpreter.cljc b/src/ludus/interpreter.cljc index ebf239a..925fc5e 100644 --- a/src/ludus/interpreter.cljc +++ b/src/ludus/interpreter.cljc @@ -674,6 +674,8 @@ (vswap! ctx update-ctx {name ref}) ref))) +(defn- interpret-repeat [ast ctx] :TODO) + (defn- interpret-loop [ast ctx] (let [data (:data ast) tuple (interpret-ast (first data) ctx) @@ -841,6 +843,8 @@ :loop-expr (interpret-loop ast ctx) + :repeat-expr (interpret-repeat ast ctx) + :block (let [exprs (:data ast) inner (pop exprs) diff --git a/src/ludus/scanner.cljc b/src/ludus/scanner.cljc index 29dad67..c273907 100644 --- a/src/ludus/scanner.cljc +++ b/src/ludus/scanner.cljc @@ -30,15 +30,15 @@ "when" :when ;; impl, replaces cond ;; actor model/concurrency - "receive" :receive + ;"receive" :receive ;;"self" :self ;; maybe not necessary?: self() is a function ;;"send" :send ;; not necessary: send(pid, message) is a function - "spawn" :spawn + ;"spawn" :spawn ;;"to" :to ;; not necessary if send is a function ;; type system ;; "data" :data ;; we are going to tear out datatypes for now: see if dynamism works for us ;; others - ;;"repeat" :repeat ;; syntax sugar over "loop": still unclear what this syntax could be + "repeat" :repeat ;; syntax sugar over "loop": still unclear what this syntax could be "test" :test ;; "module" :module ;; not necessary if we don't have datatypes })