An implementation of the Common Lisp type system.
This system is an implementation of the Common Lisp type system; particularly
specifier-ctype takes a type specifier and environment as input, and returns a "ctype": a reified representation of a type, independent of any environment. Ctypes are a precise reflection of their input specifier, i.e. information independent of the environment is not lost. They are however simplified as much as possible, so they will not reflect redundant information in the specifier. For example,
(and list cons) and
cons are interpreted as the same ctype.
subctypep functions implement
cl:subtypep, except that they take ctype objects as arguments, rather than type specifiers. Then the CL functions could be defined as
(defun typep (object type-specifier &optional environment) (ctypep object (specifier-ctype type-specifier environment))) (defun subtypep (type-specifier-1 type-specifier-2 &optional environment) (subctypep (specifier-ctype type-specifier-1 environment) (specifier-ctype type-specifier-2 environment)))
conjoin can be used to compute functions of ctypes. They are analogous to the compound type specifiers
bot return the top ctype and bottom ctype (
bot-p determine whether a given ctype is the top or the bottom ctype, respectively.
This system is intended for use in an implementation of
subtypep, and so does not use
cl:subtypep at all. Unfortunately, not all aspects of the type system on a given Lisp system are determinable with standard means without using
subtypep, and must be manually configured per implementation. See config/ for more information.
Currently, the following Lisps are supported:
Ctypes are of class
ctype. Various subclasses of
ctype implement kinds of types in the CL type system. The following subclasses are defined by the system:
cclass: a ctype representing a class. The class may be read with the
negation: The negation of its
disjunction: Represents uses of the
or(resp.) type specifier that could not be further simplified.
junction-ctypesreturns a list of the ctypes it is a con/disjunction of.
ccons: A cons type.
range: A range of real numbers.
range-kindis one of
range-high-exclusive-pread the properties of the range.
ccomplex-ucptreads the upgraded complex part type, which is either the symbol
cl:*, or something returned by
cmember-membersreturns a list of the objects of the type.
carray: An array type.
:complexaccordingly; array types including both are represented as disjunctions.
carray-uaetreads the upgraded array element type.
carray-dimsreads the dimension specification, which is a
dimension-specas accepted by the
cl:arraycompound type specifier.
charset: A subtype of
charset-pairsreads the description of the codes included, which is as described above for
+standard-charset+in the configuration section.
Additional classes may be defined by the programmer.
subctypep must be implemented for subclasses of
ctype in order for those functions to work correctly.
subctypep should return the result of
(call-next-method) if they cannot determine a conclusive answer, i.e. if they would return
(values nil nil). This ensures that all applicable methods can have a shot at giving a definitive answer.
A method on
unparse must be defined for ctypes to print correctly.
unparse should return a type specifier that could specify the given ctype. This is only used for display purposes, so it doesn't have strict requirements.
The additional generic functions
subtract may also need methods in order for
specifier-ctype to work correctly. Particularly, if the conjunction of two types is recognizably (with
subctypep) the bottom type,
conjoin/2 must return
disjointp must return definite truth, and similarly with disjunction and
disjointphas the same return value convention as
subtypep, and similarly, methods should use
call-next-methodif the answer cannot be determined.
disjointpcan be used to determine if two ctypes are completely disjoint:
(disjointp (specifier-ctype x) (specifier-ctype y))is equivalent to
(subctypep (conjoin (specifier-ctype x) (specifier-ctype y)) (specifier-ctype nil)).
negatecomputes the negation of a ctype, i.e. if a ctype is specified by
(negate that-ctype)is specified by
(not x). The default method makes a
negationctype. These ctypes do not provide enough information for all functions to work well, e.g. they may result in
nil nilanswers from
subctypep. As such, if the negation of a type can be expressed in a better way, a specializing method on
negateshould be defined.
disjoin/2are the two-argument functions underlying
disjoinrespectively. If no special behavior is defined,
disjunctiontypes, which do not always provide enough information for precise answers from
subtract, given ctypes specified by
y, may compute the ctype specified by
(and x (not y)). If no special behavior is defined with a method, a
conjunctionctype will be made, which is suboptimal.