2010/05/25

syntax-rules: dotimes

;; dotimes
(define-syntax dotimes
(syntax-rules ()
((_ n body ...)
(do ((i n (- i 1)))
((not (< 0 i)))
body ...))))
(dotimes 5
(display "hello")
(print "world"))
;; helloworld
;; helloworld
;; helloworld
;; helloworld
;; helloworld
;; #t
(define-syntax dotimes
(syntax-rules ()
((_ n body ...)
(let loop ((i n))
(when (< 0 i)
body ...
(loop (- i 1)))))))
(dotimes 5
(print "H")
(print "l")
(print "l")
(print "o"))
;; H
;; l
;; l
;; o
;; H
;; l
;; l
;; o
;; H
;; l
;; l
;; o
;; H
;; l
;; l
;; o
;; H
;; l
;; l
;; o
;; #<undef>
view raw dotimes.scm hosted with ❤ by GitHub


プログラミングGaucheThe Reasoned Schemer

0 件のコメント:

コメントを投稿