Diff
Not logged in

Differences From Artifact [3044d19024152b10]:

To Artifact [2c8664960dfdd96b]:


1 def fromTo(x, y) 1 def fromTo(x, y) 2 { 2 { 3 if( x > y ) { {} } | 3 if x > y : {} 4 else { {car: x, cdr: fromTo(x+1,y)} } | 4 else : {car: x, cdr: fromTo(x+1,y)} 5 }; 5 }; 6 6 7 def length(lst) 7 def length(lst) 8 { 8 { 9 case( lst ) | 9 case lst 10 when( {car:_, cdr:x} ) { length(x)+1 } | 10 when {car:_, cdr:x}: length(x)+1 11 when( _ ) { 0 } | 11 when _: 0 12 }; 12 }; 13 13 14 def adjSum(lst) 14 def adjSum(lst) 15 { 15 { 16 case( lst ) | 16 case lst 17 when( {car:x, cdr:{car: y, cdr:z}} ) { {car: x+y, cdr: adjSum(z)} } | 17 when {car:x, cdr:{car: y, cdr:z}} : {car: x+y, cdr: adjSum(z)} 18 when( {car:x, cdr:{}} ) { {car: x, cdr: {}} } | 18 when {car:x, cdr:{}}: {car: x, cdr: {}} 19 when( {} ) { {} } | 19 when {}: {} 20 }; 20 }; 21 21 22 var xs = fromTo(1,101); 22 var xs = fromTo(1,101); 23 23 24 print( xs ); 24 print( xs ); 25 print( length(xs) ); 25 print( length(xs) ); 26 print( adjSum(xs) ); 26 print( adjSum(xs) ); 27 print( length(adjSum(xs)) ); 27 print( length(adjSum(xs)) );