T
Tim Bradshaw
Or ever use the same one twice. Kinda limits their usefulness
methinks.
I know you won't listen [so why am I wasting my time?] but you *really*
need to actually make some effort to understand CL (or Lisp in general)
because this kind of statement is just making you look silly.
For instance, consider this macro:
(defmacro collecting (&body forms)
(let ((ln (make-symbol "LIST"))
(ltn (make-symbol "TAIL")))
`(let ((,ln '())
(,ltn '()))
(flet ((collect (it)
(if (null ,ltn)
(setf ,ln (list it)
,ltn ,ln)
(setf (cdr ,ltn) (list it)
,ltn (cdr ,ltn)))
it))
(progn
,@forms
,ln)))))
This uses two gensyms (I've made them with MAKE-SYMBOL, so I can give
them print names which help, but they are uninterned symbols.
Now, what does the expansion of this look like?
? (macroexpand
'(collecting
(collect 1)
(collect 2)))
(let ((#:list 'nil) (#:tail 'nil))
(flet ((collect (it)
(if (null #:tail)
(setf #:list (list it) #:tail #:list)
(setf (cdr #:tail) (list it) #:tail (cdr #:tail)))
it))
(progn (collect 1) (collect 2) #:list)))
Except, of course, those uninterned symbols are actually *the same two
symbols* each time they are used, as you can see from the macro
definition. Fortunately there is a machanism of showing this: set
*PRINT-CIRCLE* to true:
? (macroexpand
'(collecting
(collect 1)
(collect 2)))
(let ((#2=#:list 'nil) (#1=#:tail 'nil))
(flet ((collect (it)
(if (null #1#)
(setf #2# (list it) #1# #2#)
(setf (cdr #1#) (list it) #1# (cdr #1#)))
it))
(progn (collect 1) (collect 2) #2#)))