1.32. List functions

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