Unroll / splat arguments in common lisp

天涯浪子 提交于 2021-02-04 17:13:30

问题


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


回答1:


Oops! I should have remembered how javascript does it.

Turns out you use the apply function, as in:

(apply #'format format-args)


来源:https://stackoverflow.com/questions/2345999/unroll-splat-arguments-in-common-lisp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!