Debian Codegraph @

docsrc/xlisp/xlisp-doc/reference/keyword-new.htm

raw
1 <html><head><title>XLISP :new</title>
2
3 <link rel="stylesheet" type="text/css" href="reference.css">
4
5 </head>
6
7 <body>
8
9 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
10 <a href="../manual/contents.htm">Contents</a> |
11 <a href="../tutorials/tutorials.htm">Tutorials</a> |
12 <a href="../examples/examples.htm">Examples</a> |
13 <a href="reference-index.htm">Reference</a>
14
15 <hr>
16
17 <h1>:new</h1>
18
19 <hr>
20
21 <p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
22 <tr valign="top">
23 <td><nobr>Type:</nobr></td>
24 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
25 <td width="100%"><nobr>message selector</nobr></td>
26 </tr>
27 <tr valign="top">
28 <td><nobr>Source:</nobr></td>
29 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
30 <td width="100%"><nobr>xlobj.c</nobr></td>
31 </tr>
32 </tbody></table></p>
33
34 <h2>Syntax</h2>
35
36 <dl>
37 <dt>(send <i>class</i> :new <i>args</i>)</dt>
38 <dd><i>class</i> - an existing XLISP class except for <a href="class.htm">class</a><br>
39 <i>args</i> - the initializing arguments for the new instance<br>
40 returns - the new class object</dd>
41 </dl>
42
43 <dl>
44 <dt>(send class :new <i>ivars</i> [<i>cvars</i> [<i>superclass</i>]])</dt>
45 <dd><i>ivars</i> - list of instance variables for new class<br>
46 <i>cvars</i> - list of class variable symbols for new class<br>
47 <i>superclass</i> - superclass for new object, the default is <a href="object.htm">object</a><br>
48 returns - the new class object</dd>
49 </dl>
50
51 <h2>Description</h2>
52
53 <p>The ':new' message selector exhibits two different behaviors. When you
54 are creating an instance of a <a href="class.htm">class</a> you
55 only need the ':new' message [consisting of the message selector and any
56 data]. When you are creating a new <a href="class.htm">class</a>
57 with ':new', you need to specify instance variables and optionally the
58 <a href="class.htm">class</a> variables and superclass.</p>
59
60 <h2>Examples</h2>
61
62 <pre class="example">
63 (setq new-class (send class :new '(state))) <font color="#008844">; create NEW-CLASS with STATE</font>
64 (setq new-obj (send new-class :new)) <font color="#008844">; create NEW-OBJ of NEW-CLASS</font>
65 (send new-obj :show) <font color="#008844">; shows the object</font>
66
67 (setq sub-class (send class :new '(sub-state) <font color="#008844">; create SUB-CLASS of NEW-CLASS</font>
68 '() new-class))
69 (send sub-class :show) <font color="#008844">; show the SUB-CLASS</font>
70 </pre>
71
72 <p>See the
73 <a href="../manual/xlisp-man-010.htm#class-new">:new</a>
74 message selector in the <nobr>XLISP 2.0</nobr> manual.</p>
75
76 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</nobr></a></p>
77
78 <hr>
79
80 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
81 <a href="../manual/contents.htm">Contents</a> |
82 <a href="../tutorials/tutorials.htm">Tutorials</a> |
83 <a href="../examples/examples.htm">Examples</a> |
84 <a href="reference-index.htm">Reference</a>
85
86 </body></html>