SaltyEgg
SaltyEgg

Reputation: 1558

How to expand a type specifier inside a `declare`?

I'm using Common Lisp, and I have multiple functions use the same type of data, and I use declare to specify the type of symbols like this:

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

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

Now I want to store single-float into a custom symbol like changable-float so that I can easily change all the types of these functions (e.g., from single-float to double-float). I have tried these code but it not works:

(defvar changeable-float 'single-float)

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

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

How can I implement this idea?

Upvotes: 0

Views: 77

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139261

Use DEFTYPE to define a type.

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

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

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

Upvotes: 5

Related Questions