From f4d09afed6ee57f6b424be5e27fc5c9be99f7ed1 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Thu, 11 Jan 2024 14:26:22 -0500 Subject: [PATCH] clj->janet :: loop->clj-loop --- janet/clj-loop.janet | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 janet/clj-loop.janet diff --git a/janet/clj-loop.janet b/janet/clj-loop.janet new file mode 100644 index 0000000..4792832 --- /dev/null +++ b/janet/clj-loop.janet @@ -0,0 +1,13 @@ +(defmacro clj-loop + ``A drop-in replacement for Clojure's loop form. Useful for the current project of converting Clojure code to Janet. + `` + [bindings & body] + (assert (even? (length bindings))) + (def names @[]) + (def args @[]) + (loop [i :range [0 (length bindings)]] + (if (even? i) + (array/push names (get bindings i)) + (array/push args (get bindings i)))) + ~(do (defn recur [,;names] ,;body) (recur ,;args))) +