From a6d64ff827acef385db8ba2db0573f677eaaf4d3 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 24 Dec 2023 14:11:49 -0500 Subject: [PATCH 1/3] Change grammar --- src/ludus/grammar.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ludus/grammar.cljc b/src/ludus/grammar.cljc index 47e0978..334c491 100644 --- a/src/ludus/grammar.cljc +++ b/src/ludus/grammar.cljc @@ -229,7 +229,7 @@ (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 :times [:word :number]) block]) +(defp repeat-expr group order-1 [(quiet :repeat) (choice :times [:word :number]) non-binding]) (defp collection flat choice [;struct-literal dict list-literal set-literal tuple]) From 7541d2499de3511f3161c39dc8e11fc1f8c7b439 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 24 Dec 2023 14:12:50 -0500 Subject: [PATCH 2/3] Change interpreter (just change name of binding in interpret-repeat --- src/ludus/interpreter.cljc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ludus/interpreter.cljc b/src/ludus/interpreter.cljc index ed0cca9..70cb877 100644 --- a/src/ludus/interpreter.cljc +++ b/src/ludus/interpreter.cljc @@ -811,9 +811,9 @@ times (if (= :word (:type times-expr)) (resolve-word times-expr ctx) (-> times-expr :data first)) - block (second data)] + expr (second data)] (if (not (number? times)) (throw (ex-info (str "Repeat needs a number, not a " (base/get-type times)) {}))) - (dotimes [_ times] (interpret-ast block ctx)))) + (dotimes [_ times] (interpret-ast expr ctx)))) (defn- interpret-literal [ast] (-> ast :data first)) From 7a2c404daf28657b6f457ac85d91b36a16278c4f Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 24 Dec 2023 14:16:08 -0500 Subject: [PATCH 3/3] Light testing --- src/ludus/node.cljc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ludus/node.cljc b/src/ludus/node.cljc index 3c91609..028d899 100644 --- a/src/ludus/node.cljc +++ b/src/ludus/node.cljc @@ -60,8 +60,8 @@ (comment (def source " - - :a (_) + let times = 4 + repeat times print! (:foo) ")