在常见Lisp中展开/展开图示参数 [英] Unroll / splat arguments in common lisp

查看:59
本文介绍了在常见Lisp中展开/展开图示参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个参数列表:

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

然后我如何才能将其"splat"或展开"为一系列参数,而不是单个列表参数,以提供给format函数?即我希望进行以下函数调用:

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)

作为参考,我将在python或ruby中编写以下内容:

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

推荐答案

糟糕!我应该记得javascript是如何做到的.

Oops! I should have remembered how javascript does it.

结果证明您使用了apply函数,如下所示:

Turns out you use the apply function, as in:

(apply #'format format-args)

这篇关于在常见Lisp中展开/展开图示参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆