Differences From Artifact [157799e01f30b7fa]:
- File
sample/ast.pmy
- 2010-11-24 11:20:42 - part of checkin [153a14cec0] on branch trunk - if-then-else without {}s. some cosmetic changes (user: kinaba) [annotate]
To Artifact [a9061a338889d74c]:
- File
sample/ast.pmy
- 2010-11-24 11:45:25 - part of checkin [adacc96a55] on branch trunk - changed the syntax of pattern matching (user: kinaba) [annotate]
1 def reverse(lst, acc) 1 def reverse(lst, acc)
2 { 2 {
3 case(lst) 3 case(lst)
4 when( {car:a, cdr: d} ) { reverse(d, {car:a, cdr:acc}) } | 4 when {car:a, cdr: d}: reverse(d, {car:a, cdr:acc})
5 when( {} ) { acc } | 5 when {}: acc
6 }; 6 };
7 7
8 @macro reverseArgs(e) {@value( 8 @macro reverseArgs(e) {@value(
9 var ev = @macro(e); 9 var ev = @macro(e);
10 case(ev) 10 case(ev)
11 when( {is:"App", fun:f, args:a} ) | 11 when {is:"App", fun:f, args:a}:
12 { <
> 12 (
13 ev {args: reverse(a, {})} 13 ev {args: reverse(a, {})}
14 } <
> 14 )
15 when( _ ) | 15 when _ :
16 { <
> 16 (
17 ev 17 ev
18 } <
> 18 )
19 )}; 19 )};
20 20
21 def main() 21 def main()
22 { 22 {
23 print( reverseArgs(1 + 2) ); 23 print( reverseArgs(1 + 2) );
24 print( reverseArgs(1 - 2) ); 24 print( reverseArgs(1 - 2) );
25 }; 25 };
26 26
27 main() 27 main()