emacs.d/clones/lisp/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node272.html

50 lines
2.3 KiB
HTML
Raw Normal View History

2022-08-26 19:11:35 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>28.1.3.4. Examples</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Examples">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html5058 HREF="node273.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5056 HREF="node268.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5052 HREF="node271.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5060 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5061 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5059 HREF="node273.html"> Integrating Types and </A>
<B>Up:</B> <A NAME=tex2html5057 HREF="node268.html"> Inheritance</A>
<B> Previous:</B> <A NAME=tex2html5053 HREF="node271.html"> Inheritance of Class </A>
<HR> <P>
<H3><A NAME=SECTION003213400000000000000>28.1.3.4. Examples</A></H3>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
<P><pre>
(defclass C1 ()
((S1 :initform 5.4 :type number)
(S2 :allocation :class)))
(defclass C2 (C1)
((S1 :initform 5 :type integer)
(S2 :allocation :instance)
(S3 :accessor C2-S3)))
</pre><P>
<P>
Instances of the class <tt>C1</tt> have a local slot named <tt>S1</tt>, whose default
initial value is 5.4 and whose value should always be a number.
The class <tt>C1</tt> also has a shared slot named <tt>S2</tt>.
<P>
There is a local slot named <tt>S1</tt> in instances of <tt>C2</tt>. The
default initial value of <tt>S1</tt> is 5. The value of <tt>S1</tt> will be
of type <tt>(and integer number)</tt>. There are also local slots named
<tt>S2</tt> and <tt>S3</tt> in instances of <tt>C2</tt>. The class <tt>C2</tt>
has a method for <tt>C2-S3</tt> for reading the value of slot <tt>S3</tt>;
there is also a method for <tt>(setf C2-S3)</tt> that writes the
value of <tt>S3</tt>.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>