(defmacro collecting (vars &body body)
"Collect items into lists. The VARS are a list of collection variables --
(defmacro collecting (vars &body body)
"Collect items into lists. The VARS are a list of collection variables --
((atom vars) (setf vars (list vars))))
`(let ,(mapcar (lambda (v) `(,v (make-collector))) vars)
,@body
((atom vars) (setf vars (list vars))))
`(let ,(mapcar (lambda (v) `(,v (make-collector))) vars)
,@body
(defmacro with-collection (vars collection &body body)
"Collect items into lists VARS according to the form COLLECTION; then
(defmacro with-collection (vars collection &body body)
"Collect items into lists VARS according to the form COLLECTION; then
(defmacro collect (x &optional (name *collecting-anon-list-name*))
"Add item X to the `collecting' list NAME (or *collecting-anon-list-name*
by default)."
(defmacro collect (x &optional (name *collecting-anon-list-name*))
"Add item X to the `collecting' list NAME (or *collecting-anon-list-name*
by default)."
- (with-gensyms tmp
- `(let ((,tmp (cons ,x nil)))
- (setf (cddr ,name) ,tmp)
- (setf (cdr ,name) ,tmp))))
+ (with-gensyms new
+ `(let ((,new (cons ,x nil)))
+ (setf (cdar ,name) ,new)
+ (setf (car ,name) ,new))))
(defmacro collect-tail (x &optional (name *collecting-anon-list-name*))
"Make item X be the tail of `collecting' list NAME (or
*collecting-anon-list-name* by default). It is an error to continue
trying to add stuff to the list."
`(progn
(defmacro collect-tail (x &optional (name *collecting-anon-list-name*))
"Make item X be the tail of `collecting' list NAME (or
*collecting-anon-list-name* by default). It is an error to continue
trying to add stuff to the list."
`(progn