[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Types in CL
Date: Sun, 27 Dec 87 13:15:46 PST
From: Jon L White <edsel!jonl@labrea.stanford.edu>
re:
Actually, there is a bug in your original message, in the TYPEP call.
The predicate
(TYPEP A 'T1)
expands to
(TYPEP A '(ARRAY T2 1))
which is equivalent to
(AND (ARRAYP A)
(EQ (ARRAY-ELEMENT-TYPE A) 'T2)
(= (ARRAY-RANK A) 1)
(= (ARRAY-DIMENSION A 0) 1))
This isn't right, and is probably a good example of the single most common
error when trying to figure out what the array types mean. Since a CL
implementation of arrays is permitted to "upgrade" the :element-type
argument into something actually supported, and since there is no
requirement to preserve the original :element-type argument, then the
line above
(EQ (ARRAY-ELEMENT-TYPE A) 'T2)
should be
(SUBTYPEP 'T2 (ARRAY-ELEMENT-TYPE A))
Of course, optimizations are possible for specific T2's; but in general
the element-type might have been upgraded to, for example, T.
This contradicts an explicit statement to the contrary in CLtL. On page
46, it says:
(ARRAY CHARACTER) is not the set of all arrays that can hold
characters, but rather the set of arrays that are specialized to
hold characters and no other objects. To test whether an array FOO
can hold a character, one should not use
(TYPEP FOO '(ARRAY CHARACTER))
but rather
(SUBTYPEP 'CHARACTER (ARRAY-ELEMENT-TYPE FOO))
I therefore stand by my translation.
barmar
- References:
- Types in CL
- From: Jon L White <edsel!jonl@labrea.stanford.edu>