From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id E6D11BBC1 for ; Thu, 10 Apr 2008 09:09:01 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAHJZ/UfAXQIm/2dsb2JhbACqaA X-IronPort-AV: E=Sophos;i="4.25,633,1199660400"; d="scan'208";a="11287833" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Apr 2008 09:09:01 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m3A791YN010290 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 10 Apr 2008 09:09:01 +0200 From: luc.maranget@inria.fr (Luc Maranget) X-IronPort-AV: E=Sophos;i="4.25,633,1199660400"; d="scan'208";a="10681926" Received: from yquem.inria.fr ([128.93.8.37]) by mail1-relais-roc.national.inria.fr with ESMTP; 10 Apr 2008 09:09:01 +0200 Received: by yquem.inria.fr (Postfix, from userid 18041) id 2E40DBBC1; Thu, 10 Apr 2008 09:09:01 +0200 (CEST) Date: Thu, 10 Apr 2008 09:09:01 +0200 To: Sanghyeon Seo Cc: caml-list@inria.fr Subject: Re: [Caml-list] break and continue for OCaml Message-ID: <20080410070901.GA8177@yquem.inria.fr> References: <5b0248170804091859s75c3f725s2db53f48fba6735c@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5b0248170804091859s75c3f725s2db53f48fba6735c@mail.gmail.com> User-Agent: Mutt/1.5.9i X-Miltered: at discorde with ID 47FDBD0D.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; maranget:01 maranget:01 ocaml:01 ocaml:01 sparcs:01 bytecomp:01 bytegen:01 bytecode:01 lambda-code:01 bytecomp:01 lambda:01 mli:01 lambda:01 -dlambda:01 compilation:01 > I have the first cut of patch to implement break and continue inside > for and while loops for OCaml. > > http://sparcs.kaist.ac.kr/~tinuviel/devel/ocaml/ > > Patch is against OCaml 3.10.2. All the meat is in bytecomp/bytegen.ml. > Currently bytecode only. I am working on natvie code and error > handling when break is used outside loop etc but I thought "releasing > early" could be useful. > > What do you think? I think that you can implement break/continue without altering the lambda-code (file bytecomp/lambda.mli) by using the existing 'static exception' mechanism : ... | Lstaticraise of (int * lambda list) | Lstaticcatch of lambda * (int * Ident.t list) * lambda ... with the following pretty printing convention (cf. option -dlambda) (exit i) stands for 'Lstaticraise (i,[])' (catch e1 with (i) e2) stands for 'Lstaticcatch (e1,(i,[]),e2)' Then you have for instance while e1 do e2 done -> (catch (while (e1) (catch e2 with (icont) ()) with (ibreak) ()) In the loop body e2, break is compiled into (exit ibreak) and coninue into (exit icont). It is a bit complicated, but then you get native code compilation for free. -- Luc PS> I make no statement on whether break/continue should be added to ocaml! But.. 1. Exceptions are already here and they express more flexible control flow modifications. 2. Adding keywords is something that is not easily accepted, because it breaks existing code.