小编Jon*_*Yun的帖子

是否可以在 SBCL/Common Lisp 中在运行时检查/获取函数类型或其签名?

(deftype binary-number-func ()
  `(function (number number) number))

(declaim (ftype binary-number-func my-add))
(defun my-add (a b)
  (+ (the number a) (the number b)))

;; FAIL:
(assert (typep #'my-add 'binary-number-func))
;; Function types are not a legal argument to TYPEP:
;;  (FUNCTION (NUMBER NUMBER) (VALUES NUMBER &REST T))
;;   [Condition of type SIMPLE-ERROR]

;; FAIL:
(typep #'my-add '(function (number number) number))
;; Function types are not a legal argument to TYPEP:
;;   (FUNCTION (NUMBER NUMBER) (VALUES NUMBER &REST T))
;;    [Condition of …
Run Code Online (Sandbox Code Playgroud)

lisp types runtime function common-lisp

5
推荐指数
1
解决办法
311
查看次数

标签 统计

common-lisp ×1

function ×1

lisp ×1

runtime ×1

types ×1