[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

list of proposed changes to Common Lisp

    (*) 158 Specify that it is an error for more than one TYPE declaration
    for a given variable to appear in a group of declarations (those all
    at the head of the same body), or more than one FTYPE or FUNCTION
    declaration for a given function name, or both an INLINE and a
    NOTINLINE declaration for the same function.

I think this is excessively restrictive.  The obvious meaning of
multiple type declarations for the same variable is that the value of
the variable is of *both* types.  (declare (type a foo) (type b foo))
is the same as (declare (type (and a b) foo)).

This feature could actually be used to good effect.  Suppose a clever
writer of the DOTIMES macro realized that the variable will always be
of type (INTEGER 0), and added such a declaration in the expansion.
The user of DOTIMES might know that the upper bound is always a
fixnum, and write (dotimes (i x) (declare (fixnum i)).  The compiler
could then determine that the step variable is in fact a non-negative
fixnum, which might be a useful piece of information.

Note that if the declared types are known to be disjoint, the variable
will have effectively been declared to be of type NIL, thus the
binding (not the declaration) is illegal, since its initial value
cannot be of type NIL.  Note also that this interpretation won't break
anything; the variable belongs to all the types, thus an
implementation which uses any one will still be correct.

An FTYPE declaration is identical to a type declaration except for
specifying the result of functional evaluation, so the same reasoning
holds.  A FUNCTION declaration is in fact a (TYPE FUNCTION ...)
declaration, so this is also reasonable.

I have no objection of saying that conflicting INLINE and NOTINLINE
declarations are illegal, but due to the advisory nature of INLINE
declarations, it might be reasonable to say the compiler can obey
whichever declaration it feels like.

While we are talking about types, I will mention that there is a
missing type specifier, namely REAL, which is probably the same as
(OR FLOAT RATIONAL).  Although probably useless as a declaration, it
is useful for things like CHECK-TYPE.