collect: New functions collect-append and collect-nconc.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 1 Jun 2006 15:26:31 +0000 (16:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 1 Jun 2006 15:26:31 +0000 (16:26 +0100)
collect.lisp

index 219f351..359780c 100644 (file)
      (setf (cdar ,name) ,x)
      (setf (car ,name) nil)))
 
+(defmacro collect-append (list &optional (name *collecting-anon-list-name*))
+  "Append LIST to the tail of `collecting' list NAME.  This obviously
+   involves copying LIST."
+  (with-gensyms item
+    `(dolist (,item ,list)
+       (collect ,item ,name))))
+
+(defmacro collect-nconc (list &optional (name *collecting-anon-list-name*))
+  "Attach LIST to the tail of `collecting' list NAME.  This will involve
+   destroying LIST if anything else gets collected afterwards."
+  (let*/gensyms list
+    `(when ,list
+       (setf (cdar ,name) ,list)
+       (setf (car ,name) (last ,list)))))
+
 ;;;----- That's all, folks --------------------------------------------------