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 OAA26003; Thu, 11 Oct 2001 14:52:14 +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 OAA25999 for ; Thu, 11 Oct 2001 14:52:13 +0200 (MET DST) Received: from localhost.localdomain (Mix-Montsouris-109-4-64.abo.wanadoo.fr [80.9.126.64]) by nez-perce.inria.fr (8.11.1/8.10.0) with SMTP id f9BCqBn25297 for ; Thu, 11 Oct 2001 14:52:12 +0200 (MET DST) Received: (qmail 30765 invoked by uid 1001); 11 Oct 2001 12:47:33 -0000 Date: Thu, 11 Oct 2001 14:47:33 +0200 From: Berke Durak To: Jeff Henrikson Cc: caml-list@inria.fr Subject: Re: [Caml-list] C style for loop Message-ID: <20011011144733.A3985@gogol.zorgol> References: <004001c15218$29c42e20$0b01a8c0@mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <004001c15218$29c42e20$0b01a8c0@mit.edu>; from jehenrik@yahoo.com on Thu, Oct 11, 2001 at 01:47:07AM -0400 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Oct 11, 2001 at 01:47:07AM -0400, Jeff Henrikson wrote: > Okay, so maybe I should be more specific about what I want in a > "C-style for loop." Its readablity merits are hopefully self > evident. Well, unless you're a compulsive CPS addict who wishes > even his grocery list could be written to tail recurse. . . [...] Do you really pretend that ``C-style for loops'' have ``self-evident readability merits'' ?! My opinion is that ```C-style'' loop syntax IS unreadable, ununderstandable and unprovable. How many people using C know the _exact_ semantics of : for(exp1;expr2;expr3){expr4} I never manage to remember if expr3 is evaluated if expr2 is always zero. However with for i = 0 to 33 do f i done the ONLY little point about which you MIGHT hesitate is : does f 33 get called or does the loop stop at 32 ? So I'd rather write for i = 0 to m - 1 do for j = 0 to n - 1 do f i j (i * n + j) done done and let the compiler sort it out. Further, with C syntax, a for loop is not guaranteed to terminate, even if its body is guaranteed to. With Caml-syntax, if your program hangs, you know it's not because of a for-loop. Die-hard C-style ``for'' syntax fanatics :) can define functionals to do the same thing and pressure the Caml team to improve their compilers if they find it's too slow. If you're sure nobody will ever read your code, you can hack a Camlp4 syntax for it, but I don't think it's worth it. I'd like to mention that Scheme has some kind of generalized, totally awful and superfluous loop-construction (I think it's called ``do'' or ``while'', don't remember, these were old, weakly typed times). We don't want such a thing, do we ? -- Berke ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr