Differences From Artifact [3044d19024152b10]:
- File
sample/pattern.pmy
- 2010-11-21 15:48:16 - part of checkin [f86026acb8] on branch trunk - macro cache and automemoization reloaded. auto re-run implemented. but automemo and autorerun is currently disabled. we need Table.opCmp... we also need to think more about the memoization (user: kinaba) [annotate]
To Artifact [2c8664960dfdd96b]:
- File
sample/pattern.pmy
- 2010-11-24 12:14:00 - part of checkin [3ae09b8cbf] on branch trunk - changed if-then-else syntax (user: kinaba) [annotate]
1 1 def fromTo(x, y)
2 2 {
3 - if( x > y ) { {} }
4 - else { {car: x, cdr: fromTo(x+1,y)} }
3 + if x > y : {}
4 + else : {car: x, cdr: fromTo(x+1,y)}
5 5 };
6 6
7 7 def length(lst)
8 8 {
9 - case( lst )
10 - when( {car:_, cdr:x} ) { length(x)+1 }
11 - when( _ ) { 0 }
9 + case lst
10 + when {car:_, cdr:x}: length(x)+1
11 + when _: 0
12 12 };
13 13
14 14 def adjSum(lst)
15 15 {
16 - case( lst )
17 - when( {car:x, cdr:{car: y, cdr:z}} ) { {car: x+y, cdr: adjSum(z)} }
18 - when( {car:x, cdr:{}} ) { {car: x, cdr: {}} }
19 - when( {} ) { {} }
16 + case lst
17 + when {car:x, cdr:{car: y, cdr:z}} : {car: x+y, cdr: adjSum(z)}
18 + when {car:x, cdr:{}}: {car: x, cdr: {}}
19 + when {}: {}
20 20 };
21 21
22 22 var xs = fromTo(1,101);
23 23
24 24 print( xs );
25 25 print( length(xs) );
26 26 print( adjSum(xs) );
27 27 print( length(adjSum(xs)) );