User Tools

Site Tools


ch2_1_dotimes

DOTIMES

Classic LISP iteration macro, implemented as special form in LabLISP. Expects at least one argument, which must be properly formed list: First element is a plain symbol, which will be the counter variable. Second element must evaluate to integer - number of loops. There might be optional third element, the result form - single expression which will be evaluated after the looping is finished. If there is no result expression, the DOTIMES form returns NIL.

After the initializer list, there can be any number of expressions (implicit PROGN), which will be evaluated repeatedly in loop.

>(dotimes (i 3) (print i))   ; loop will run 3 times
0                            ; I starts from 0
1
2
NIL                          ; DOTIMES returns NIL

Note that the optional result form is evaluated in the context where the counter symbol is still defined and has the integer value of the number of loops done.

>(dotimes (i 3 i) (print "loop"))
"loop"
"loop"
"loop"
3                            ; result form has value 3

See also: DOLIST, RETURN

ch2_1_dotimes.txt · Last modified: 2022/02/20 05:03 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki