[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
true-list type specifier
Since we seem to be on the subject of type specifiers, let me add this
question. Given the following code
(defun foo (my-list)
(declare (list my-list))
(member 'my my-list))
and a compiler that has been told to turn off type-checking where
licenced by user declarations. One might assume that MEMBER need not
do a LIST check on each CDR of MY-LIST. But this is not the case, the
above declaration merely licences the compiler to assume that MY-LIST
is NIL or a CONS, but a type check should still be done on the CDR of
MY-LIST (when it is a CONS), and on its CDR, etc.
My question is: How does one declare that MY-LIST is a true list?
For the purpose of discrimination, I suppose the following would
suffice:
(deftype true-list ()
'(or null (and cons (satisfies true-list-p))))
(defun true-cons-p (cons)
(declare (cons cons))
(null (last cons)))
But this would not be usable for purposes of declaration (unless one
was dealing with an AI compiler :->).
So I propose that the type specifier true-list be introduced. This
would then allow compilers to validly substitute a NULL test for a
NULL/CONSP test in the case mentioned above.
-- Nick