Lisp SBCL 声明一个函数参数是用于类型检查的某种类型的列表



我很难弄清楚如何告诉 sbcl 编译器函数的&rest args应该是 TYPE 列表。

基本上,我想变成这样的东西:

(defun g (f1 and rest fn) (声明 (函数 f1) (列表 fn)) ... )

像这样:

(DeFun G (F1 and Rest FN) (声明 (函数 f1) (fixnums-type?fn)) ...

我想我可以这样做:

(DeFun G (F1 FN) (声明 (函数 f1) (类型 (向量函数) fn) ... )

但是我必须使用向量而不是列表。我知道我可以使用谓词 但是它不会在编译时执行此操作,我必须手动抛出错误。

我正在尝试做的事情可能吗?

我正在使用 SBCL 1.3.15

您可以在声明函数的 ftype 时为 rest 参数指定类型。

(declaim (ftype (function (function &rest fixnum) t)
foo))
(defun foo (f &rest nums)
(funcall f nums))
(defun bar ()
(foo #'princ 345 -432 23 "45" 54)) ; warning: Constant "45" conflicts with its asserted type FIXNUM

最新更新