I see that this is pretty old, but it needs saying. Be wary of using quasiquotes for building lists as they basically assume that any code that touches those lists isn't going to mutate them. In general, you cannot assume that everybody that uses your library is going know not to do that. Take for instance:
Code: Select all
CL-USER> (defun func1 () `(1 2 ,@'(3 4)))
FUNC1
CL-USER> (func1)
(1 2 3 4)
CL-USER> (setf (cdr (func1)) '(a b c))
(A B C)
CL-USER> (func1)
(1 A B C)
CL-USER> (defun func2 () `(1 2 ,.'(3 4)))
FUNC2
CL-USER> (func2)
(1 2 3 4)
CL-USER> (setf (cdr (func2)) '(a b c))
(A B C)
CL-USER> (func2)
(1 A B C)
That list is closed over, not newly generated.
To answer your question, I find myself doing a lot of this:
Code: Select all
(append '(a b c)
(if (= x 5)
(list 'd 'e 'f)
() )
;; or
(when (predicate?)
(list 'h 'i 'j) ))
...or you can use NCONC if all of the lists are freshly consed.