Next: , Previous: , Up: Value Accumulation   [Contents][Index]


15.25.8.2 append - appending - nconc - nconcing

append expr [into var]
appending expr [into var]
nconc expr [into var]
nconcing expr [into var]

These constructs are similar to ‘collect’ except that the values of the specified expression must be lists.

append

keyword causes its list values to be concatenated into a single list, as if they were arguments to the Common Lisp function append.

nconc

keyword causes its list values to be concatenated into a single list, as if they were arguments to the Common Lisp function nconc. Note that the ‘nconc’ keyword destructively modifies its argument lists.

var

is set to the list of concatenated values; if you specify var, the loop does not return the final list automatically. The var argument is bound as if by the construct ‘with’. You cannot specify a data type for var; it must be of type ‘list’.

Examples

;;; Use APPEND to concatenate some sublists.
(loop for x in '((a) (b) ((c)))
      append x)
;;; NCONC some sublists together.  Note that only lists
;;; made by the call to LIST are modified.
(loop for i upfrom 0
      as x in '(a b (c))
      nconc (if (evenp i) (list x) '()))