by pfdietz · 1y ago · 0 comments
Arrays can have an element type specified, and this type is "upgraded" to a type that is actually store in the array. This upgraded type is a supertype of the actual element type. Upgrading must also preserve subtypes: if T1 is a subtype of T2, then upgrade(T1) must be a subtype of upgrade(T2) (not necessarily a proper subtype, even if T1 != T2).
Now, the standard requires that the upgrade of BIT is BIT (that is, (INTEGER 0 1)), and the upgrade of CHARACTER is CHARACTER. So, what is the upgrade of NIL, the empty type? It must be a subtype of both BIT and CHARACTER, but the only type with that property is NIL itself.
So, the standard requires there must be a specialized array type with element type NIL. That is, it cannot store any values at all.
* (typep #c(1 1) 'complex)
T
* (typep #c(1 0) 'complex)
NIL
* (typep #c(1.0 0) 'complex)
TThere's also a confusion between "subtype" and "recognizable subtype" (that is, something for which SUBTYPEP returns true as a second value). Subtype relations between SATISFIES types aren't even computable.
All this could have been worked through if the standardization process had continued, but commercial lisps ran out of steam to support the rather heavyweight standard making process.
(Also, just for onlookers, in ANSI Common Lisp, but not its ancestors or its sorta-sibling Emacs Lisp, characters are disjoint from integers. That's why the intersection of BIT and CHARACTER is empty.)
Here is why: an array is actually a function which maps an integer index to a value.
The element type of an array therefore a return value type of this function.
A "function returning SUP" is not a supertype of "function returning SUB".
NIL is a value in Lisp, no? So that means an array with element type NIL should be able to store exactly one value, whose index is NIL.
The Common Lisp type NIL has no elements; no value exists which has type NIL.
NULL is Common Lisp's null type (and so is correctly named).
The type named NIL is Common Lisp's bottom type. The top type is T.
This is pretty clever; they found another punning of NIL and T. Everything is of type T, and nothing is of type NIL.
Only NIL is of type NULL.
The existing, ancient function NULL that predates this type system becomes a type predicate. That is to say, when we evaluate the expression (NULL NIL), yielding true, it has a semantic interpretation as a type test! By testing whether its argument is the NIL object, it's also perpetrating whether the argument is of the NULL type. And so that type name jibes with the name of the ancient NULL function.
But when used as a type specifier, NIL denotes the empty set. So no Lisp object is of that type, and an array with that element type cannot store any object.
No value has type NIL.