2.32. List functions

Start felix section to tut/tutorial/tut-1.32-0.flx[1 /1 ]
     1: #line 3518 "./lpsrc/flx_tutorial.pak"
     2: //Check list:inductive
     3: #import <flx.flxh>
     4: open List;
     5: val x : list[int] =
     6:   Cons (1, Cons (2, Cons (3, Empty[int])));
     7: val y = rev x;
     8: iter (proc (x:int) { print x; print ", "; }) x; endl;
     9: iter (proc (x:int) { print x; print ", "; }) y; endl;
    10: 
    11: proc print (x:list[int])
    12: {
    13:   match x with
    14:   | Empty[int] => { print "[]"; }
    15:   | Cons[int] (?h,?t) =>
    16:     {
    17:       print "["; print h;
    18:       iter (proc (x:int) { print ","; print x; }) t;
    19:       print "]";
    20:     }
    21:   endmatch;
    22: }
    23: 
    24: fun add (x:int) (y:int):int = { return x + y; }
    25: 
    26: val x_l_total = fold_left add of (int) 0 x;
    27: val y_l_total = fold_left add of (int) 0 y;
    28: val x_r_total = fold_right add of (int) x 0;
    29: val y_r_total = fold_right add of (int) y 0;
    30: print x_l_total; endl;
    31: print y_l_total; endl;
    32: print x_r_total; endl;
    33: print y_r_total; endl;
End felix section to tut/tutorial/tut-1.32-0.flx[1]
Start data section to tut/tutorial/tut-1.32-0.expect[1 /1 ]
     1: 1, 2, 3,
     2: 3, 2, 1,
     3: 6
     4: 6
     5: 6
     6: 6
End data section to tut/tutorial/tut-1.32-0.expect[1]