You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: courses/RascalAmendmentProposals/RAP7/RAP7.md
+16-17Lines changed: 16 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ sidebar_position: 7
12
12
13
13
## Abstract
14
14
15
-
The proposal is to disallow assignments (=) into all pattern variables, including those of function parameters and the left-hand side of generators (all pattern variables). This effectively makes all those names \`final\` in Java jargon.
15
+
The proposal is to disallow assignments (`=`) into all pattern variables, including those of function parameters and the left-hand side of generators (all pattern variables). This effectively makes all those names `final` in Java jargon.
16
16
17
17
## Motivation
18
18
@@ -32,49 +32,49 @@ The basic motivation is to simplify the programming and analysis of Rascal progr
32
32
33
33
## Specification
34
34
35
-
* The static checker should disallow \`x \= exp;\` for all \`x\` introduced as pattern variables; this is the core of the proposal and the rest follows.
35
+
* The static checker should disallow `x = exp;` for all `x` introduced as pattern variables; this is the core of the proposal and the rest follows.
36
36
* Closures should capture all pattern variables by-value (*or else we would not be able to satisfy the constraint that they are final*)
37
37
38
38
For example:
39
39
40
40
int f(int j) {
41
-
j \= 0; // error\! Can not assign to pattern variable j
41
+
j = 0; // error\! Can not assign to pattern variable j
42
42
43
-
for (k \<- \[0..9\]) {
44
-
k \*= 2; // error Can not assign to pattern variable k
43
+
for (k <- [0..9]) {
44
+
k *= 2; // error Can not assign to pattern variable k
45
45
println(k);
46
46
}
47
47
}
48
48
49
49
// prints 0123456789 (and not 999999999 anymore\!):
50
50
void testClosureNoState() {
51
-
x \= for (int j \<- \[0..10\]) {
51
+
x = for (int j <- [0..10]) {
52
52
append () { return j; };
53
53
}
54
-
for (f \<- x) {
54
+
for (f <- x) {
55
55
print(f());
56
56
}
57
57
}
58
58
59
59
// prints 999999999:
60
60
void testClosureWithState() {
61
-
int state \= \-1;
62
-
x \= for (int j \<- \[0..10\]) {
63
-
state \= j; // no error, this is a local variable
61
+
int state = \-1;
62
+
x = for (int j <- [0..10]) {
63
+
state = j; // no error, this is a local variable
64
64
append () { return state; };
65
65
}
66
-
for (f \<- x) {
66
+
for (f <- x) {
67
67
print(f());
68
68
}
69
69
}
70
70
71
71
// prints 123456789:
72
72
void testClosureWithScopedState() {
73
-
x \= for (int j \<- \[0..10\]) {
74
-
int state \= j; // no error, this is a local variable
75
-
append () { return state; }; // \`state\` is new every loop
73
+
x = for (int j <- [0..10]) {
74
+
int state = j; // no error, this is a local variable
75
+
append () { return state; }; // `state` is new every loop
0 commit comments