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 TAA30800; Thu, 8 Jul 2004 19:12:40 +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 TAA00067 for ; Thu, 8 Jul 2004 19:12:39 +0200 (MET DST) Received: from mail6.speakeasy.net (mail6.speakeasy.net [216.254.0.206]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i68HCbSH023271 for ; Thu, 8 Jul 2004 19:12:38 +0200 Received: (qmail 15878 invoked from network); 8 Jul 2004 17:12:34 -0000 Received: from shell1.speakeasy.net ([69.17.110.70]) (envelope-sender ) by mail6.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 8 Jul 2004 17:12:34 -0000 Date: Thu, 8 Jul 2004 10:12:33 -0700 (PDT) From: brogoff To: Luc Maranget cc: caml-list Subject: Tail calls (Was Re: [Caml-list] Does Caml have slow arithmetics ?) In-Reply-To: <20040708163653.A1260@beaune.inria.fr> Message-ID: References: <20040707091308.GA26172@bourg.inria.fr> <20040707145803.GB27498@yquem.inria.fr> <1089227778.29648.81.camel@pelican.wigram> <20040708034455.GB29942@davidb.org> <40ED190E.3080005@ps.uni-sb.de> <20040708140408.GA2386@davidb.org> <20040708163653.A1260@beaune.inria.fr> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 40ED8085.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 brogoff:01 caml-list:01 arithmetics:01 2004:99 rossberg:01 tail-call:01 ocamlc:01 ocamlopt:01 params:01 accum:01 params:01 accum:01 uglier:01 recursion:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 8 Jul 2004, Luc Maranget wrote: > > On Thu, Jul 08, 2004 at 11:51:10AM +0200, Andreas Rossberg wrote: > > > > Many ocaml programs depend on tail-call elimination, although I don't > > believe anything in the docs requires it to be done. > > > > Well, when programming in caml, I use the following rules (which I hope to be > accurate!) > > + ocamlc does perform tail call elimation > + ocamlopt does it less often. Namely, calls in tail position > become real tail calls when all their arguments are passed in registers. > (This does not apply to self-tail calls which are always optimized) In my own code the self tail call is by far more let rec loop params accum = if finished params accum then result params accum else loop (update_params params) (update_accum params accum) is by far more the most common, so much so that that idiom is "under finger". Usually params takes up one or two arguments. Anyone have good examples where this limitation leads to significantly "uglier" code? The limitation you describe should be well doumented, but is not yet annoying to me. I'll need to write some tests and check the assembly output on the Linux machines I have access to. More annoying is the lack of some way to get the "tail recursion modulo cons" capability directly in the language without needing to use Obj functionality. -- 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