0

Some of the Common Lisp list and sequence functions can take multiple lists or sequences as their final arguments. For example:

(mapcar #'list '(a b) '(c d) '(e f)) => ((a c e) (b d f))

But if the final arguments are already consolidated into a list/sequence like ((a b) (c d) (e f) ...), how can you achieve the same result (as if the list/sequence were spliced into the original function)? Is there a more straightforward approach than writing a macro?

EDIT: I think I've found one way: (apply #'funcall #'mapcar #'list '((a b) (c d) (e f))) but there may be others.

davypough
  • 1,847
  • 11
  • 21

1 Answers1

3

You use apply, which takes as last argument a spreadable arguments list designator.

For your example:

(apply #'mapcar #'list '((a b) (c d) (e f)))
Svante
  • 50,694
  • 11
  • 78
  • 122
  • [This answer](https://stackoverflow.com/a/33553757/1281433) (disclaimer, I wrote it) has some more examples of spreadable arglists. – Joshua Taylor Sep 02 '19 at 20:01