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.

1
  • 2
    That #'funcall is unnecessary. Commented Aug 31, 2019 at 18:05

1 Answer 1

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)))
Sign up to request clarification or add additional context in comments.

1 Comment

This answer (disclaimer, I wrote it) has some more examples of spreadable arglists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.