Artifact 3044d19024152b10898042989a7948b2f818828a
- 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]
def fromTo(x, y) { if( x > y ) { {} } else { {car: x, cdr: fromTo(x+1,y)} } }; def length(lst) { case( lst ) when( {car:_, cdr:x} ) { length(x)+1 } when( _ ) { 0 } }; def adjSum(lst) { case( lst ) when( {car:x, cdr:{car: y, cdr:z}} ) { {car: x+y, cdr: adjSum(z)} } when( {car:x, cdr:{}} ) { {car: x, cdr: {}} } when( {} ) { {} } }; var xs = fromTo(1,101); print( xs ); print( length(xs) ); print( adjSum(xs) ); print( length(adjSum(xs)) );