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 XAA07586; Sat, 7 Jun 2003 23:44:06 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA07400 for ; Sat, 7 Jun 2003 23:44:05 +0200 (MET DST) Received: from mail.speakeasy.net (mail15.speakeasy.net [216.254.0.215]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h57Li1T11923 for ; Sat, 7 Jun 2003 23:44:04 +0200 (MET DST) Received: (qmail 27722 invoked from network); 7 Jun 2003 21:44:00 -0000 Received: from unknown (HELO apprentice.genxnet.com) ([64.81.145.152]) (envelope-sender ) by mail15.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 7 Jun 2003 21:44:00 -0000 Date: Sat, 7 Jun 2003 16:46:56 -0500 From: art yerkes To: David Brown Cc: caml-list@inria.fr Subject: Re: [Caml-list] Why do input* and readdir throw End_of_file ... annoying! Message-Id: <20030607164656.1ad1afd5.ayerkes@on-demand-tech.com> In-Reply-To: <20030607202711.GA32043@davidb.org> References: <20030606170131.GA2769@redhat.com> <32CAF7EC-9849-11D7-BAD2-000393863F70@exomi.com> <20030606184304.GA3396@redhat.com> <20030607150854.GA20233@ecooper.com> <20030607202711.GA32043@davidb.org> X-Mailer: Sylpheed version 0.8.11 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; yerkes:01 ayerkes:01 caml-list:01 readdir:01 0400,:01 opendir:01 closedir:01 dirs:01 bug:01 faq:01 beginner's:01 beginners:01 aged:99 bin:01 caml-bugs:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 7 Jun 2003 13:27:11 -0700 David Brown wrote: > 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 how about: open Unix let read_fs starting_dir = let rec go_until_exception list_ref f = list_ref := (f ()) :: !list_ref ; go_until_exception list_ref f and dirs_ref = ref [] in let the_dir = opendir starting_dir in try go_until_exception dirs_ref (fun () -> readdir the_dir) with End_of_file -> !dirs_ref > > ------------------- > 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 -- `No, you don't understand,' the Knight said, looking a little vexed. `That's what the name is called. The name really is "The Aged Aged Man."' -- Lewis Carroll ------------------- 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