1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- structure ListExtra = struct
- fun is_list_prefix nil nil = true
- | is_list_prefix nil lst_elems = true
- | is_list_prefix prefix_elems nil = false
- | is_list_prefix prefix_elems lst_elems =
- if (hd prefix_elems) = (hd lst_elems)
- then is_list_prefix (tl prefix_elems) (tl lst_elems)
- else false;
- fun prepend nil nil = []
- | prepend xlst nil = xlst
- | prepend nil ys = ys
- | prepend (x::nil) ys = x :: ys
- | prepend (x::xs) ys =
- x :: prepend xs ys;
- fun sum_lists (nil, nil) = []
- | sum_lists (nil, l2) = []
- | sum_lists (l1, nil) = []
- | sum_lists (alst as (a::arest), blst as (b::brest)) =
- (a + b) :: sum_lists(arest, brest);
- fun make_list (0, _) = []
- | make_list (len, fill) =
- fill :: make_list (len - 1, fill);
- fun flatten nil = nil
- | flatten (l::ls) =
- l @ (flatten ls);
- fun remove nil elem = nil
- | remove (lst as (x::xs)) elem =
- if x = elem
- then xs
- else x :: (remove xs elem);
- (* fun last nil = raise Fail "empty list, not last element" *)
- (* | last (x::nil) = x *)
- (* | last (x::xs) = last xs; *)
- (* fun prexifes nil = [] *)
- (* | prexifes lst = *)
- (* let *)
- (* fun iter (nil, acc) = acc *)
- (* | iter (remaining, acc) = *)
- (* (hd remaining) :: acc *)
- (* in *)
- (* rev (iter (lst, [[]])) *)
- (* end; *)
- end;
|