scm.mes: implement do.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-24 17:03:28 +02:00
parent 746d06a0ec
commit 39d5722973
2 changed files with 8 additions and 0 deletions

View file

@ -62,6 +62,12 @@
(let-loop ,bindings-or-label ,(car rest) ,(cdr rest))) (let-loop ,bindings-or-label ,(car rest) ,(cdr rest)))
(#t (simple-let ,bindings-or-label ,rest)))) (#t (simple-let ,bindings-or-label ,rest))))
(define-macro (do init test . body)
`(let loop ((,(caar init) ,(cadar init)))
(when (not ,@test)
,@body
(loop ,@(cddar init)))))
(define-macro (or2 x y) (define-macro (or2 x y)
`(cond (,x ,x) (#t ,y))) `(cond (,x ,x) (#t ,y)))

View file

@ -285,6 +285,8 @@
(pass-if "min 1" (seq? (min 0 1) 0)) (pass-if "min 1" (seq? (min 0 1) 0))
(pass-if "min 2" (seq? (min 1 0 2) 0)) (pass-if "min 2" (seq? (min 1 0 2) 0))
(pass-if "do" (sequal? (let ((acc '())) (do ((i 0 (+ i 1))) ((>= i 3)) (set! acc (cons i acc))) acc) '(2 1 0)))
(newline) (newline)
(display "passed: ") (display (car (result))) (newline) (display "passed: ") (display (car (result))) (newline)
(display "failed: ") (display (cadr (result))) (newline) (display "failed: ") (display (cadr (result))) (newline)