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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 163DEBC6B for ; Mon, 9 Jul 2007 11:11:13 +0200 (CEST) Received: from hades.snarc.org (hades.snarc.org [212.85.152.11]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l699BB1O021937 for ; Mon, 9 Jul 2007 11:11:12 +0200 Received: by hades.snarc.org (Postfix, from userid 1000) id 1BBED1B4D7; Mon, 9 Jul 2007 11:01:32 +0200 (CEST) Date: Mon, 9 Jul 2007 11:01:31 +0200 To: Jon Harrop Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] try .. finally using new camlp4 Message-ID: <20070709090131.GA17462@snarc.org> References: <200707080114.42213.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200707080114.42213.jon@ffconsultancy.com> X-Warning: Email may contain unsmilyfied humor and/or satire. User-Agent: Mutt/1.5.13 (2006-08-11) From: tab@snarc.org (Vincent Hanquez) X-Miltered: at concorde with ID 4691FBAF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 0100,:01 camlp:01 syntax:01 afaict:01 ocaml:01 ocaml:01 compiler:01 expr:01 expr:01 val:01 exn:01 val:01 exn:01 cheers:01 On Sun, Jul 08, 2007 at 01:14:41AM +0100, Jon Harrop wrote: > I'm just getting my toe wet with the new camlp4 and I can't get this simple > syntax extension to work. AFAICT, the following code: A bit OT, but I found it quite easy to actually hack ocaml source directly to do the right thing for try finally. My modification seems to works correctly, without having any deep knowledge of ocaml internal compiler code. > EXTEND Gram > expr: LEVEL "top" > [[ "try"; f=expr; "finally"; g=expr -> > <:expr< > ((function > | `Val v, g -> g(); v > | `Exn e, g -> g(); raise e) > ((try `Val($f$) with e -> `Exn e), (fun () -> $g$))) > >>]]; > END I don't know camlp4, but why don't you use a more straightforward (let r = try f() with e -> g(); raise e in g(); r) construct instead of wrapping/unwrapping the thing into polymorphic variant ? Cheers, -- Vincent Hanquez