Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] ocaml and large development projects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Siegfried Gonzi <siegfried.gonzi@s...>
Subject: Re: [Caml-list] Reading a file
Siegfried Gonzi wrote:

>
> I got this version and I think I like it best

==
| let map_on_lines ic f =
|   let lines = ref [] in
|   begin try while true do
|     let l = input_line ic in
|     lines := l :: !lines
|   done 
|   with End_of_file -> close_in ic
|   end ;
|   List.rev_map f !lines
| 
| let extract_floats reg userval l =
|   List.map 
|     (function
|       | "n/a" | "nil" -> userval
|       | s -> float_of_string s)
|     (Str.split reg l)
| 
| let main = 
|   let ic = open_in "foo" in
|   map_on_lines ic 
|     (extract_floats (Str.regexp ",") (-1.0))
==



It is due to Olivier Andrieu

S. Gonzi



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners