summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-08-29 07:58:35 -0400
committerDavid Thompson <dthompson2@worcester.edu>2018-08-29 07:58:35 -0400
commite39cf322b25a8ffd9f0fc3f3d85370802740528f (patch)
tree8861a997d6cd752b859a6fa27b88030e90a0f8e5
parent7d64cb370bd5abcdaed9215a33bc450c0bb21bf4 (diff)
scripting: Add repeat macro.
* chickadee/scripting.scm (repeat): New syntax.
-rw-r--r--chickadee/scripting.scm8
1 files changed, 8 insertions, 0 deletions
diff --git a/chickadee/scripting.scm b/chickadee/scripting.scm
index d88e422..ff65e86 100644
--- a/chickadee/scripting.scm
+++ b/chickadee/scripting.scm
@@ -22,6 +22,7 @@
#:use-module (chickadee scripting channel)
#:use-module (chickadee scripting script)
#:export (forever
+ repeat
sleep
tween)
#:replace (sleep))
@@ -41,6 +42,13 @@
"Evaluate BODY in an endless loop."
(while #t body ...))
+(define-syntax-rule (repeat n body ...)
+ "Evaluate BODY N times."
+ (let loop ((i 0))
+ (when (< i n)
+ body ...
+ (loop (+ i 1)))))
+
(define (sleep duration)
"Wait DURATION before resuming the current script."
;; Capture the current agenda before suspending the script so that