Anonymous user
Text processing/2: Difference between revisions
→{{header|OCaml}}: tail recursive call should be outside of try
m (→{{header|zkl}}: update) |
(→{{header|OCaml}}: tail recursive call should be outside of try) |
||
Line 1,649:
let strip_cr str =
let last = pred (String.length str) in
if str.[last] <> '\r' then
let map_records =
Line 1,658:
aux (e::acc) tail
| [_] -> invalid_arg "invalid data"
| [] ->
in
aux [] ;;
Line 1,671:
aux acc tl
| [] ->
in
aux [] ;;
let record_ok (_,record) =
let is_ok (_,v) =
let sum_ok =
List.fold_left (fun sum this ->
if is_ok this then succ sum else sum) 0 record
in
let num_good_records =
Line 1,690:
let li = split (regexp "[ \t]+") line in
let records = map_records (List.tl li)
and date =
(date, records)
Line 1,696:
let ic = open_in "readings.txt" in
let rec read_loop acc =
try▼
with End_of_file -> None
▲ let line = strip_cr(input_line ic) in
None -> close_in ic; List.rev acc
| Some line -> read_loop (
in
let inputs = read_loop [] in
|