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 BAA13642; Wed, 28 Jul 2004 01:43:21 +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 BAA16924 for ; Wed, 28 Jul 2004 01:43:16 +0200 (MET DST) From: briand@aracnet.com Received: from jade.spiritone.com (jade.spiritone.com [216.99.193.136]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6RNhBEV021523 for ; Wed, 28 Jul 2004 01:43:14 +0200 Received: from soggy.deldotd.com (216-99-206-32.cust.aracnet.com [216.99.206.32]) by jade.spiritone.com (8.12.8/8.12.8) with ESMTP id i6RNhAYw001415 for ; Tue, 27 Jul 2004 16:43:10 -0700 Received: from briand by soggy.deldotd.com with local (Exim 3.36 #1 (Debian)) id 1BpbbC-0000Lq-00 for ; Tue, 27 Jul 2004 16:43:10 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16646.59534.101085.662305@soggy.deldotd.com> Date: Tue, 27 Jul 2004 16:43:10 -0700 To: caml-list@inria.fr Subject: [Caml-list] looping recursion X-Mailer: VM 6.92 under Emacs 21.2.1 X-Miltered: at nez-perce with ID 4106E88F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; recursion:01 recursion:01 rec:01 rec:01 overflow:02 stack:02 stack:02 string:03 chunk:03 recursive:03 scheme:03 scheme:03 let:04 let:04 proc:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Well without an eof-object to check for (as in scheme) I've started using the following code chunk to read all the lines out of a file : let read_file filename = let file = open_in filename in let rec proc line = print_string line; print_newline(); try proc (input_line file); with End_of_file -> true; in proc (input_line file); works great until you read enough lines and then you get: Stack overflow during evaluation (looping recursion?). naturally I suspected that the try was perhaps ruining the tail-callness of the code, so I moved it outside of the recursive proc, i.e. let rec proc line = ... in try proc (input_line file); with End_of_file -> true; and that works just fine. Is there a better way to just pull in all the lines of a file ? I've just gotten used to doing it like this, because in scheme it's very clean. And since I'm not actually accumulating anything, I'm most confused as to how the stack space is disappearing. Brian ------------------- 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