adding (do ) form

This commit is contained in:
JeffBezanson 2009-02-20 19:50:35 +00:00
parent 3aad0bd6be
commit 76edead57b
1 changed files with 19 additions and 0 deletions

View File

@ -424,6 +424,25 @@
(cdr clause))) (cdr clause)))
clauses))))) clauses)))))
(define-macro (do vars test-spec . commands)
(let ((loop (gensym))
(test-expr (car test-spec))
(vars (map car vars))
(inits (map cadr vars))
(steps (map (lambda (x)
(if (pair? (cddr x))
(caddr x)
(car x)))
vars)))
`(letrec ((,loop (lambda ,vars
(if ,test-expr
(begin
,@(cdr test-spec))
(begin
,@commands
(,loop ,@steps))))))
(,loop ,@inits))))
(define-macro (dotimes var . body) (define-macro (dotimes var . body)
(let ((v (car var)) (let ((v (car var))
(cnt (cadr var))) (cnt (cadr var)))