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 WAA06556; Sat, 7 Jun 2003 22:27:15 +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 WAA06624 for ; Sat, 7 Jun 2003 22:27:14 +0200 (MET DST) Received: from opus.davidb.org (66-75-152-1.san.rr.com [66.75.152.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h57KRCH03085 for ; Sat, 7 Jun 2003 22:27:13 +0200 (MET DST) Received: from davidb by opus.davidb.org with local (Exim 3.31 #1 (Debian)) id 19OkHP-0008LX-00 for ; Sat, 07 Jun 2003 13:27:11 -0700 Date: Sat, 7 Jun 2003 13:27:11 -0700 From: David Brown To: caml-list@inria.fr Subject: Re: [Caml-list] Why do input* and readdir throw End_of_file ... annoying! Message-ID: <20030607202711.GA32043@davidb.org> References: <20030606170131.GA2769@redhat.com> <32CAF7EC-9849-11D7-BAD2-000393863F70@exomi.com> <20030606184304.GA3396@redhat.com> <20030607150854.GA20233@ecooper.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030607150854.GA20233@ecooper.com> User-Agent: Mutt/1.5.4i X-Spam: no; 0.00; caml-list:01 readdir:01 0400,:01 opendir:01 closedir:01 rec:01 filesystem:02 match:02 exception:02 dave:03 wrote:03 annoying:03 recursive:03 tail:03 argument:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, Jun 07, 2003 at 11:08:54AM -0400, Eric C. Cooper wrote: > and read_directory path = > let dirh = opendir path in > let rec loop entries = > try match readdir dirh with > | "." | ".." -> loop entries > | filename -> loop (read_filesystem filename :: entries) > with End_of_file -> entries > in > let list = loop [] in > closedir dirh; > list But, this isn't tail recursive, so you might as well not pass the argument and build up the list upon returning. Is there a way of making it really tail recursive, while using the exception? It isn't too hard with a list ref to accumulate the results. Dave ------------------- 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