Macros 如何在“declare”中展开类型说明符?

Macros 如何在“declare”中展开类型说明符?,macros,common-lisp,Macros,Common Lisp,我使用的是Common Lisp,我有多个函数使用相同类型的数据,我使用declare指定如下符号类型: (defun foo (x) (declare (type single-float x)) ...) (defun bar (x y) (declare (type single-float x y)) ...) 现在,我想将单浮点数存储到自定义符号中,如可更改浮点数,以便轻松更改这些函数的所有类型(例如,从单浮点数到双浮点数)。我尝试过这些代码,但不起作用: (def

我使用的是Common Lisp,我有多个函数使用相同类型的数据,我使用
declare
指定如下符号类型:

(defun foo (x)
  (declare (type single-float x))
  ...)

(defun bar (x y)
  (declare (type single-float x y))
  ...)
现在,我想将
单浮点数
存储到自定义符号中,如
可更改浮点数
,以便轻松更改这些函数的所有类型(例如,从
单浮点数
双浮点数
)。我尝试过这些代码,但不起作用:

(defvar changeable-float 'single-float)

(defun foo (x)
  (declare (type changeable-float x))
  ...)

(defun bar (x y)
  (declare (type changeable-float x y))
  ...)

如何实现此想法?

使用
DEFTYPE
定义类型

CL-USER 41 > (deftype foo () 'integer)
FOO

CL-USER 42 > (typep 3 'foo)
T

CL-USER 43 > (typep "33" 'foo)
NIL

使用
DEFTYPE
定义类型

CL-USER 41 > (deftype foo () 'integer)
FOO

CL-USER 42 > (typep 3 'foo)
T

CL-USER 43 > (typep "33" 'foo)
NIL