At least some implementations of Common Lisp do not allow the use of user-defined constants as array sizes in some type specifiers. For example, in SBCL, this code:
(defconstant +len+ 3)
(defun foo (x)
(declare (type (simple-array fixnum (+len+)) x))
x)
generates this error:
Why? It seems surprising that custom constants cannot be used in type specifiers, since it would be desirable to be able to coordinate multiple type specifiers using some kind of global definition. I understand that type specifiers should be fully understood at compile time. But I would have thought that the compiler would be able to replace the characters defined by defconstanttheir literal values. I would think that this is one of the goals defconstant. (So far, I have not been successful in understanding this issue more deeply from Common Lisp Hyperspec, CLTL2, SBCL's guide, or Google's emergence. I suspect the answer is in one form or another ....)
source
share