gensym's behavior in a macro
Posted: Sun Dec 02, 2012 6:46 am
HI
I have a fast & easy question(easy for You ) about gensym used in that macro example:
But if I redefine ‘do test ‘as : (> ,var ,stop) instead of (> ,var ,gstop) for demonstration purposes only:
if I see it expanded:
(pprint (macroexpand-1 '(for x 1 5 (princ x)))) return -> (DO ((X 1 (1+ X))) ((> X 5)) (PRINC X))
it should work equally…..???why “do body†is not valued? Only because gensym’s variable is unused??
thanks in advance!
I have a fast & easy question(easy for You ) about gensym used in that macro example:
Code: Select all
(defmacro for (var start stop &body body)
(let ((gstop (gensym)))
`(do ((,var ,start (1+ ,var))
(,gstop ,stop))
((> ,var ,gstop))
,@body)))
>(for x 1 5 (princ x)))
12345
NIL
Code: Select all
(defmacro for (var start stop &body body)
(let ((gstop (gensym)))
`(do ((,var ,start (1+ ,var))
(,gstop ,stop))
((> ,var ,stop)) ;; here
,@body)))
;;why macro call:
(for x 1 5 (princ x))) ; return only -> NIL?
(pprint (macroexpand-1 '(for x 1 5 (princ x)))) return -> (DO ((X 1 (1+ X))) ((> X 5)) (PRINC X))
it should work equally…..???why “do body†is not valued? Only because gensym’s variable is unused??
thanks in advance!