【发布时间】:2016-05-25 04:55:41
【问题描述】:
给定
(defun show-arg (a)
(format t "a is ~a~%" a))
(defun show-key (&key a)
(format t "a is ~a~%" a))
评估
(show-arg)
将导致错误提示“参数数量无效:0”,其中
(show-key)
将显示a is NIL
如何让SHOW-KEY 像SHOW-ARG 一样发出错误信号?除了在函数体中使用(unless a (error "a is required")),还有其他方法吗?我非常喜欢关键字参数并经常使用它们,并且几乎总是希望它们是必需的。
【问题讨论】:
标签: common-lisp keyword-argument