Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Why do input* and readdir throw End_of_file ... annoying!
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabrice Le Fessant <lefessan@t...>
Subject: Re: [Caml-list] Why do input* and readdir throw End_of_file ... annoying!

>  On Fri, Jun 06, 2003 at 07:43:04PM +0100, Richard Jones wrote:
>  > The problem is that there doesn't seem to be a way to write the
>  > loop function using readdir. eg:

Why don't you use the while ... do ... done loop instead with an
external reference ?

let list = ref [] in
let dir = opendir "......." in
try
  while true do
    match readdir dir with
      "." | ".." -> ()
    | filename -> list := filename :: !list
  done
with End_of_file -> !list

Recursive functions are elegant to use, but sometimes, it is simpler
to use simple loops instead.

- Fabrice


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