This question already has an answer here:
So I would like to write a type specifier for list that allows one to specify the types of the list elements. Something like :
(deftype list-of (v) (cons ,v (or null (list-of ,v))))
but of course, that's not going to work because as we all know, recursive types are not supported. One could map something like "satisfies" of course (as has been mentioned here: Is it possible to define a recursive type in Common Lisp?), but that kind of negates the advantage of a clean recursive definition suitable for language analysis and offline code analysis. (E.g., proving code is correct, and or translating between languages).
Any suggestions? Seems like this is a missing bit of standard, unless I'm missing something obvious, given we typically use lists to represent sets - why not have a simple way to declare the types of set elements?
Sorry, this isn't allowed. The
DEFTYPE
specification says:This language was the result of a the RECURSIVE-DEFTYPE cleanup issue during the standardization process. An implementation could allow recursive type definitions in some cases as an extension, but you can't depend on it portably.