Skip to content

Commit 1d75e49

Browse files
author
jmc
committed
fix out-of-date statements
git-svn-id: https://svn.r-project.org/R-dev-web/trunk@745 c52295ea-58df-0310-926a-d16021944841
1 parent 76fcf4f commit 1d75e49

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

equalAssign.html

+34-19
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@ <h1>Assignments with the <code>=</code> Operator</h1>
1414
<p>
1515
All the previously allowed assignment operators (<code><-</code>,
1616
<code>:=</code>, <code>_</code>, and <code><<-</code>)
17-
remain fully in effect. The <code>=</code> operator is semantically
18-
equivalent to all of these, except the last.
17+
remain fully in effect. The <code>_</code> is a historical curio and
18+
there seems to be general agreement that it should be phased out.
19+
(The historical origin is as follows. During the early work on S at
20+
Bell Labs, the main time-shared terminal in use was the Execuport, a
21+
heavyweight thermal-paper machine which had, among other oddities, a
22+
key corresponding to the ASCII underscore that printed as a back
23+
arrow. This was adopted as an easy-to-type and natural-looking
24+
assignment operator. The two-character back arrow was the less
25+
convenient, but portable version.)
26+
27+
Where it is allowed, the <code>=</code> operator is semantically
28+
equivalent to all of the earlier assignments, except of course <code><<-</code. However, it is not
29+
allowed in all situations.
1930
<p>
2031
<h3>Limitations Imposed</h3>
2132
<p>
2233
The new assignments are allowed in only two places in the grammar: at
23-
the top level (as a complete program or user-typed expression); and as
24-
an element in a braced list of expressions. In all other places, one
25-
of the existing assignment operators must be used.
34+
the top level (as a complete program or user-typed expression); and
35+
when isolated from surrounding logical structure, by braces or an
36+
extra pair of parentheses.
2637
<p>
2738
So the following are allowed:
2839
<code><pre>
@@ -31,24 +42,26 @@ <h3>Limitations Imposed</h3>
3142
> zzz$a[1] = NA
3243
> for(i in 1:10) { xx = min(rnorm(100)); zzz$a[i] = xx}
3344
</pre></code>
34-
But the following is not:
45+
But the following famous C programming error is illegal in the grammar:
3546
<code><pre>
36-
> while((temp = y[i]) > .5) i
47+
> if(x = 0) 1 else x
3748
Error: syntax error
3849
</pre></code>
39-
Embedded assignments of this sort have to be done with one of the older
40-
assignment operators.
50+
Assignments in control structures are generally dangerous; in any
51+
case, to use them you have to either use one of the older assignment
52+
operators, or add an extra level of parentheses.
4153
<p>
4254
There are two reasons for the restricitions:
4355
<ol>
44-
<li> Some restriction is needed, because the same syntax is used for
45-
specifying named arguments in function calls. The additional
46-
restrictions are minor by comparison.<p>
56+
<li> The language already has assignments with <code>=</code>,
57+
known as named arguments in calls. These of course continue to
58+
be interpreted as before. (They are in essence assignments in
59+
the environment created for the call.) Regualar assignments in any
60+
argument in a function call still have to be done with the old
61+
operator, or else surrounded by an extra set of parentheses.<p>
4762
<li> Disallowing the new assignment form in control expressions
48-
avoids some infamous C-style programming errors, such as
49-
<code><pre>
50-
while(result = 0) ## do something important (but it won't happen!)
51-
</pre></code>
63+
avoids programming errors (such as the example above) that are
64+
more likely with the equal operator than with other S assignments.
5265
</ol>
5366
<p>
5467
The restrictions do produce some other limitations that users may find
@@ -62,15 +75,17 @@ <h3>Limitations Imposed</h3>
6275
> quote(y[1] = 1)
6376
Error: syntax error
6477
</pre></code>
65-
(The function is implemented as a special that doesn't check argument
78+
The function is implemented as a special that doesn't check argument
6679
names. The first two examples just use <code>y</code> as the
6780
argument name, and the third fails because the expression on the left
68-
of the <code>=</code> operator isn't valid as an argument name.)
81+
of the <code>=</code> operator isn't valid as an argument name.
82+
A future revision of the function could interpret the first two, but the
83+
grammar pretty much rules out the last example.
6984

7085

7186
<hr>
7287
<address><a href="http://cm.bell-labs.com/cm/ms/departments/sia/jmc/">John Chambers</a><a href=mailto:[email protected]>&lt;[email protected]&gt;</a></address>
7388
<!-- hhmts start -->
74-
Last modified: Mon Aug 13 17:08:02 EDT 2001
89+
Last modified: Sun Dec 16 17:58:58 EST 2001
7590
<!-- hhmts end -->
7691
</body> </html>

0 commit comments

Comments
 (0)