From 906f11fb2104c4f6f9770c0c4d747cf44c13bfe6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 16 Apr 2015 06:28:11 -0700 Subject: Adding dotimes macro. * eval.c (me_dotimes): New function. (eval_init): Registering dotimes macro. * txr.1: Documented dotimes. --- txr.1 | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 6b7c013c..e1c1394c 100644 --- a/txr.1 +++ b/txr.1 @@ -10370,6 +10370,47 @@ is returned. (format t "frobosity value ~a exceeds 150\en" fv)) .cble +.coNP Macro @ dotimes +.synb +.mets (dotimes >> ( var < count-form <> [ result-form ]) << body-form *) +.syne +.desc +The +.code dotimes +macro implements a simple counting loop. +.meta var +is established as a variable, and initialized to zero. +.meta count-form +is evaluated one time to produce a limiting value, which should be a number. +Then, if the value of +.meta var +is less than the limiting value, the +.metn body-form -s +are evaluated, +.meta var +is incremented by one, and the process repeats with a new comparison +of +.meta var +against the limiting value possibly leading to another evaluation of +the forms. + +If +.meta var +is found to equal or exceed the limiting value, then the loop terminates. + +When the loop terminates, its return value is +.code nil +unless a +.meta result-form +is present, in which case the value of that form specifies the return value. + +.metn body-form -s +as well as +.meta result-form +are evaluated in the scope in which the binding of +.meta var +is visible. + .coNP Operator @ unwind-protect .synb .mets (unwind-protect < protected-form << cleanup-form *) -- cgit v1.2.3