-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimpleExtension.html
72 lines (69 loc) · 3.13 KB
/
simpleExtension.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<link REL=stylesheet HREF=Rtech.css>
<title>Simple Class Extensions</title>
</head>
<body>
<h1>Simple Class Extensions</h1>
A class <code>C<sub>2</sub></code> is defined to be a simple extension of a
class <code>C<sub>1</sub></code> if the two classes are related by a simple
<code>setIs</code> call:
<code><pre>
setIs(<code>C<sub>2</sub></code>, <code>C<sub>1</sub></code>)
</pre></code>
Simple extensions happen in two ways:<p>
<ol>
<li> Implicitly, by <code>C<sub>1</sub></code> being included in the
representation of <code>C<sub>2</sub></code>, in which case no
explicit call to <code>setIs</code> is needed;<p>
<li> Explicitly, by a call to <code>setIs</code>, in which case
<code>C<sub>1</sub></code> must either be a virtual class or included
in <code>C<sub>2</sub></code> (in the sense of both having the same
definition for all the slots of <code>C<sub>1</sub></code>).
</ol>
<p>
In the current version of R (1.5.0 and later), simple extensions are
used in formal method dispatch without transforming the actual
argument.
That is, if a method exists corresponding to class <code>C<sub>1</sub></code>
for some argument, and the actual argument has class
<code>C<sub>2</sub></code>, then the method can be selected. If it is, the
method will be called with an untransformed argument (still class
<code>C<sub>2</sub></code>, not the defined class).
<p>
We are considering applying the same convention to slot assignments.
Suppose a slot is assigned, say
<code><pre>
z@type <- x
</pre></code>
If the slot was defined to have class <code>C<sub>1</sub></code> and
<code>x</code> has class <code>C<sub>2</sub></code>, the assignment would
succeed and <code>x</code> would be stored in the slot, untransformed.
<p>
The same rule would apply to named arguments supplied to the function
<code>new</code>, assuming the class had no special
<code>initialize</code> method defined.
<p>
There are a few details to note:<p>
<ul>
<li> Possibilities 1 and 2 are the <i>only</i> valid simple calls to
<code>setIs</code>, because otherwise the two class
representations conflict, so a <code>coerce=</code> argument
must be supplied to <code>setIs</code>.<p>
<li> Simple extensions are transitive: if <i>C<sub>3</sub></i> is a
simple extension of <i>C<sub>2</sub></i>, it is also a simple
extension of <i>C<sub>1</sub></i>.<p>
<li> Classes related by non-simple extensions are fine either for
method dispatch or for slot assignment, but the supplied
argument or slot value will be transformed to class <i>C<sub>1</sub></i>.<p>
<li> The current API only requires that slot replacements be
coercible to the target class, not that there be an extension.
It's possible that this might be tightened if it seemed helpful
in avoiding programming errors.
</ul>
<hr>
<address><a href="http://cm.bell-labs.com/cm/ms/departments/sia/jmc/">John Chambers</a><a href=mailto:[email protected]><[email protected]></a></address>
<!-- hhmts start -->
Last modified: Thu Mar 7 14:50:08 EST 2002
<!-- hhmts end -->
</body> </html>