Skip to content

Instantly share code, notes, and snippets.

@shouya
Created June 22, 2012 15:48
Show Gist options
  • Save shouya/2973612 to your computer and use it in GitHub Desktop.
Save shouya/2973612 to your computer and use it in GitHub Desktop.
A short scheme macro demonstration(like dotimes in Common Lisp)
(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