Common lisp Lisp SBCL将函数参数声明为特定类型的列表,以进行类型检查

Common lisp Lisp SBCL将函数参数声明为特定类型的列表,以进行类型检查,common-lisp,compiler-warnings,sbcl,typechecking,Common Lisp,Compiler Warnings,Sbcl,Typechecking,我很难弄明白如何告诉sbcl编译器函数的&rest args应该是一个类型列表 基本上,我想变成这样: (defun g (f1 &rest fn) (declare (function f1) (list fn)) ... ) (除g外(f1和其余fn) (声明(函数f1)(列表fn))…) 对这样的事情: (defun g (f1 &rest fn) (declare (function f1) (list fn)) ... ) (defun g (

我很难弄明白如何告诉sbcl编译器函数的
&rest args
应该是一个类型列表

基本上,我想变成这样: (defun g (f1 &rest fn) (declare (function f1) (list fn)) ... ) (除g外(f1和其余fn) (声明(函数f1)(列表fn))…)

对这样的事情:

(defun g (f1 &rest fn) (declare (function f1) (list fn)) ... ) (defun g (f1 &rest fn) (declare (function f1) (list-of-fixnums-type? fn)) ... ) (除g外(f1和其余fn) (声明(函数f1)(fixnums类型列表?fn))…) 我想我可以做到:

(defun g (f1 fn) (declare (function f1) (type (vector function) fn) ... ) (德芬g(f1-fn) (声明(函数f1)(类型(向量函数)fn)…) 但我必须使用向量而不是列表。我知道我可以使用谓词 但是,它在编译时不会这样做,我必须手动抛出一个错误

我想做的事可能吗


我使用的是SBCL 1.3.15

在声明函数的类型时,可以指定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