1
0
Fork 0
cl-sites/lisp-docs.github.io/cl-language-reference/chap-4/e-d-classes.html

144 lines
92 KiB
HTML
Raw Normal View History

2024-03-13 23:00:32 +01:00
<!doctype html>
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-chap-4/e-d-classes" data-has-hydrated="false">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v3.0.1">
<title data-rh="true">4.3 Classes | Common Lisp (New) Language Reference</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" name="twitter:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" property="og:url" content="https://lisp-docs.github.io/cl-language-reference/chap-4/e-d-classes"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="google-site-verification" content="Vzaw013_bfdKeUVG89Ch3W1zC9_vH9ID2dPB9Dz0vr0"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="4.3 Classes | Common Lisp (New) Language Reference"><meta data-rh="true" name="description" content="4.3.1 Introduction to Classes"><meta data-rh="true" property="og:description" content="4.3.1 Introduction to Classes"><link data-rh="true" rel="icon" href="../img/favicon.ico"><link data-rh="true" rel="canonical" href="e-d-classes.html"><link data-rh="true" rel="alternate" href="e-d-classes.html" hreflang="en"><link data-rh="true" rel="alternate" href="e-d-classes.html" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://C1F2Q5VM6X-dsn.algolia.net" crossorigin="anonymous"><link rel="preconnect" href="https://www.google-analytics.com">
<link rel="preconnect" href="https://www.googletagmanager.com">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-8TJCE4NSF8"></script>
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-8TJCE4NSF8",{})</script>
<link rel="search" type="application/opensearchdescription+xml" title="Common Lisp (New) Language Reference" href="../opensearch.xml"><link rel="stylesheet" href="../assets/css/styles.f13b59fe.css">
<script src="../assets/js/runtime~main.02699c25.js" defer="defer"></script>
<script src="../assets/js/main.4f0a7a76.js" defer="defer"></script>
</head>
<body class="navigation-with-keyboard">
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="e-d-classes.html#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a href="../../index.html" target="_blank" rel="noopener noreferrer" class="navbar__brand"><div class="navbar__logo"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div><b class="navbar__title text--truncate">Common Lisp Docs</b></a><a href="../../docs/tutorial/index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Tutorial</a><a href="../index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Technical Reference</a><a href="../../docs/whylisp.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Why Lisp?</a><a href="../../docs/howto.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Guides</a></div><div class="navbar__items navbar__items--right"><a href="../../docs/contribute.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Contribute!</a><a href="../../docs/help.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Getting Help</a><a href="../../docs/about.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">About</a><a href="../../blog.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Blog</a><a href="https://github.com/lisp-docs" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.
<!-- -->
<p>While the object system is general enough to describe all <em>standardized classes</em> (including, for example, <span><b>number</b></span>, <span><b>hash-table</b></span>, and <span><b>symbol</b></span>), Figure 47 contains a list of <em>classes</em> that are especially relevant to understanding the object system.</p>
<p>|<strong>built-in-class method-combination standard-object class standard-class structure-class generic-function standard-generic-function structure-object method standard-method</strong>|</p>
<p>| :- |</p>
<p><strong>Figure 47. Object System Classes</strong></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="431-introduction-to-classes">4.3.1 Introduction to Classes<a href="e-d-classes.html#431-introduction-to-classes" class="hash-link" aria-label="Direct link to 4.3.1 Introduction to Classes" title="Direct link to 4.3.1 Introduction to Classes"></a></h2>
<!-- -->
<p>A <span><i>class</i></span> is an <span><i>object</i></span> that determines the structure and behavior of a set of other <span><i>objects</i></span>, which are called its <span><i>instances</i></span>.</p>
<p>A <span><i>class</i></span> can inherit structure and behavior from other <em>classes</em>. A <span><i>class</i></span> whose definition refers to other <em>classes</em> for the purpose of inheriting from them is said to be a <span><i>subclass</i></span> of each of those <em>classes</em>. The <em>classes</em> that are designated for purposes of inheritance are said to be <em>superclasses</em> of the inheriting <span><i>class</i></span>.</p>
<p>A <span><i>class</i></span> can have a <span><i>name</i></span>. The <span><i>function</i></span> <span><b>class-name</b></span> takes a <em>class object</em> and returns its <span><i>name</i></span>. The <span><i>name</i></span> of an anonymous <span><i>class</i></span> is <span><b>nil</b></span>. A <span><i>symbol</i></span> can <span><i>name</i></span> a <span><i>class</i></span>. The <span><i>function</i></span> <span><b>find-class</b></span> takes a <span><i>symbol</i></span> and returns the <span><i>class</i></span> that the <span><i>symbol</i></span> names. A <span><i>class</i></span> has a <span><i>proper name</i></span> if the <span><i>name</i></span> is a <span><i>symbol</i></span> and if the <span><i>name</i></span> of the <span><i>class</i></span> names that <span><i>class</i></span>. That is, a <em>class C</em> has the <em>proper name S</em> if <em>S</em> = (class-name <em>C</em>) and <em>C</em> = (find-class <em>S</em>). Notice that it is possible for (find-class <em>S</em><sub>1</sub>) = (find-class <em>S</em><sub>2</sub>) and <em>S</em><sub>1</sub> <em>6</em>= <em>S</em><sub>2</sub>. If <em>C</em> = (find-class <em>S</em>), we say that <em>C</em> is the <em>class named S</em>.</p>
<p>A <i>class C</i><sub>1</sub> is a <i>direct superclass</i> of a <i>class C</i><sub>2</sub> if <i>C</i><sub>2</sub> explicitly designates <i>C</i><sub>1</sub> as a <i>superclass</i> in its definition. In this case <i>C</i><sub>2</sub> is a <i>direct subclass</i> of <i>C</i><sub>1</sub>. A <i>class C<sub>n</sub></i> is a <i>superclass</i> of a <i>class C</i><sub>1</sub> if there exists a series of <i>classes C</i><sub>2</sub><i>, . . . , C<sub>n</sub></i>1 such that <i>C<sub>i</sub></i>+1 is a <i>direct superclass</i> of <i>C<sub>i</sub></i> for 1 <i>≤ i</i> &lt; <i>n</i>. In this case, <i>C</i><sub>1</sub> is a <i>subclass</i> of <i>C<sub>n</sub></i>. A <i>class</i> is considered neither a <i>superclass</i> nor a <i>subclass</i> of</p>
<p>itself. That is, if <em>C</em><sub>1</sub> is a <span><i>superclass</i></span> of <em>C</em><sub>2</sub>, then <em>C</em><sub>1</sub> <em>6</em>= <em>C</em><sub>2</sub>. The set of <em>classes</em> consisting of some given <em>class C</em> along with all of its <em>superclasses</em> is called “<em>C</em> and its superclasses.”</p>
<p>Each <span><i>class</i></span> has a <span><i>class precedence list</i></span>, which is a total ordering on the set of the given <span><i>class</i></span> and its <em>superclasses</em>. The total ordering is expressed as a list ordered from most specific to least specific. The <span><i>class precedence list</i></span> is used in several ways. In general, more specific <em>classes</em> can <span><i>shadow</i></span><sub>1</sub> features that would otherwise be inherited from less specific <em>classes</em>. The <span><i>method</i></span> selection and combination process uses the <span><i>class precedence list</i></span> to order <span><i>methods</i></span> from most specific to least specific.</p>
<p>When a <span><i>class</i></span> is defined, the order in which its direct <em>superclasses</em> are mentioned in the defining</p>
<p>form is important. Each <span><i>class</i></span> has a <span><i>local precedence order</i></span>, which is a <span><i>list</i></span> consisting of the <span><i>class</i></span> followed by its <em>direct superclasses</em> in the order mentioned in the defining <span><i>form</i></span>.</p>
<p>A <span><i>class precedence list</i></span> is always consistent with the <span><i>local precedence order</i></span> of each <span><i>class</i></span> in the list. The <em>classes</em> in each <span><i>local precedence order</i></span> appear within the <span><i>class precedence list</i></span> in the same order. If the <span><i>local precedence orders</i></span> are inconsistent with each other, no <span><i>class precedence list</i></span> can be constructed, and an error is signaled. The <span><i>class precedence list</i></span> and its computation is discussed in Section 4.3.5 (Determining the Class Precedence List).</p>
<p><em>classes</em> are organized into a directed acyclic graph. There are two distinguished <em>classes</em>, named <span><b>t</b></span> and <span><b>standard-object</b></span>. The <span><i>class</i></span> named <span><b>t</b></span> has no <em>superclasses</em>. It is a <span><i>superclass</i></span> of every <span><i>class</i></span> except itself. The <span><i>class</i></span> named <span><b>standard-object</b></span> is an <span><i>instance</i></span> of the <span><i>class</i></span> <span><b>standard-class</b></span> and is a <span><i>superclass</i></span> of every <span><i>class</i></span> that is an <span><i>instance</i></span> of the <span><i>class</i></span> <span><b>standard-class</b></span> except itself.</p>
<p>There is a mapping from the object system <span><i>class</i></span> space into the <span><i>type</i></span> space. Many of the standard <span><i>types</i></span> specified in this document have a corresponding <span><i>class</i></span> that has the same <span><i>name</i></span> as the <span><i>type</i></span>. Some <span><i>types</i></span> do not have a corresponding <span><i>class</i></span>. The integration of the <span><i>type</i></span> and <span><i>class</i></span> systems is discussed in Section 4.3.7 (Integrating Types and Classes).</p>
<p><em>Classes</em> are represented by <span><i>objects</i></span> that are themselves <span><i>instances</i></span> of <em>classes</em>. The <span><i>class</i></span> of the <span><i>class</i></span> of an <span><i>object</i></span> is termed the <span><i>metaclass</i></span> of that <span><i>object</i></span>. When no misinterpretation is possible, the term <span><i>metaclass</i></span> is used to refer to a <span><i>class</i></span> that has <span><i>instances</i></span> that are themselves <em>classes</em>. The <span><i>metaclass</i></span> determines the form of inheritance used by the <em>classes</em> that are its <span><i>instances</i></span> and the representation of the <span><i>instances</i></span> of those <em>classes</em>. The object system provides a default <span><i>metaclass</i></span>, <span><b>standard-class</b></span>, that is appropriate for most programs.</p>
<p>Except where otherwise specified, all <em>classes</em> mentioned in this standard are <span><i>instances</i></span> of the <span><i>class</i></span> <span><b>standard-class</b></span>, all <span><i>generic functions</i></span> are <span><i>instances</i></span> of the <span><i>class</i></span> <span><b>standard-generic-function</b></span>, and all <span><i>methods</i></span> are <span><i>instances</i></span> of the <span><i>class</i></span> <span><b>standard-method</b></span>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4311-standard-metaclasses">4.3.1.1 Standard Metaclasses<a href="e-d-classes.html#4311-standard-metaclasses" class="hash-link" aria-label="Direct link to 4.3.1.1 Standard Metaclasses" title="Direct link to 4.3.1.1 Standard Metaclasses"></a></h3>
<!-- -->
<p>The object system provides a number of predefined <em>metaclasses</em>. These include the <em>classes</em> <span><b>standard-class</b></span>, <span><b>built-in-class</b></span>, and <span><b>structure-class</b></span>:</p>
<p><em></em> The <span><i>class</i></span> <span><b>standard-class</b></span> is the default <span><i>class</i></span> of <em>classes</em> defined by <span><b>defclass</b></span>.</p>
<p><em></em> The <span><i>class</i></span> <span><b>built-in-class</b></span> is the <span><i>class</i></span> whose <span><i>instances</i></span> are <em>classes</em> that have special implementations with restricted capabilities. Any <span><i>class</i></span> that corresponds to a standard <span><i>type</i></span> might be an <span><i>instance</i></span> of <span><b>built-in-class</b></span>. The predefined <span><i>type</i></span> specifiers that are required to have corresponding <em>classes</em> are listed in Figure 48. It is <span><i>implementation-dependent</i></span> whether each of these <em>classes</em> is implemented as a <span><i>built-in class</i></span>.</p>
<p><em></em> All <em>classes</em> defined by means of <span><b>defstruct</b></span> are <span><i>instances</i></span> of the <span><i>class</i></span> <span><b>structure-class</b></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="432-defining-classes">4.3.2 Defining Classes<a href="e-d-classes.html#432-defining-classes" class="hash-link" aria-label="Direct link to 4.3.2 Defining Classes" title="Direct link to 4.3.2 Defining Classes"></a></h2>
<!-- -->
<p>The macro <span><b>defclass</b></span> is used to define a new named <span><i>class</i></span>.</p>
<p>The definition of a <span><i>class</i></span> includes:</p>
<p><em></em> The <span><i>name</i></span> of the new <span><i>class</i></span>. For newly-defined <em>classes</em> this <span><i>name</i></span> is a <span><i>proper name</i></span>. <em></em> The list of the direct <em>superclasses</em> of the new <span><i>class</i></span>.</p>
<p><em></em> A set of <span><i>slot specifiers</i></span>. Each <span><i>slot specifier</i></span> includes the <span><i>name</i></span> of the <span><i>slot</i></span> and zero or more <span><i>slot</i></span> options. A <span><i>slot</i></span> option pertains only to a single <span><i>slot</i></span>. If a <span><i>class</i></span> definition contains two <span><i>slot specifiers</i></span> with the same <span><i>name</i></span>, an error is signaled.</p>
<p><em></em> A set of <span><i>class</i></span> options. Each <span><i>class</i></span> option pertains to the <span><i>class</i></span> as a whole.</p>
<p>The <span><i>slot</i></span> options and <span><i>class</i></span> options of the <span><b>defclass</b></span> form provide mechanisms for the following: <em></em> Supplying a default initial value <span><i>form</i></span> for a given <span><i>slot</i></span>.</p>
<p><em></em> Requesting that <span><i>methods</i></span> for <span><i>generic functions</i></span> be automatically generated for reading or writing <span><i>slots</i></span>.</p>
<p><em></em> Controlling whether a given <span><i>slot</i></span> is shared by all <span><i>instances</i></span> of the <span><i>class</i></span> or whether each <span><i>instance</i></span> of the <span><i>class</i></span> has its own <span><i>slot</i></span>.</p>
<p><em></em> Supplying a set of initialization arguments and initialization argument defaults to be used in <span><i>instance</i></span> creation.</p>
<p><em></em> Indicating that the <span><i>metaclass</i></span> is to be other than the default. The <!-- -->:metaclass<!-- --> option is reserved for future use; an implementation can be extended to make use of the <!-- -->:metaclass<!-- --> option.</p>
<p><em></em> Indicating the expected <span><i>type</i></span> for the value stored in the <span><i>slot</i></span>.</p>
<p><em></em> Indicating the <span><i>documentation string</i></span> for the <span><i>slot</i></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="433-creating-instances-of-classes">4.3.3 Creating Instances of Classes<a href="e-d-classes.html#433-creating-instances-of-classes" class="hash-link" aria-label="Direct link to 4.3.3 Creating Instances of Classes" title="Direct link to 4.3.3 Creating Instances of Classes"></a></h2>
<!-- -->
<p>The generic function <span><b>make-instance</b></span> creates and returns a new <span><i>instance</i></span> of a <span><i>class</i></span>. The object system provides several mechanisms for specifying how a new <span><i>instance</i></span> is to be initialized. For example, it is possible to specify the initial values for <span><i>slots</i></span> in newly created <span><i>instances</i></span> either by giving arguments to <span><b>make-instance</b></span> or by providing default initial values. Further initialization</p>
<p>activities can be performed by <span><i>methods</i></span> written for <span><i>generic functions</i></span> that are part of the initialization protocol. The complete initialization protocol is described in Section 7.1 (Object Creation and Initialization).</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="434-inheritance">4.3.4 Inheritance<a href="e-d-classes.html#434-inheritance" class="hash-link" aria-label="Direct link to 4.3.4 Inheritance" title="Direct link to 4.3.4 Inheritance"></a></h2>
<!-- -->
<p>A <span><i>class</i></span> can inherit <span><i>methods</i></span>, <span><i>slots</i></span>, and some <span><b>defclass</b></span> options from its <em>superclasses</em>. Other sections describe the inheritance of <span><i>methods</i></span>, the inheritance of <span><i>slots</i></span> and <span><i>slot</i></span> options, and the inheritance of <span><i>class</i></span> options.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4341-examples-of-inheritance">4.3.4.1 Examples of Inheritance<a href="e-d-classes.html#4341-examples-of-inheritance" class="hash-link" aria-label="Direct link to 4.3.4.1 Examples of Inheritance" title="Direct link to 4.3.4.1 Examples of Inheritance"></a></h3>
<!-- -->
<div class="language-lisp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-lisp codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> C1 </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">S1</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:initform</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">5.4</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:type</span><span class="token plain"> number</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">S2</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:allocation</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:class</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> C2 </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">C1</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">S1</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:initform</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">5</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:type</span><span class="token plain"> integer</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">S2</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:allocation</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:instance</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">S3</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:accessor</span><span class="token plain"> C2-S3</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" sty
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4342-inheritance-of-class-options">4.3.4.2 Inheritance of Class Options<a href="e-d-classes.html#4342-inheritance-of-class-options" class="hash-link" aria-label="Direct link to 4.3.4.2 Inheritance of Class Options" title="Direct link to 4.3.4.2 Inheritance of Class Options"></a></h3>
<!-- -->
<p>The <!-- -->:default-initargs<!-- --> class option is inherited. The set of defaulted initialization arguments for a <span><i>class</i></span> is the union of the sets of initialization arguments supplied in the <!-- -->:default-initargs<!-- --> class options of the <span><i>class</i></span> and its <em>superclasses</em>. When more than one default initial value <span><i>form</i></span> is supplied</p>
<p>for a given initialization argument, the default initial value <span><i>form</i></span> that is used is the one supplied by the <span><i>class</i></span> that is most specific according to the <span><i>class precedence list</i></span>.</p>
<p>If a given <!-- -->:default-initargs<!-- --> class option specifies an initialization argument of the same <span><i>name</i></span> more than once, an error of <span><i>type</i></span> <span><b>program-error</b></span> is signaled.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="435-determining-the-class-precedence-list">4.3.5 Determining the Class Precedence List<a href="e-d-classes.html#435-determining-the-class-precedence-list" class="hash-link" aria-label="Direct link to 4.3.5 Determining the Class Precedence List" title="Direct link to 4.3.5 Determining the Class Precedence List"></a></h2>
<!-- -->
<p>The <span><b>defclass</b></span> form for a <span><i>class</i></span> provides a total ordering on that <span><i>class</i></span> and its direct <em>superclasses</em>. This ordering is called the <span><i>local precedence order</i></span>. It is an ordered list of the <span><i>class</i></span> and its direct <em>superclasses</em>. The <span><i>class precedence list</i></span> for a class <em>C</em> is a total ordering on <em>C</em> and its <em>superclasses</em> that is consistent with the <span><i>local precedence orders</i></span> for each of <em>C</em> and its <em>superclasses</em>.</p>
<p>A <span><i>class</i></span> precedes its direct <em>superclasses</em>, and a direct <span><i>superclass</i></span> precedes all other direct <em>superclasses</em> specified to its right in the <em>superclasses</em> list of the <span><b>defclass</b></span> form. For every class <em>C</em>, define</p>
<p><i>R<sub>C</sub></i> = <i>{</i>(<i>C, C</i><sub>1</sub>)<i>,</i>(<i>C</i><sub>1</sub><i>, C</i><sub>2</sub>)<i>, . . . ,</i>(<i>C<sub>n</sub></i>1<i>, C<sub>n</sub></i>)<i>}</i></p>
<p>where <i>C</i><sub>1</sub><i>, . . . , C<sub>n</sub></i> are the direct <i>superclasses</i> of <i>C</i> in the order in which they are mentioned in the <b>defclass</b> form. These ordered pairs generate the total ordering on the class <i>C</i> and its direct <i>superclasses</i>.</p>
<p>Let <i>S<sub>C</sub></i> be the set of <i>C</i> and its <i>superclasses</i>. Let <i>R</i> be</p>
<i>R<sub>c</sub></i>
<p>.</p>
<p><sub><i>R</i> =</sub>[ <i>c∈S<sub>C</sub></i></p>
<p>The set <i>R</i> might or might not generate a partial ordering, depending on whether the <i>R<sub>c</sub></i>, <i>c ∈ S<sub>C</sub></i> , are consistent; it is assumed that they are consistent and that <i>R</i> generates a partial ordering. When the <i>R<sub>c</sub></i> are not consistent, it is said that <i>R</i> is inconsistent.</p>
<p>To compute the <i>class precedence list</i> for <i>C</i>, topologically sort the elements of <i>S<sub>C</sub></i> with respect to the partial ordering generated by <i>R</i>. When the topological sort must select a <i>class</i> from a set of two or more <i>classes</i>, none of which are preceded by other <i>classes</i> with respect to <i>R</i>, the <i>class</i> selected is chosen deterministically, as described below.</p>
<p>If <em>R</em> is inconsistent, an error is signaled.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4351-topological-sorting">4.3.5.1 Topological Sorting<a href="e-d-classes.html#4351-topological-sorting" class="hash-link" aria-label="Direct link to 4.3.5.1 Topological Sorting" title="Direct link to 4.3.5.1 Topological Sorting"></a></h3>
<!-- -->
<p>Topological sorting proceeds by finding a class <i>C</i> in <i>S<sub>C</sub></i> such that no other <i>class</i> precedes that element according to the elements in <i>R</i>. The class <i>C</i> is placed first in the result. Remove <i>C</i> from <i>S<sub>C</sub></i> , and remove all pairs of the form (<i>C, D</i>), <i>D ∈ S<sub>C</sub></i> , from <i>R</i>. Repeat the process, adding <i>classes</i> with no predecessors to the end of the result. Stop when no element can be found that has no predecessor.</p>
<p>If <i>S<sub>C</sub></i> is not empty and the process has stopped, the set <i>R</i> is inconsistent. If every <i>class</i> in the finite set of <i>classes</i> is preceded by another, then <i>R</i> contains a loop. That is, there is a chain of classes <i>C</i><sub>1</sub><i>, . . . , C<sub>n</sub></i> such that <i>C<sub>i</sub></i> precedes <i>C<sub>i</sub></i>+1, 1 <i>≤ i</i> &lt; <i>n</i>, and <i>C<sub>n</sub></i> precedes <i>C</i><sub>1</sub>.</p>
<p>Sometimes there are several <i>classes</i> from <i>S<sub>C</sub></i> with no predecessors. In this case select the one that has a direct <i>subclass</i> rightmost in the <i>class precedence list</i> computed so far. (If there is no such candidate <i>class</i>, <i>R</i> does not generate a partial ordering—the <i>R<sub>c</sub></i>, <i>c ∈ S<sub>C</sub></i> , are inconsistent.)</p>
<p>In more precise terms, let <i>{N</i><sub>1</sub><i>, . . . , N<sub>m</sub>}</i>, <i>m ≥</i> 2, be the <i>classes</i> from <i>S<sub>C</sub></i> with no predecessors. Let (<i>C</i><sub>1</sub> <i>. . . C<sub>n</sub></i>), <i>n ≥</i> 1, be the <i>class precedence list</i> constructed so far. <i>C</i><sub>1</sub> is the most specific <i>class</i>, and <i>C<sub>n</sub></i> is the least specific. Let 1 <i>≤ j ≤ n</i> be the largest number such that there exists an <i>i</i> where 1 <i>≤ i ≤ m</i> and <i>N<sub>i</sub></i>is a direct <i>superclass</i> of <i>C<sub>j</sub></i> ; <i>N<sub>i</sub></i>is placed next.</p>
<p>The effect of this rule for selecting from a set of <em>classes</em> with no predecessors is that the <em>classes</em> in a simple <span><i>superclass</i></span> chain are adjacent in the <span><i>class precedence list</i></span> and that <em>classes</em> in each relatively separated subgraph are adjacent in the <span><i>class precedence list</i></span>. For example, let <span><i>T</i></span><sub>1</sub> and <span><i>T</i></span><sub>2</sub> be subgraphs whose only element in common is the class <em>J</em>. Suppose that no superclass of <em>J</em> appears in either <span><i>T</i></span><sub>1</sub> or <span><i>T</i></span><sub>2</sub>, and that <em>J</em> is in the superclass chain of every class in both <span><i>T</i></span><sub>1</sub> and <span><i>T</i></span><sub>2</sub>. Let <em>C</em><sub>1</sub> be the bottom of <span><i>T</i></span><sub>1</sub>; and let <em>C</em><sub>2</sub> be the bottom of <span><i>T</i></span><sub>2</sub>. Suppose <em>C</em> is a <span><i>class</i></span> whose direct <em>superclasses</em> are <em>C</em><sub>1</sub> and <em>C</em><sub>2</sub> in that order, then the <span><i>class precedence list</i></span> for <em>C</em> starts with <em>C</em> and is followed by all <em>classes</em> in <span><i>T</i></span><sub>1</sub> except <em>J</em>. All the <em>classes</em> of <span><i>T</i></span><sub>2</sub> are next. The <em>class J</em> and its <em>superclasses</em> appear last.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4352-examples-of-class-precedence-list-determination">4.3.5.2 Examples of Class Precedence List Determination<a href="e-d-classes.html#4352-examples-of-class-precedence-list-determination" class="hash-link" aria-label="Direct link to 4.3.5.2 Examples of Class Precedence List Determination" title="Direct link to 4.3.5.2 Examples of Class Precedence List Determination"></a></h3>
<!-- -->
<div class="language-lisp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-lisp codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">This example determines a *class precedence list* for the class pie. The following *classes* are defined: </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> pie </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">apple</span><span class="token plain"> cinnamon</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> apple </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">fruit</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> cinnamon </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">spice</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> fruit </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">food</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> spice </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">food</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">defclass</span><span class="token plain"> food </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class=
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="436-redefining-classes">4.3.6 Redefining Classes<a href="e-d-classes.html#436-redefining-classes" class="hash-link" aria-label="Direct link to 4.3.6 Redefining Classes" title="Direct link to 4.3.6 Redefining Classes"></a></h2>
<!-- -->
<p>A <span><i>class</i></span> that is a <span><i>direct instance</i></span> of <span><b>standard-class</b></span> can be redefined if the new <span><i>class</i></span> is also a <span><i>direct instance</i></span> of <span><b>standard-class</b></span>. Redefining a <span><i>class</i></span> modifies the existing <em>class object</em> to reflect the new <span><i>class</i></span> definition; it does not create a new <em>class object</em> for the <span><i>class</i></span>. Any <em>method object</em> created by a <!-- -->:reader<!-- -->, <!-- -->:writer<!-- -->, or <!-- -->:accessor<!-- --> option specified by the old <span><b>defclass</b></span> form is removed from the corresponding <span><i>generic function</i></span>. <span><i>Methods</i></span> specified by the new <span><b>defclass</b></span> form are added.</p>
<p>When the class <em>C</em> is redefined, changes are propagated to its <span><i>instances</i></span> and to <span><i>instances</i></span> of any of its <em>subclasses</em>. Updating such an <span><i>instance</i></span> occurs at an <span><i>implementation-dependent</i></span> time, but no later than the next time a <span><i>slot</i></span> of that <span><i>instance</i></span> is read or written. Updating an <span><i>instance</i></span> does not change its identity as defined by the <span><i>function</i></span> <span><b>eq</b></span>. The updating process may change the <span><i>slots</i></span> of that particular <span><i>instance</i></span>, but it does not create a new <span><i>instance</i></span>. Whether updating an <span><i>instance</i></span> consumes storage is <span><i>implementation-dependent</i></span>.</p>
<p>Note that redefining a <span><i>class</i></span> may cause <span><i>slots</i></span> to be added or deleted. If a <span><i>class</i></span> is redefined in a way that changes the set of <em>local slots accessible</em> in <span><i>instances</i></span>, the <span><i>instances</i></span> are updated. It is <span><i>implementation-dependent</i></span> whether <span><i>instances</i></span> are updated if a <span><i>class</i></span> is redefined in a way that does not change the set of <em>local slots accessible</em> in <span><i>instances</i></span>.</p>
<p>The value of a <span><i>slot</i></span> that is specified as shared both in the old <span><i>class</i></span> and in the new <span><i>class</i></span> is retained. If such a <span><i>shared slot</i></span> was unbound in the old <span><i>class</i></span>, it is unbound in the new <span><i>class</i></span>. <span><i>Slots</i></span> that were local in the old <span><i>class</i></span> and that are shared in the new <span><i>class</i></span> are initialized. Newly added <span><i>shared slots</i></span> are initialized.</p>
<p>Each newly added <span><i>shared slot</i></span> is set to the result of evaluating the <span><i>captured initialization form</i></span> for the <span><i>slot</i></span> that was specified in the <span><b>defclass</b></span> <span><i>form</i></span> for the new <span><i>class</i></span>. If there was no <span><i>initialization form</i></span>, the <span><i>slot</i></span> is unbound.</p>
<p>If a <span><i>class</i></span> is redefined in such a way that the set of <em>local slots accessible</em> in an <span><i>instance</i></span> of the <span><i>class</i></span> is changed, a two-step process of updating the <span><i>instances</i></span> of the <span><i>class</i></span> takes place. The process may be explicitly started by invoking the generic function <span><b>make-instances-obsolete</b></span>. This two-step process can happen in other circumstances in some implementations. For example, in some implementations this two-step process is triggered if the order of <span><i>slots</i></span> in storage is changed.</p>
<p>The first step modifies the structure of the <span><i>instance</i></span> by adding new <span><i>local slots</i></span> and discarding <span><i>local slots</i></span> that are not defined in the new version of the <span><i>class</i></span>. The second step initializes the newly-added <span><i>local slots</i></span> and performs any other user-defined actions. These two steps are further specified in the next two sections.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4361-modifying-the-structure-of-instances">4.3.6.1 Modifying the Structure of Instances<a href="e-d-classes.html#4361-modifying-the-structure-of-instances" class="hash-link" aria-label="Direct link to 4.3.6.1 Modifying the Structure of Instances" title="Direct link to 4.3.6.1 Modifying the Structure of Instances"></a></h3>
<!-- -->
<p>The first step modifies the structure of <span><i>instances</i></span> of the redefined <span><i>class</i></span> to conform to its new <span><i>class</i></span> definition. <span><i>Local slots</i></span> specified by the new <span><i>class</i></span> definition that are not specified as either local or shared by the old <span><i>class</i></span> are added, and <span><i>slots</i></span> not specified as either local or shared by the new <span><i>class</i></span> definition that are specified as local by the old <span><i>class</i></span> are discarded. The <span><i>names</i></span> of these added and discarded <span><i>slots</i></span> are passed as arguments to <strong>update-instance-for-redefined-class</strong> as described in</p>
<p>the next section.</p>
<p>The values of <span><i>local slots</i></span> specified by both the new and old <em>classes</em> are retained. If such a <span><i>local slot</i></span> was unbound, it remains unbound.</p>
<p>The value of a <span><i>slot</i></span> that is specified as shared in the old <span><i>class</i></span> and as local in the new <span><i>class</i></span> is retained. If such a <span><i>shared slot</i></span> was unbound, the <span><i>local slot</i></span> is unbound.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4362-initializing-newly-added-local-slots">4.3.6.2 Initializing Newly Added Local Slots<a href="e-d-classes.html#4362-initializing-newly-added-local-slots" class="hash-link" aria-label="Direct link to 4.3.6.2 Initializing Newly Added Local Slots" title="Direct link to 4.3.6.2 Initializing Newly Added Local Slots"></a></h3>
<!-- -->
<p>The second step initializes the newly added <span><i>local slots</i></span> and performs any other user-defined actions. This step is implemented by the generic function <strong>update-instance-for-redefined-class</strong>, which is called after completion of the first step of modifying the structure of the <span><i>instance</i></span>.</p>
<p>The generic function <strong>update-instance-for-redefined-class</strong> takes four required arguments: the <span><i>instance</i></span> being updated after it has undergone the first step, a list of the names of <span><i>local slots</i></span> that were added, a list of the names of <span><i>local slots</i></span> that were discarded, and a property list containing the <span><i>slot</i></span> names and values of <span><i>slots</i></span> that were discarded and had values. Included among the discarded <span><i>slots</i></span> are <span><i>slots</i></span> that were local in the old <span><i>class</i></span> and that are shared in the new <span><i>class</i></span>.</p>
<p>The generic function <strong>update-instance-for-redefined-class</strong> also takes any number of initialization arguments. When it is called by the system to update an <span><i>instance</i></span> whose <span><i>class</i></span> has been redefined, no initialization arguments are provided.</p>
<p>There is a system-supplied primary <span><i>method</i></span> for <strong>update-instance-for-redefined-class</strong> whose <span><i>parameter specializer</i></span> for its <span><i>instance</i></span> argument is the <span><i>class</i></span> <span><b>standard-object</b></span>. First this <span><i>method</i></span> checks the validity of initialization arguments and signals an error if an initialization argument is supplied that is not declared as valid. (For more information, see Section 7.1.2 (Declaring the Validity of Initialization Arguments).) Then it calls the generic function <span><b>shared-initialize</b></span> with the following arguments: the <span><i>instance</i></span>, the list of <span><i>names</i></span> of the newly added <span><i>slots</i></span>, and the initialization arguments it received.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4363-customizing-class-redefinition">4.3.6.3 Customizing Class Redefinition<a href="e-d-classes.html#4363-customizing-class-redefinition" class="hash-link" aria-label="Direct link to 4.3.6.3 Customizing Class Redefinition" title="Direct link to 4.3.6.3 Customizing Class Redefinition"></a></h3>
<!-- -->
<p><span><i>Methods</i></span> for <strong>update-instance-for-redefined-class</strong> may be defined to specify actions to be taken when an <span><i>instance</i></span> is updated. If only <span><i>after methods</i></span> for <strong>update-instance-for-redefined-class</strong> are defined, they will be run after the system-supplied primary <span><i>method</i></span> for initialization and therefore will not interfere with the default behavior of <strong>update-instance-for-redefined-class</strong>. Because no initialization arguments are passed to <strong>update-instance-for-redefined-class</strong> when it is called by the system, the <span><i>initialization forms</i></span> for <span><i>slots</i></span> that are filled by <span><i>before methods</i></span> for <strong>update-instance-for-redefined-class</strong> will not be evaluated by <span><b>shared-initialize</b></span>.</p>
<p><span><i>Methods</i></span> for <span><b>shared-initialize</b></span> may be defined to customize <span><i>class</i></span> redefinition. For more information, see Section 7.1.5 (Shared-Initialize).</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="437-integrating-types-and-classes">4.3.7 Integrating Types and Classes<a href="e-d-classes.html#437-integrating-types-and-classes" class="hash-link" aria-label="Direct link to 4.3.7 Integrating Types and Classes" title="Direct link to 4.3.7 Integrating Types and Classes"></a></h2>
<!-- -->
<!-- -->
<p>The object system maps the space of <em>classes</em> into the space of <span><i>types</i></span>. Every <span><i>class</i></span> that has a proper name has a corresponding <span><i>type</i></span> with the same <span><i>name</i></span>.</p>
<p>The proper name of every <span><i>class</i></span> is a valid <span><i>type specifier</i></span> . In addition, every <em>class object</em> is a valid <span><i>type specifier</i></span> . Thus the expression (typep <em>object class</em>) evaluates to <span><i>true</i></span> if the <span><i>class</i></span> of <span><i>object</i></span> is <span><i>class</i></span> itself or a <span><i>subclass</i></span> of <span><i>class</i></span>. The evaluation of the expression (subtypep class1 class2) returns the values <span><i>true</i></span> and <span><i>true</i></span> if class1 is a subclass of class2 or if they are the same <span><i>class</i></span>; otherwise it returns the values <span><i>false</i></span> and <span><i>true</i></span>. If <em>I</em> is an <span><i>instance</i></span> of some <em>class C</em> named <em>S</em> and <em>C</em></p>
<p>is an <span><i>instance</i></span> of <span><b>standard-class</b></span>, the evaluation of the expression (type-of <em>I</em>) returns <em>S</em> if <em>S</em> is the <span><i>proper name</i></span> of <em>C</em>; otherwise, it returns <em>C</em>.</p>
<p>Because the names of <em>classes</em> and <em>class objects</em> are <span><i>type specifiers</i></span>, they may be used in the special form <span><b>the</b></span> and in type declarations.</p>
<p>Many but not all of the predefined <span><i>type specifiers</i></span> have a corresponding <span><i>class</i></span> with the same proper name as the <span><i>type</i></span>. These type specifiers are listed in Figure 48. For example, the <span><i>type</i></span> <span><b>array</b></span> has a corresponding <span><i>class</i></span> named <span><b>array</b></span>. No <span><i>type specifier</i></span> that is a list, such as (vector double-float 100), has a corresponding <span><i>class</i></span>. The <span><i>operator</i></span> <span><b>deftype</b></span> does not create any <em>classes</em>.</p>
<p>Each <span><i>class</i></span> that corresponds to a predefined <span><i>type specifier</i></span> can be implemented in one of three ways, at the discretion of each implementation. It can be a <span><i>standard class</i></span>, a <span><i>structure class</i></span>, or a <span><i>system class</i></span>.</p>
<p>A <span><i>built-in class</i></span> is one whose <span><i>generalized instances</i></span> have restricted capabilities or special representations. Attempting to use <span><b>defclass</b></span> to define <em>subclasses</em> of a <span><b>built-in-class</b></span> signals an error. Calling <span><b>make-instance</b></span> to create a <span><i>generalized instance</i></span> of a <span><i>built-in class</i></span> signals an error. Calling <span><b>slot-value</b></span> on a <span><i>generalized instance</i></span> of a <span><i>built-in class</i></span> signals an error. Redefining a <span><i>built-in class</i></span> or using <span><b>change-class</b></span> to change the <span><i>class</i></span> of an <span><i>object</i></span> to or from a <span><i>built-in class</i></span> signals an error. However, <em>built-in classes</em> can be used as <span><i>parameter specializers</i></span> in <span><i>methods</i></span>.</p>
<p>It is possible to determine whether a <span><i>class</i></span> is a <span><i>built-in class</i></span> by checking the <span><i>metaclass</i></span>. A <span><i>standard class</i></span> is an <span><i>instance</i></span> of the <span><i>class</i></span> <span><b>standard-class</b></span>, a <span><i>built-in class</i></span> is an <span><i>instance</i></span> of the <span><i>class</i></span> <span><b>built-in-class</b></span>, and a <span><i>structure class</i></span> is an <span><i>instance</i></span> of the <span><i>class</i></span> <span><b>structure-class</b></span>.</p>
<p>Each <em>structure type</em> created by <span><b>defstruct</b></span> without using the <!-- -->:type<!-- --> option has a corresponding <span><i>class</i></span>. This <span><i>class</i></span> is a <span><i>generalized instance</i></span> of the <span><i>class</i></span> <span><b>structure-class</b></span>. The <!-- -->:include<!-- --> option of <span><b>defstruct</b></span> creates a direct <span><i>subclass</i></span> of the <span><i>class</i></span> that corresponds to the included <em>structure type</em>.</p>
<p>It is <span><i>implementation-dependent</i></span> whether <span><i>slots</i></span> are involved in the operation of <span><i>functions</i></span> defined in this specification on <span><i>instances</i></span> of <em>classes</em> defined in this specification, except when <span><i>slots</i></span> are explicitly defined by this specification.</p>
<p>If in a particular <span><i>implementation</i></span> a <span><i>class</i></span> defined in this specification has <span><i>slots</i></span> that are not defined by this specfication, the names of these <span><i>slots</i></span> must not be <span><i>external symbols</i></span> of <span><i>packages</i></span> defined in this specification nor otherwise <span><i>accessible</i></span> in the CL-USER <span><i>package</i></span>.</p>
<p>The purpose of specifying that many of the standard <span><i>type specifiers</i></span> have a corresponding <span><i>class</i></span> is to enable users to write <span><i>methods</i></span> that discriminate on these <span><i>types</i></span>. <span><i>Method</i></span> selection requires that a <span><i>class precedence list</i></span> can be determined for each <span><i>class</i></span>.</p>
<p>The hierarchical relationships among the <span><i>type specifiers</i></span> are mirrored by relationships among the <em>classes</em> corresponding to those <span><i>types</i></span>.</p>
<p>Figure 48 lists the set of <em>classes</em> that correspond to predefined <span><i>type specifiers</i></span>.</p>
<p>|</p><p><strong>arithmetic-error generic-function simple-error array hash-table simple-type-error bit-vector integer simple-warning broadcast-stream list standard-class built-in-class logical-pathname standard-generic-function cell-error method standard-method character method-combination standard-object class null storage-condition complex number stream</strong> </p><p><strong>concatenated-stream package stream-error condition package-error string</strong> </p><p><strong>cons parse-error string-stream control-error pathname structure-class division-by-zero print-not-readable structure-object echo-stream program-error style-warning end-of-file random-state symbol</strong> </p><p><strong>error ratio synonym-stream file-error rational t</strong> </p><p><strong>file-stream reader-error two-way-stream float readtable type-error floating-point-inexact real unbound-slot floating-point-invalid-operation restart unbound-variable floating-point-overflow sequence undefined-function floating-point-underflow serious-condition vector</strong> </p><p><strong>function simple-condition warning</strong></p>|<p></p>
<p>| :- |</p>
<p><strong>Figure 48. Classes that correspond to pre-defined type specifiers</strong></p>
<p>The <span><i>class precedence list</i></span> information specified in the entries for each of these <em>classes</em> are those that are required by the object system.</p>
<p>Individual implementations may be extended to define other type specifiers to have a corresponding <span><i>class</i></span>. Individual implementations may be extended to add other <span><i>subclass</i></span> relationships and to add other <span><i>elements</i></span> to the <span><i>class precedence lists</i></span> as long as they do not violate the type relationships and disjointness requirements specified by this standard. A standard <span><i>class</i></span> defined with no direct <em>superclasses</em> is guaranteed to be disjoint from all of the <em>classes</em> in the table, except for the class named <span><b>t</b></span>.</p></div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/lisp-docs/cl-language-reference/tree/main/docs/chap-4/e-d-classes.md" target="_blank" rel="noopener noreferrer" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col lastUpdated_vwxv"><span class="theme-last-updated">Last updated<!-- --> by <b>daninus14</b></span></div></div></footer></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href="e-c-types.html"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">4.2 Types</div></a><a class="pagination-nav__link pagination-nav__link--next" href="../category/44-types-and-classes-dictionary.html"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">4.4 Types and Classes Dictionary</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="e-d-classes.html#431-introduction-to-classes" class="table-of-contents__link toc-highlight">4.3.1 Introduction to Classes</a><ul><li><a href="e-d-classes.html#4311-standard-metaclasses" class="table-of-contents__link toc-highlight">4.3.1.1 Standard Metaclasses</a></li></ul></li><li><a href="e-d-classes.html#432-defining-classes" class="table-of-contents__link toc-highlight">4.3.2 Defining Classes</a></li><li><a href="e-d-classes.html#433-creating-instances-of-classes" class="table-of-contents__link toc-highlight">4.3.3 Creating Instances of Classes</a></li><li><a href="e-d-classes.html#434-inheritance" class="table-of-contents__link toc-highlight">4.3.4 Inheritance</a><ul><li><a href="e-d-classes.html#4341-examples-of-inheritance" class="table-of-contents__link toc-highlight">4.3.4.1 Examples of Inheritance</a></li><li><a href="e-d-classes.html#4342-inheritance-of-class-options" class="table-of-contents__link toc-highlight">4.3.4.2 Inheritance of Class Options</a></li></ul></li><li><a href="e-d-classes.html#435-determining-the-class-precedence-list" class="table-of-contents__link toc-highlight">4.3.5 Determining the Class Precedence List</a><ul><li><a href="e-d-classes.html#4351-topological-sorting" class="table-of-contents__link toc-highlight">4.3.5.1 Topological Sorting</a></li><li><a href="e-d-classes.html#4352-examples-of-class-precedence-list-determination" class="table-of-contents__link toc-highlight">4.3.5.2 Examples of Class Precedence List Determination</a></li></ul></li><li><a href="e-d-classes.html#436-redefining-classes" class="table-of-contents__link toc-highlight">4.3.6 Redefining Classes</a><ul><li><a href="e-d-classes.html#4361-modifying-the-structure-of-instances" class="table-of-contents__link toc-highlight">4.3.6.1 Modifying the Structure of Instances</a></li><li><a href="e-d-classes.html#4362-initializing-newly-added-local-slots" class="table-of-contents__link toc-highlight">4.3.6.2 Initializing Newly Added Local Slots</a></li><li><a href="e-d-classes.html#4363-customizin
</body>
</html>