Last active
August 29, 2015 14:02
-
-
Save toctan/0f307c3aef04d30acb1e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defmacro ntimes (n &rest body) ; wrong | |
`(do ((i 0 (1+ i))) | |
((>= i ,n)) | |
,@body)) | |
(let ((i 10)) ; 10 | |
(ntimes 5 (incf i)) | |
i) | |
(defmacro ntimes (n &rest body) ; also wrong, but in a different way | |
(let ((i (gensym))) | |
`(do ((,i 0 (1+ ,i))) | |
((>= ,i ,n)) | |
,@body))) | |
(let ((v 10)) ; ..... | |
(ntimes (decf v) | |
(princ "."))) | |
(defmacro ntimes (n &rest body) ; finally, the right version | |
(let ((i (gensym)) | |
(g (gensym))) | |
`(let ((,g ,n)) | |
(do ((,i 0 (1+ ,i))) | |
((>= ,i ,g)) | |
,@body)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment