Classify pattern-assignment as 'advanced' so tests pass again.
Chris Pressey
10 years ago
25 | 25 |
3, base a loop around something that doesn't consume any input, like `!`.
|
26 | 26 |
|
27 | 27 |
expr = !"\n" & expr
|
|
28 |
|
|
29 |
Advanced Assignment
|
|
30 |
-------------------
|
|
31 |
|
|
32 |
The right-hand side of `→` can actually be more than a variable name;
|
|
33 |
it can be a pattern term, just like is used in the arguments, above.
|
|
34 |
This can be useful for "deconstructing" a compound return value from a
|
|
35 |
production to extract the parts you want.
|
|
36 |
|
|
37 |
| main = foo → pair(A,B) & return A.
|
|
38 |
| foo = return pair(wellington, trainer).
|
|
39 |
= wellington
|
|
40 |
|
|
41 |
| main = foo → pair(A,B) & return B.
|
|
42 |
| foo = return pair(wellington, trainer).
|
|
43 |
= trainer
|
|
44 |
|
|
45 |
Even without variables, this can also be useful simply to assert something
|
|
46 |
returns some value.
|
|
47 |
|
|
48 |
| main = foo → b & print 'yes' | print 'no'.
|
|
49 |
| foo = return a.
|
|
50 |
= no
|
|
51 |
= no
|
|
52 |
|
|
53 |
| main = foo → b & print 'yes' | print 'no'.
|
|
54 |
| foo = return b.
|
|
55 |
= yes
|
|
56 |
= yes
|
28 | 57 |
|
29 | 58 |
Advanced Programming
|
30 | 59 |
--------------------
|
1210 | 1210 |
= c
|
1211 | 1211 |
= end
|
1212 | 1212 |
= ok
|
1213 | |
|
1214 | |
Advanced Assignment
|
1215 | |
-------------------
|
1216 | |
|
1217 | |
The right-hand side of `→` can actually be more than a variable name;
|
1218 | |
it can be a pattern term, just like is used in the arguments, above.
|
1219 | |
This can be useful for "deconstructing" a compound return value from a
|
1220 | |
production to extract the parts you want.
|
1221 | |
|
1222 | |
| main = foo → pair(A,B) & return A.
|
1223 | |
| foo = return pair(wellington, trainer).
|
1224 | |
= wellington
|
1225 | |
|
1226 | |
| main = foo → pair(A,B) & return B.
|
1227 | |
| foo = return pair(wellington, trainer).
|
1228 | |
= trainer
|
1229 | |
|
1230 | |
Even without variables, this can also be useful simply to assert something
|
1231 | |
returns some value.
|
1232 | |
|
1233 | |
| main = foo → b & print 'yes' | print 'no'.
|
1234 | |
| foo = return a.
|
1235 | |
= no
|
1236 | |
= no
|
1237 | |
|
1238 | |
| main = foo → b & print 'yes' | print 'no'.
|
1239 | |
| foo = return b.
|
1240 | |
= yes
|
1241 | |
= yes
|
1242 | 1213 |
|
1243 | 1214 |
Advanced Scanning
|
1244 | 1215 |
-----------------
|