Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   let read_int in_ch =
  2.     let is_valid ch = ch >= '0' && ch <= '9' in
  3.     let ioc ch = (int_of_char ch)-(int_of_char '0') in
  4.  
  5.     let res = ref 0 in
  6.     let tmp = ref '0' in
  7.     try
  8.       while true do
  9.         tmp := (input_char in_ch);
  10.         if (is_valid !tmp) then
  11.           begin
  12.             res := !res * 10 + (ioc !tmp);
  13.           end
  14.         else
  15.           raise Exit;
  16.       done;
  17.       !res;
  18.     with
  19.         Exit -> !res;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement