Abstract
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 of SUBTYPEP fail 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.
Similar content being viewed by others
References
Aho, Alfred V., Sethi, Ravi, and Ullman, Jeffrey D.Compilers: Principles, Techniques, and Tools. Addison-Wesley, 1986.
Baker, Henry G.The Nimble Type Inferencer for Common Lisp-84. Submitted to ACM Trans. on Prog. Langs. and Systems.
Bauer, Alan M., and Saal, Harry J.Does APL really need run-time checking?. Software Practice and Experience, v.4, pp. 129–138, 1974.
Beer, Randall D.The compile-time type inference and type checking of Common Lisp programs: a technical summary. TR 88–116, Ctr. for Automation and Intelligent Sys. Research, Case Western Reserve Univ., May 1988.
Bobrow, et al.Common Lisp Object System Specification X3J13. ACM SIGPLAN Notices, v.23, Sept. 1988; also Lisp and Symbolic Computation 1, 3–4, 245–394; also X3J13 Document 88-002R, June 1988.
Borning, Alan H. and Ingalls, Daniel H. H.A Type Declaration and Inference System for Smalltalk. ACM POPL 9, 133–141, 1982.
Budd, Timothy.An APL Compiler. Springer-Verlag, NY, 1988.
Church, A.Introduction to Mathematical Logic. Vol. I. Princeton University Press, 1956.
Ferrante, J., and Rackoff, C.A decision procedure for the first order theory of real addition with order. SIAM J. Comput. 4, 1, 69–76, 1975.
Ferrante, J. and Geiser, J.An efficient decision procedure for the theory of rational order. Theor. Computer Sci. 4, 2, 227–234, 1977.
Floating-Point Working Group 754 of the Microprocessor Standards Committee. newblockA Standard for Binary Floating-Point Arithmetic. IEEE, 345 E. 47th St., New York, NY 10017, 1982.
Hughes, G.E., and Cresswell, M.J.An Introduction to Modal Logic. Methuen and Co., 1968.
Kaplan, Marc A., and Ullman, Jeffrey D.A Scheme for the Automatic Inference of Variable Types JACM 27,1, 128–145, Jan. 1980.
Loos, R.Computing in Algebraic Extensions In Buchberger, et al. Computer Algebra: Symbolic and Algebraic Computation, Second Edition. Springer-Verlag, New York, 173–187, 1983.
Ma, Kwan-Liu, and Kessler, Robert R.TICL-A Type Inference System for Common Lisp SW-Prac.&Exper. 20,6, 593–623, June 1990.
MacLane, Saunders and Birkhoff, and Garrett.ALGEBRA. Macmillan, 1967.
McAllester, David, and Zabih, Ramin.Boolean Classes. Proc. '86 OOPSLA, Sigplan Notices 21,11, 417–423, Nov. 1986.
Milner, Robin.A Theory of Type Polymorphism in Programming. JCSS 17, 348–375, 1978.
Morris, J.H.Types are Not Sets. ACM POPL, 120–124, 1973.
Rackoff, C.W.The complexity of theories of the monadic predicate calculus. IRIA Rep. 136, Roquencourt, France, 1975.
Rees, J. and Clinger, W., et al.Revised Report on the Algorithmic Language Scheme. SIGPLAN Notices 21, 12, 37–79, Dec. 1986.
Reference Manual for the Ada Programming Language. ANSI/MILSTD-1815A-1983, US GPO, Wash, DC, 1983.
Scott, D.Data types as lattices. SIAM J. Computing, 5,3, 522–587, Sept. 1976.
Steele, Guy L., Jr.Rabbit: A Compiler for SCHEME (A Study in Compiler Optimization) AI-TR-474, Artificial Intelligence Laboratory, MIT, May 1978.
Steele, Guy L., Jr.Common Lisp: The Language. Digital Press, 1984.
Steele, Guy L., Jr.Common Lisp: The Language, Second Edition. Digital Press, Bedford, MA, 1990.
Suzuki, Norihisa.Inferring Types in Smalltalk. ACM POPL 8, 187–199, 1981.
Tarski, A.A Decision Method for Elementary Algebra and Geometry. 2nd ed., Univ. of Cal. Press, Berkeley, 1951.
Author information
Authors and Affiliations
Additional information
This work was supported in part by the U.S. Department of Energy Contract No. DE-AC03-88ER80663.
Rights and permissions
About this article
Cite this article
Baker, H.G. A decision procedure for common Lisp'sSUBTYPEP predicate. Lisp and Symbolic Computation 5, 157–190 (1992). https://doi.org/10.1007/BF01807504
Issue Date:
DOI: https://doi.org/10.1007/BF01807504