【发布时间】:2016-12-12 21:02:13
【问题描述】:
在阅读 Paul Graham 的 On Lisp 时,我在 第 4 章,实用函数中发现了以下 function。
(defun symb (&rest args)
(values (intern (apply #'mkstr args)))) ;; mkstr function is "applied"
;; which evaluates like in the following example:
> (symb nil T :a)
NILTA
想了解一下跟下面这个函数有什么区别,略有不同:
(defun symb1 (&rest args)
(values (intern (mkstr args)))) ;; directly calling mkstr
;; which evaluates like in the following example:
> (symb1 nil T :a)
|(NIL T A)|
在第二个版本中,mkstr 直接使用 args 参数进行评估,但我不明白为什么我们需要在原始版本中执行 (apply #'mkstr ...)。
【问题讨论】:
-
其余参数
ARGS将包含给定参数的列表(示例中为(NIL T :A))。APPLY将“拼接”该列表,因此(apply #'mkstr args)与(mkstr nil t :a)相同。如果没有APPLY,您会将列表作为单个参数传递给MKSTR。
标签: common-lisp on-lisp