Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. (* 2.3 list_upcase *)
  2.  
  3. (* 1.1 char_upcase *)
  4.  
  5. let rec char_upcase x =
  6. if x < 'a' || x > 'z'
  7. then
  8. print_char x
  9. else
  10. print_char (Char.chr((Char.code x)-(Char.code 'a' - Char.code 'A')))
  11. ;;
  12.  
  13. (* 1.2 string_iter *)
  14.  
  15. let string_iter f s =
  16. let rec s_iter f s = function
  17. n when n = String.length s -> ()
  18. | n -> (f s.[n]) ; (s_iter f s (n+1))
  19. in s_iter f s 0 ;;
  20.  
  21. (* 1.3 string_upcase *)
  22.  
  23. let string_upcase x = string_iter char_upcase x ;;
  24.  
  25. (* 1.4 list_upcase *)
  26.  
  27. let rec list_upcase liste =
  28. let rec list_iter f = function
  29. [] -> ()
  30. | e::l -> f e ; print_newline (); list_iter f l
  31. in list_iter string_upcase liste ;;
  32.  
  33.  
  34.  
  35. let make_liste =
  36. let length = Array.length Sys.argv
  37. in
  38. let rec aux = function
  39. n when n = length -> []
  40. | n -> Sys.argv.(n)::aux (n+1)
  41. in aux 1 ;;
  42.  
  43. let _= list_upcase make_liste ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement