Skip to main content
Log in

A decision procedure for common Lisp'sSUBTYPEP predicate

  • Published:
LISP and Symbolic Computation

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.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Aho, Alfred V., Sethi, Ravi, and Ullman, Jeffrey D.Compilers: Principles, Techniques, and Tools. Addison-Wesley, 1986.

  2. Baker, Henry G.The Nimble Type Inferencer for Common Lisp-84. Submitted to ACM Trans. on Prog. Langs. and Systems.

  3. Bauer, Alan M., and Saal, Harry J.Does APL really need run-time checking?. Software Practice and Experience, v.4, pp. 129–138, 1974.

    Google Scholar 

  4. 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.

  5. 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.

  6. Borning, Alan H. and Ingalls, Daniel H. H.A Type Declaration and Inference System for Smalltalk. ACM POPL 9, 133–141, 1982.

    Google Scholar 

  7. Budd, Timothy.An APL Compiler. Springer-Verlag, NY, 1988.

    Google Scholar 

  8. Church, A.Introduction to Mathematical Logic. Vol. I. Princeton University Press, 1956.

  9. 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.

    Google Scholar 

  10. Ferrante, J. and Geiser, J.An efficient decision procedure for the theory of rational order. Theor. Computer Sci. 4, 2, 227–234, 1977.

    Google Scholar 

  11. 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.

  12. Hughes, G.E., and Cresswell, M.J.An Introduction to Modal Logic. Methuen and Co., 1968.

  13. Kaplan, Marc A., and Ullman, Jeffrey D.A Scheme for the Automatic Inference of Variable Types JACM 27,1, 128–145, Jan. 1980.

    Google Scholar 

  14. 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.

    Google Scholar 

  15. Ma, Kwan-Liu, and Kessler, Robert R.TICL-A Type Inference System for Common Lisp SW-Prac.&Exper. 20,6, 593–623, June 1990.

    Google Scholar 

  16. MacLane, Saunders and Birkhoff, and Garrett.ALGEBRA. Macmillan, 1967.

  17. McAllester, David, and Zabih, Ramin.Boolean Classes. Proc. '86 OOPSLA, Sigplan Notices 21,11, 417–423, Nov. 1986.

    Google Scholar 

  18. Milner, Robin.A Theory of Type Polymorphism in Programming. JCSS 17, 348–375, 1978.

    Google Scholar 

  19. Morris, J.H.Types are Not Sets. ACM POPL, 120–124, 1973.

  20. Rackoff, C.W.The complexity of theories of the monadic predicate calculus. IRIA Rep. 136, Roquencourt, France, 1975.

    Google Scholar 

  21. Rees, J. and Clinger, W., et al.Revised Report on the Algorithmic Language Scheme. SIGPLAN Notices 21, 12, 37–79, Dec. 1986.

    Google Scholar 

  22. Reference Manual for the Ada Programming Language. ANSI/MILSTD-1815A-1983, US GPO, Wash, DC, 1983.

  23. Scott, D.Data types as lattices. SIAM J. Computing, 5,3, 522–587, Sept. 1976.

    Google Scholar 

  24. Steele, Guy L., Jr.Rabbit: A Compiler for SCHEME (A Study in Compiler Optimization) AI-TR-474, Artificial Intelligence Laboratory, MIT, May 1978.

  25. Steele, Guy L., Jr.Common Lisp: The Language. Digital Press, 1984.

  26. Steele, Guy L., Jr.Common Lisp: The Language, Second Edition. Digital Press, Bedford, MA, 1990.

    Google Scholar 

  27. Suzuki, Norihisa.Inferring Types in Smalltalk. ACM POPL 8, 187–199, 1981.

    Google Scholar 

  28. Tarski, A.A Decision Method for Elementary Algebra and Geometry. 2nd ed., Univ. of Cal. Press, Berkeley, 1951.

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Additional information

This work was supported in part by the U.S. Department of Energy Contract No. DE-AC03-88ER80663.

Rights and permissions

Reprints 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

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF01807504

Keywords

Navigation