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
Markus Mottl wrote:

>You cannot just take one solution of one language and assume that it
>is equally efficient or elegant in another language. This also heavily
>depends on availability and functionality of libraries. E.g. there is no
>"take_while" or "drop_while" in the OCaml standard library - you'd have
>to write them yourself.
>

I got this version and I think I like it best (except for this single 
semicolon; may be C could get some punctuation hell-ideas from Ocaml):

 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))


The problem what I am now faced with is as follows: how to use it. Do I 
have to link against a regex.o library? There is no Readme in the 
additional libraay folder of Ocaml how to use regex in Ocaml programs.

Regards,
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