-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpatterns.edh
48 lines (38 loc) · 1.05 KB
/
patterns.edh
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
# %%
# a wild capturing pattern is useful when the match target is a complex
# expression
case 3*7-5 of { result }
-> 'a wild capture pattern receives the result= ' ++ result
# %%
case 3:2:1 of {
{ x:y } -> 'pair pattern matches the length'
{ x:y:z } -> 'so this one fires instead of the above'
}
# %%
case 3:2 of { ( x:y ) }
-> 'the pair pattern can be parenthesised'
# %%
case 'b' of { [ 'a', 'b', 'c' ] }
-> 'any-of pattern does is-element-of test'
# %%
case [ 7, 3, 5 ] of { head :> tail }
-> 'uncons pattern does uncons, got ' ++ ( head, tail )
# %%
case ( 3, 5, 7 ) of {
{ ( x, y ) } -> 'positional args pattern matches the length'
{ ( x, y, z ) } -> 'so this one fires instead of the above'
}
# %%
case [] of { () }
-> 'but an empty args pattern matches empty list as well'
# %%
class B pass
class C extends B
c = C()
# %%
case c of { { B:b } }
-> 'instance resolving pattern obtains the right super instance: ' ++ b
# %%
case 'abc' of { prefix @< 'b' >@ suffix }
-> 'string cut patterns can obtain prefix & suffix like: '
+ prefix + ' & ' + suffix