
Common Lisp Object System Specification 1. Programmer Interface Concepts Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated: June 15, 1988 All Rights Reserved The distribution and publication of this document are not restricted. In order to preserve the integrity of the specification, any publication or distribution must reproduce this document in its entirety, preserve its formatting, and include this title page. For information about obtaining the sources for this document, send an Internet message to common-lisp-object-system-specifi[email protected]. The authors wish to thank Patrick Dussud, Kenneth Kahn, Jim Kempf, Larry Masinter, Mark Stefik, Daniel L. Weinreb, and Jon L White for their contributions to this document. At the X3J13 meeting on June 15, 1988, the following motion was adopted: “The X3J13 Committee hereby accepts chapters 1 and 2 of the Common Lisp Object System, as defined in document 88-002R, for inclusion in the Common Lisp language being specified by this committee. Subsequent changes will be handled through the usual editorial and cleanup processes.” Programmer Interface Concepts 1–1 CONTENTS Introduction ................................................................... 1–3 Error Terminology ............................................................... 1–4 Classes ....................................................................... 1–6 Defining Classes ............................................................... 1–7 Creating Instances of Classes ..................................................... 1–8 Slots ....................................................................... 1–8 Accessing Slots ............................................................... 1–9 Inheritance ................................................................... 1–10 Inheritance of Methods ......................................................... 1–10 Inheritance of Slots and Slot Options .............................................. 1–10 Inheritance of Class Options ..................................................... 1–11 Examples .................................................................. 1–12 Integrating Types and Classes ..................................................... 1–13 Determining the Class Precedence List ............................................... 1–16 Topological Sorting ........................................................... 1–16 Examples .................................................................. 1–17 Generic Functions and Methods .................................................... 1–19 Introduction to Generic Functions ................................................. 1–19 Introduction to Methods ....................................................... 1–20 Agreement on Parameter Specializers and Qualifiers ................................... 1–22 Congruent Lambda-Lists for All Methods of a Generic Function ........................... 1–23 Keyword Arguments in Generic Functions and Methods ................................. 1–23 Method Selection and Combination .................................................. 1–25 Determining the Effective Method ................................................. 1–25 Selecting the Applicable Methods ............................................... 1–25 Sorting the Applicable Methods by Precedence Order ................................ 1–25 Applying Method Combination to the Sorted List of Applicable Methods .................. 1–26 Standard Method Combination ................................................... 1–27 Declarative Method Combination ................................................. 1–29 Built-in Method Combination Types ............................................... 1–29 Meta-Objects .................................................................. 1–31 Metaclasses ................................................................. 1–31 Standard Metaclasses .......................................................... 1–31 Standard Meta-objects ......................................................... 1–31 Object Creation and Initialization ................................................... 1–33 Initialization Arguments ........................................................ 1–34 Declaring the Validity of Initialization Arguments ..................................... 1–34 Defaulting of Initialization Arguments .............................................. 1–35 Rules for Initialization Arguments ................................................. 1–36 Shared-Initialize .............................................................. 1–37 Initialize-Instance ............................................................. 1–38 Definitions of Make-Instance and Initialize-Instance .................................... 1–39 Redefining Classes .............................................................. 1–41 Modifying the Structure of Instances ............................................... 1–41 1–2 Common Lisp Object System Specification Initializing Newly Added Local Slots ............................................... 1–42 Customizing Class Redefinition ................................................... 1–42 Extensions .................................................................. 1–43 Changing the Class of an Instance .................................................. 1–44 Modifying the Structure of the Instance ............................................ 1–44 Initializing Newly Added Local Slots ............................................... 1–44 Customizing the Change of Class of an Instance ...................................... 1–45 Reinitializing an Instance ......................................................... 1–46 Customizing Reinitialization ..................................................... 1–46 Programmer Interface Concepts 1–3 1–4 Common Lisp Object System Specification Introduction The Common Lisp Object System is an object-oriented extension to Common Lisp as defined in Common Lisp: The Language, by Guy L. Steele Jr. It is based on generic functions, multiple inheritance, declarative method combination, and a meta-object protocol. The first two chapters of this specification present a description of the standard Programmer Interface for the Common Lisp Object System. The first chapter contains a description of the concepts of the Common Lisp Object System, and the second contains a description of the functions and macros in the Common Lisp Object System Programmer Interface. The chapter “The Common Lisp Object System Meta-Object Protocol” describes how the Common Lisp Object System can be customized. The fundamental objects of the Common Lisp Object System are classes, instances, generic functions, and methods. A class object determines the structure and behavior of a set of other objects, which are called its instances. Every Common Lisp object is an instance of a class. The class of an object determines the set of operations that can be performed on the object. A generic function is a function whose behavior depends on the classes or identities of the arguments supplied to it. A generic function object contains a set of methods, a lambda-list, a method combination type, and other information. The methods define the class-specific behavior and operations of the generic function; a method is said to specialize a generic function. When invoked, a generic function executes a subset of its methods based on the classes of its arguments. A generic function can be used in the same ways that an ordinary function can be used in Com- mon Lisp; in particular, a generic function can be used as an argument to funcall and apply and can be given a global or a local name. A method is an object that contains a method function, a sequence of parameter specializers that specify when the given method is applicable, and a sequence of qualifiers that is used by the method combination facility to distinguish among methods. Each required formal parameter of each method has an associated parameter specializer, and the method will be invoked only on arguments that satisfy its parameter specializers. The method combination facility controls the selection of methods, the order in which they are run, and the values that are returned by the generic function. The Common Lisp Object System offers a default method combination type and provides a facility for declaring new types of method combination. Programmer Interface Concepts 1–5 Error Terminology The terminology used in this document to describe erroneous situations differs from the termi- nology used in Common Lisp: The Language, by Guy L. Steele Jr. This terminology involves situations; a situation is the evaluation of an expression in some specific context. For example, a situation might be the invocation of a function on arguments that fail to satisfy some specified constraints. In the specification of the Common Lisp Object System, the behavior of programs in all situations is described, and the options available to the implementor are defined. No implementation is allowed to extend the syntax or semantics of the Object System except as explicitly defined in the Object System specification. In particular, no implementation is allowed to extend the syntax of the Object System in such a way that ambiguity between the specified syntax of Object System and those extensions is possible. “When situation S occurs, an error is signaled.” This terminology has the following meaning: • If this situation occurs,
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages48 Page
-
File Size-