Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unroll / splat arguments in common lisp

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...

like image 472
gfxmonk Avatar asked Feb 27 '10 02:02

gfxmonk


1 Answers

Oops! I should have remembered how javascript does it.

Turns out you use the apply function, as in:

(apply #'format format-args)
like image 108
gfxmonk Avatar answered Nov 12 '22 07:11

gfxmonk