git @ Cat's Eye Technologies Tamsin / 7acbaad
Classify pattern-assignment as 'advanced' so tests pass again. Chris Pressey 10 years ago
2 changed file(s) with 29 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
2525 3, base a loop around something that doesn't consume any input, like `!`.
2626
2727 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
2857
2958 Advanced Programming
3059 --------------------
12101210 = c
12111211 = end
12121212 = 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
12421213
12431214 Advanced Scanning
12441215 -----------------