syntax-dotimes


R5RS includes the versatile do-macro which can do most of the things you need from a looping construct. But it's syntax is extremely hard to remember to many people and so DO isn't used too often.

Usually one just uses the named-let? idiom, but for some common cases it's more concise to use dedicated forms.

dotimes (borrowed from Common-Lisp)

 (define-syntax dotimes 
   (syntax-rules () 
     ((_ (var n res) . body) 
      (do ((limit n) 
           (var 0 (+ var 1))) 
          ((>= var limit) res) 
        . body)) 
     ((_ (var n) . body) 
      (do ((limit n) 
           (var 0 (+ var 1))) 
          ((>= var limit)) 
        . body)))) 

category-code