Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 =
|     (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.

S. Gonzi

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: