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 PAA13546; Tue, 23 Dec 2003 15:35:11 +0100 (MET) 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 PAA13556 for ; Tue, 23 Dec 2003 15:35:09 +0100 (MET) Received: from jalapeno.cc.columbia.edu (jalapeno.cc.columbia.edu [128.59.59.238]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBNEZ8b09060 for ; Tue, 23 Dec 2003 15:35:08 +0100 (MET) Received: from tw304h3.cpmc.columbia.edu (tw304h3.cpmc.columbia.edu [156.111.84.180]) (user=ot14 mech=LOGIN bits=0) by jalapeno.cc.columbia.edu (8.12.10/8.12.10) with ESMTP id hBNEZ6kE000457 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT); Tue, 23 Dec 2003 09:35:07 -0500 (EST) From: Oleg Trott To: Dustin Sallings , Samuel Lacas Subject: Re: [Caml-list] Frustrated Beginner Date: Tue, 23 Dec 2003 09:34:59 -0500 User-Agent: KMail/1.5.4 Cc: Tyler Eaves , caml-list@inria.fr References: <1072152186.59938.30.camel@tylere> <3FE8183F.90205@trusted-logic.fr> <5DA31570-3537-11D8-A8F7-000393CB0F1E@spy.net> In-Reply-To: <5DA31570-3537-11D8-A8F7-000393CB0F1E@spy.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200312230935.00259.oleg_trott@columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.35 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; oleg:01 oleg:01 caml-list:01 samuel:01 lacas:01 pleac:01 sourceforge:01 pleac:01 ocaml:01 rec:01 rec:01 syntax:02 match:02 wrote:03 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tuesday 23 December 2003 06:01 am, Dustin Sallings wrote: > On Dec 23, 2003, at 2:26, Samuel Lacas wrote: > > May be > > > > http://pleac.sourceforge.net/pleac_ocaml.html > > > > may help you here. > > Interesting, this has the same problem I had when I tried to create > fold_lines: > > let rec fold_lines f init chan = > try > let line = input_line chan in > fold_lines f (f init line) chan > with End_of_file -> init > > That ends up not being tail recursive. I suppose I should get on the > list and try to make some suggestions. Non-recursive version let fold_lines f init chan = let res = ref init in (try while true do res := f !res (input_line chan) done with End_of_file -> ()); !res Tail-recursive version: let rec fold_lines f init chan = match try Some (input_line chan) with End_of_file -> None with | Some line -> fold_lines f (f init line) chan | None -> init (But I don't think "fold" functions are useful for a beginner, especially one who's still having problems with the syntax aspect of the language. TE, look elsewhere) -- Oleg Trott ------------------- 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