【问题标题】:Unroll / splat arguments in common lisp在普通 lisp 中展开 / splat 参数
【发布时间】:2011-01-21 16:56:43
【问题描述】:

假设我有一个参数列表:

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

我怎样才能将它“splat”或“展开”成一系列参数而不是单个列表参数,以提供给格式函数? 即我希望进行以下函数调用:

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

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

format(*format-args)

我确信可以做到,但也许我想错了。这个操作的名称似乎并没有得到很好的认同,这也无济于事......

【问题讨论】:

    标签: common-lisp splat


    【解决方案1】:

    哎呀!我应该记得 javascript 是如何做到的。

    原来你使用了 apply 函数,如下所示:

    (apply #'format format-args)
    

    【讨论】:

      猜你喜欢
      • 2010-12-10
      • 2015-11-13
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      相关资源
      最近更新 更多