lisp: consolidate a list-of-lists into a single list?

(apply #'append '((a b c) (d e f) (g h i)))

or

(loop for outer in '((a b c) (d e f) (g h i))
      nconcing (loop for inner in outer collecting inner))

That's a typical homework question. Generally this operation is called FLATTEN (which flattens lists on all levels).

(mapcan #'copy-list '((a b c) (d e f) nil (g h)))

The APPLY variant has the problem that it may run into the CALL-ARGUMENTS-LIMIT when there are more sublists than CALL-ARGUMENTS-LIMIT.

See for example also http://rosettacode.org/wiki/Flatten_a_list#Common_Lisp

Tags:

List

Lisp