Common Lisp [25],[26] includes a dynamic datatype system of moderate complexity, as well as predicates for checking the types of language objects. Additionally, an interesting predicate of two “type specifiers”—SUBTYPEP—is included in the language. Thissubtypep predicate provides a mechanism with which to query the Common Lisp type system regarding containment relations among the various built-in and user-defined types. Whilesubtypep is rarely needed by an applications programmer, the efficiency of a Common Lisp implementation can depend critically upon the quality of itssubtypep predicate: the run-time system typically calls uponsubtypep to decide what sort of representations to use when making arrays; the compiler calls uponsubtypep to interpret userdeclarations, on which efficient data representation and code generation decisions are based.As might be expected due to the complexity of the Common Lisp type system, there may be type containment questions which cannot be decided. In these casessubtypep is expected to return “can't determine”, in order to avoid giving an incorrect answer. Unfortunately, most Common Lisp implementations have abused this license by answering “can't determine” in all but the most trivial cases.In particular, most Common Lisp implementations ofSUBTYPEPfail on the basic axioms of the Common Lisp type system itself [25][26]. This situation is particularly embarrassing for Lisp-the premier “symbol processing language”—in which the implementation of complex symbolic logical operations should be relatively easy. Sincesubtypep was presumably included in Common Lisp to answer thehard cases of type containment, this “lazy evaluation” limits the usefulness of an important language feature.This paper shows how those type containment relations of Common Lisp which can be decided at all, can be decided simply and quickly by a decision procedure which can dramatically reduce the number of occurrences of the “can't determine” answer fromsubtypep. This decision procedure doesnot require the conversion of a type specifier expression to conjunctive or disjunctive normal form, and therefore does not incur the exponential explosion in space and time that such a conversion would entail.The lattice mechanism described here for decidingsubtypep is also ideal for performingtype inference [2]; the particular implementation developed here, however, is specific to the type system of Common Lisp [4].Categories and Subject Descriptors: Lisp, dynamic typing, compiler optimization, type inference, decision procedure.
[1]
T G Muchnick,et al.
On some extensions of syntactic error recovery technique based on phrase markers
,
1986,
SIGP.
[2]
Jeffrey D. Ullman,et al.
A Scheme for the Automatic Inference of Variable Types
,
1980,
JACM.
[3]
Kwan-Liu Ma,et al.
TICL—A type inference system for Common Lisp
,
1990,
Softw. Pract. Exp..
[4]
Dana S. Scott,et al.
Data Types as Lattices
,
1976,
SIAM J. Comput..
[5]
Ramin Zabih,et al.
Boolean classes
,
1986,
OOPSLA 1986.
[6]
Jr. Guy L. Steele,et al.
Common LISP: the language (2nd ed.)
,
1990
.
[7]
Alonzo Church,et al.
Introduction to Mathematical Logic
,
1991
.
[8]
James H. Morris,et al.
Types are not sets
,
1973,
POPL.
[9]
Guy L. Steele,et al.
Common Lisp the Language
,
1984
.
[10]
Robin Milner,et al.
A Theory of Type Polymorphism in Programming
,
1978,
J. Comput. Syst. Sci..
[11]
Henry Ledgard,et al.
Reference Manual for the ADA® Programming Language
,
1983,
Springer New York.
[12]
D. H. Bartley,et al.
Revised4 report on the algorithmic language scheme
,
1991,
LIPO.
[13]
Norihisa Suzuki,et al.
Inferring types in Smalltalk
,
1981,
POPL '81.
[14]
Alan Borning,et al.
A type declaration and inference system for smalltalk
,
1982,
POPL '82.
[15]
Jeanne Ferrante,et al.
A Decision Procedure for the First Order Theory of Real Addition with Order
,
1975,
SIAM J. Comput..
[16]
R. Loos.
Computing in Algebraic Extensions
,
1983
.
[17]
Elliott Mendelson,et al.
Introduction to Mathematical Logic
,
1979
.
[18]
Alan M. Bauer,et al.
Does APL really need run‐time checking?
,
1974,
Softw. Pract. Exp..
[19]
James R. Geiser,et al.
An Efficient Decision Procedure for the Theory of Rational Order
,
1977,
Theor. Comput. Sci..
[20]
Timothy Budd,et al.
An APL Compiler
,
1987,
Springer New York.
[21]
A. Tarski.
A Decision Method for Elementary Algebra and Geometry
,
2023
.
[22]
Max J. Cresswell,et al.
A New Introduction to Modal Logic
,
1998
.