Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Stack Overflow... (recursion in try-statement)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Charles Martin <joelisp@y...>
Subject: Re: [Caml-list] Stack Overflow... (recursion in try-statement)

>I think you stumbled on the good old "evaluation order is not specified"
>thingy ... If the right hand side of the append is called before the
>left hand side, it is not going to work. How about this code:
>
>let rec traversedir dir =
>  try 
>    let d = Unix.readdir dir in
>    d :: (traversedir dir)
>  with
>  | End_of_file -> []

You are building a stack of exception handlers here as well... you might want to go with:

let traversedir dir =
  let dd = ref [] in
  try while true do dd := Unix.readdir dir :: !dd done
  with End_of_file -> !dd

Disclaimer: I didn't run this code :)


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

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