Created
June 22, 2012 15:48
-
-
Save shouya/2973612 to your computer and use it in GitHub Desktop.
A short scheme macro demonstration(like dotimes in Common Lisp)
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
(define-macro do-times | |
(lambda (times . body) | |
(let ((rest-time (gensym)) | |
(loop-func-name (gensym))) | |
(begin | |
`(letrec ((,loop-func-name | |
(lambda (,rest-time) | |
(if (= ,rest-time 0) '() | |
(begin | |
,@body | |
(,loop-func-name (- ,rest-time 1))))))) | |
(,loop-func-name ,times)))))) | |
(do-times 10 | |
(display "hello\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment