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 HAA14369; Thu, 11 Oct 2001 07:34:11 +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 HAA14584 for ; Thu, 11 Oct 2001 07:34:10 +0200 (MET DST) Received: from ms1.surfglobal.net (eone.surfglobal.net [207.136.213.7]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f9B5Y9n18690 for ; Thu, 11 Oct 2001 07:34:09 +0200 (MET DST) Received: from vaiobambino (GILLIGAN [140.186.148.41]) by ms1.surfglobal.net with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 4KGRMPQL; Thu, 11 Oct 2001 01:34:07 -0400 From: "Jeff Henrikson" To: , Subject: [Caml-list] C style for loop Date: Thu, 11 Oct 2001 01:47:07 -0400 Message-ID: <004001c15218$29c42e20$0b01a8c0@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Importance: Normal Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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. . . Suppose (* loop var | init val | while | expr for next val *) for c 0 (c<10) (c+1) do (* bla *) done; desugars into: let rec iter_gensymXXX c = (* bla *) let c = (c+1) in if (c<10) then iter_gensymXXX c else () in iter_gensymXXX 0 Then we could write nice readable nested loops for square arrays, etc. And then there's the canonical loop form which enters in a place different from the exit test. For that, C style "break" is a readable idiom: for c 0 true c do (* bla1 *) let c = c+1 in if !(c<10) then break; (* bla2 *) end; could desugar into: let rec iter_gensymXXX c = (* bla1 *) let c = c+1 in if !(c<10) then () else begin (* bla2 *) let c = c in if true then iter_gensymXXX c else () end in iter_gensymXXX 0 The transformation for "continue" is similar. Pardon my laziness, camlp4 looks really cool, but I haven't taken the time to learn it. For the time being, if somebody has already written a macro kind of like this, I'll take it. IMHO it would be a boon to the caml community to have a standard form for this. Even if it were only a "style guide" addition or what have you. Jeff Henrikson ------------------- 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