From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA08479; Wed, 24 Apr 2002 06:53:05 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA08311 for ; Wed, 24 Apr 2002 06:53:04 +0200 (MET DST) Received: from kraid.nerim.net (kraid.nerim.net [62.4.16.95]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3O4r4H24391 for ; Wed, 24 Apr 2002 06:53:04 +0200 (MET DST) Received: from alan-schm1p.inria.fr (aboukir-101-1-10-alanschmitt.adsl.nerim.net [62.212.98.49]) by kraid.nerim.net (Postfix) with ESMTP id 0902840F00; Wed, 24 Apr 2002 06:49:56 +0200 (CEST) Received: by alan-schm1p.inria.fr (Postfix, from userid 501) id 0A7D3409E; Wed, 24 Apr 2002 06:52:25 +0200 (CEST) Date: Wed, 24 Apr 2002 06:52:25 +0200 From: Alan Schmitt To: Oliver Bandel Cc: caml-list@inria.fr Subject: Re: [Caml-list] Stack Overflow... (recursion in try-statement) Message-ID: <20020424045225.GD2828@alan-schm1p> Mail-Followup-To: Oliver Bandel , caml-list@inria.fr References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.28i X-Editor: Vim http://vim.sf.net/ X-Info: http://pauillac.inria.fr/~aschmitt/ X-Operating-System: Linux/2.4.18-6mdk (i686) X-Uptime: 6:44am up 11:17, 1 user, load average: 0.11, 0.20, 0.18 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk * Oliver Bandel (oliver@first.in-berlin.de) wrote: > Hello, > > > why does an stack overflow-error occur here? > > let rec traversedir dir = > try ( [Unix.readdir dir] @ traversedir dir ) with > End_of_file -> [];; > > > I have not tried it with very deep directories, so > I did not expect such an error... > > What is the problem here? > 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 -> [] (Disclaimer: I didn't test the code). The idea is you force the evaluation of readdir before the recursive call. I also modified the [d] @ l into a d :: l, which seems to be the same thing to me. HTH, Alan -- The hacker: someone who figured things out and made something cool happen. ------------------- 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