Unroll / splat arguments in common lisp
Asked Answered
I

1

10

Say I have a list of arguments:

> (setf format-args `(t "it's ~a" 1))  
(T "it's ~a" 1)

How can I then "splat" or "unroll" this into a series of arguments rather than a single list argument, for supplying to the format function? i.e I would like the following function call to take place:

> (format t "it's ~a" 1)

For reference, I would write the following in python or ruby:

format(*format-args)

I'm sure it can be done, but perhaps I'm thinking about it wrong. It also doesn't help that the name for this operation doesn't seem to be terribly well agreed upon...

Incapacitate answered 27/2, 2010 at 2:22 Comment(0)
I
10

Oops! I should have remembered how javascript does it.

Turns out you use the apply function, as in:

(apply #'format format-args)
Incapacitate answered 27/2, 2010 at 2:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.