From 38c49c635ca520305948d2ded3660dea83e514e1 Mon Sep 17 00:00:00 2001 From: Dustin Getz Date: Tue, 3 Sep 2024 09:44:27 -0400 Subject: [PATCH] e/with-cycle --- src/hyperfiddle/electric3.cljc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hyperfiddle/electric3.cljc b/src/hyperfiddle/electric3.cljc index 60f8c8b39..dd9000256 100644 --- a/src/hyperfiddle/electric3.cljc +++ b/src/hyperfiddle/electric3.cljc @@ -203,6 +203,14 @@ this tuple. Returns the concatenation of all body results as a single vector. ~(rec bindings)) `(do ~@body))) (seq bindings)))) +(defmacro with-cycle + "evaluates body with symbol s bound to the previous result of the body evaluation. + the first evaluation binds s to i." + {:style/indent 1} + [[s i] & body] + `(let [a# (atom ~i) ~s (watch a#)] + (reset! a# (do ~@body)))) + ;; mklocal = declare lexical slot ;; bindlocal = bind lexical slot to value by name ;; See compiler walkthrough: electric/impl/lang_3_walkthrough.md