128 lines
5.5 KiB
HTML
128 lines
5.5 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<!-- This manual documents Guile version 3.0.10.
|
||
|
|
||
|
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
|
||
|
Inc.
|
||
|
|
||
|
Copyright (C) 2021 Maxime Devos
|
||
|
|
||
|
Copyright (C) 2024 Tomas Volf
|
||
|
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with no
|
||
|
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
|
||
|
copy of the license is included in the section entitled "GNU Free
|
||
|
Documentation License." -->
|
||
|
<title>Inheritance (Guile Reference Manual)</title>
|
||
|
|
||
|
<meta name="description" content="Inheritance (Guile Reference Manual)">
|
||
|
<meta name="keywords" content="Inheritance (Guile Reference Manual)">
|
||
|
<meta name="resource-type" content="document">
|
||
|
<meta name="distribution" content="global">
|
||
|
<meta name="Generator" content=".texi2any-real">
|
||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
|
|
||
|
<link href="index.html" rel="start" title="Top">
|
||
|
<link href="Concept-Index.html" rel="index" title="Concept Index">
|
||
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
||
|
<link href="GOOPS.html" rel="up" title="GOOPS">
|
||
|
<link href="Introspection.html" rel="next" title="Introspection">
|
||
|
<link href="Methods-and-Generic-Functions.html" rel="prev" title="Methods and Generic Functions">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
span:hover a.copiable-link {visibility: visible}
|
||
|
-->
|
||
|
</style>
|
||
|
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en">
|
||
|
<div class="section-level-extent" id="Inheritance">
|
||
|
<div class="nav-panel">
|
||
|
<p>
|
||
|
Next: <a href="Introspection.html" accesskey="n" rel="next">Introspection</a>, Previous: <a href="Methods-and-Generic-Functions.html" accesskey="p" rel="prev">Methods and Generic Functions</a>, Up: <a href="GOOPS.html" accesskey="u" rel="up">GOOPS</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<h3 class="section" id="Inheritance-1"><span>8.7 Inheritance<a class="copiable-link" href="#Inheritance-1"> ¶</a></span></h3>
|
||
|
|
||
|
<p>Here are some class definitions to help illustrate inheritance:
|
||
|
</p>
|
||
|
<div class="example lisp">
|
||
|
<pre class="lisp-preformatted">(define-class A () a)
|
||
|
(define-class B () b)
|
||
|
(define-class C () c)
|
||
|
(define-class D (A B) d a)
|
||
|
(define-class E (A C) e c)
|
||
|
(define-class F (D E) f)
|
||
|
</pre></div>
|
||
|
|
||
|
<p><code class="code">A</code>, <code class="code">B</code>, <code class="code">C</code> have a null list of superclasses. In this
|
||
|
case, the system will replace the null list by a list which only
|
||
|
contains <code class="code"><object></code>, the root of all the classes defined by
|
||
|
<code class="code">define-class</code>. <code class="code">D</code>, <code class="code">E</code>, <code class="code">F</code> use multiple
|
||
|
inheritance: each class inherits from two previously defined classes.
|
||
|
Those class definitions define a hierarchy which is shown in
|
||
|
<a class="ref" href="#fig_003ahier">Figure 8.2</a>. In this figure, the class <code class="code"><top></code> is also shown;
|
||
|
this class is the superclass of all Scheme objects. In particular,
|
||
|
<code class="code"><top></code> is the superclass of all standard Scheme
|
||
|
types.
|
||
|
</p>
|
||
|
<div class="float" id="fig_003ahier">
|
||
|
<pre class="verbatim"> <top>
|
||
|
/ \\\_____________________
|
||
|
/ \\___________ \
|
||
|
/ \ \ \
|
||
|
<object> <pair> <procedure> <number>
|
||
|
/ | \ |
|
||
|
/ | \ |
|
||
|
A B C <complex>
|
||
|
|\__/__ | |
|
||
|
\ / \ / |
|
||
|
D E <real>
|
||
|
\ / |
|
||
|
F |
|
||
|
<integer>
|
||
|
</pre>
|
||
|
<div class="caption"><p><strong class="strong">Figure 8.2: </strong>A class hierarchy.</p></div></div>
|
||
|
<p>When a class has superclasses, its set of slots is calculated by taking
|
||
|
the union of its own slots and those of all its superclasses. Thus each
|
||
|
instance of D will have three slots, <code class="code">a</code>, <code class="code">b</code> and
|
||
|
<code class="code">d</code>). The slots of a class can be discovered using the
|
||
|
<code class="code">class-slots</code> primitive. For instance,
|
||
|
</p>
|
||
|
<div class="example lisp">
|
||
|
<pre class="lisp-preformatted">(class-slots A) ⇒ ((a))
|
||
|
(class-slots E) ⇒ ((a) (e) (c))
|
||
|
(class-slots F) ⇒ ((e) (c) (b) (d) (a) (f))
|
||
|
</pre></div>
|
||
|
|
||
|
<p>The ordering of the returned slots is not significant.
|
||
|
</p>
|
||
|
|
||
|
|
||
|
<ul class="mini-toc">
|
||
|
<li><a href="Class-Precedence-List.html" accesskey="1">Class Precedence List</a></li>
|
||
|
<li><a href="Sorting-Methods.html" accesskey="2">Sorting Methods</a></li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<div class="nav-panel">
|
||
|
<p>
|
||
|
Next: <a href="Introspection.html">Introspection</a>, Previous: <a href="Methods-and-Generic-Functions.html">Methods and Generic Functions</a>, Up: <a href="GOOPS.html">GOOPS</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|