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 EAA01877; Wed, 9 Apr 2003 04:43:52 +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 EAA29531 for ; Wed, 9 Apr 2003 04:43:51 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com 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 h392hnX22722 for ; Wed, 9 Apr 2003 04:43:50 +0200 (MET DST) Received: from davidb by opus.davidb.org with local (Exim 3.31 #1 (Debian)) id 1935Yv-0002jA-00; Tue, 08 Apr 2003 19:43:45 -0700 Date: Tue, 8 Apr 2003 19:43:45 -0700 From: David Brown To: Yang Shouxun Cc: caml-list@inria.fr Subject: Re: [Caml-list] stack overflow Message-ID: <20030409024345.GA10452@opus.davidb.org> References: <200304091010.37547.yangsx@fltrp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200304091010.37547.yangsx@fltrp.com> User-Agent: Mutt/1.4i X-Spam: no; 0.00; caml-list:01 shouxun:01 invocation:01 ocaml:01 rec:01 overflow:02 exception:02 native:02 stack:02 dave:03 wrote:03 recursive:03 tail:03 anybody:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Apr 09, 2003 at 10:10:37AM +0800, Yang Shouxun wrote: > I've written a modified version of C4.5 program in OCaml. However, when the > input is big, say over 50000, the program (native code on Debian) died for > stack overflow. Otherwise, it runs as expected. > > Can anybody explain possible reasons causing stack overflow in OCaml? Where do you catch the End_of_file exception. A common mistake is to add a try clause inside of a tail recursive call. The call is no longer tail-recursive, and makes a chain of exception handlers for each invocation. e.g. let rec loop () = try let line = input_line () in ...; loop () with End_of_file -> ... instead of let rec loop () = let line = input_line () in ...; loop () in try loop () with End_of_file -> ... 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