Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.49 KB | None | 0 0
  1. (*
  2.     * Deletes all invalid characters starting from last valid one
  3.     * valid characters passes the 'test_char' function
  4. *)
  5.  
  6. let trim w =
  7.     let rec aux ww =
  8.         match ww with
  9.         | [] -> []
  10.         | h :: t -> if test_char h then List.rev (h :: t) else aux t
  11.         in
  12.         aux (List.rev w)
  13.     ;;
  14.  
  15. (* Testing, let's say we accept just a-z A-Z *)
  16. trim ['c', 'b', 'd', '!', '$'];; (* outputs: ['c', 'b', 'd'] *)
  17. trim ['c', '$', 'd'];; (* outputs: ['c', '$', 'd'] *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement