This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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> | |
0 件のコメント:
コメントを投稿