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=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id BA438BC69 for ; Tue, 25 Dec 2007 23:49:15 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAOYXcUfRVca+kmdsb2JhbACDIoxtAQEBAQcCBhMWlBODSw X-IronPort-AV: E=Sophos;i="4.24,206,1196636400"; d="scan'208";a="20683644" Received: from rv-out-0910.google.com ([209.85.198.190]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Dec 2007 23:49:11 +0100 Received: by rv-out-0910.google.com with SMTP id k20so1629426rvb.3 for ; Tue, 25 Dec 2007 14:49:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=Gg/OxWaDC4JA1Xtk1CyPKtNDpzch6542kLEeCV+aYG0=; b=EUdEanhSFVW+XUu7QqzjXGsx2IGbyBbM1xty7Gq/wgsouXoQgM+HISoEpB61ElICfiTFqTab5uZWjlU3WKos+v6Xy8JbLC1j4Y+qqiKg995JTatcqNw8VFzhPtxHwngP9l/CJR5F4I2Je4wzJ3mgevBMaF+xC0shBysZG6er96M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Vl7fOXoGx7iLDVFD+xxPsEv98ov2usaxUevo5T14sOxhTHtoaR3Rj5M00wmqQ991CpEhZhJDivC0CsG2tl4Uc8gdMZSluWSN5l9a2bRUQ4a/v5+2/6qFgPZhE8+OkXMoRGICLUOw7b2x8V8kgDVWV4RJQ9MnVUkS4LSZD3Exm/M= Received: by 10.142.49.4 with SMTP id w4mr1703537wfw.167.1198622940184; Tue, 25 Dec 2007 14:49:00 -0800 (PST) Received: by 10.142.173.15 with HTTP; Tue, 25 Dec 2007 14:49:00 -0800 (PST) Message-ID: <527cf6bc0712251449t53d9e0c9sc0680cb037319671@mail.gmail.com> Date: Tue, 25 Dec 2007 23:49:00 +0100 From: "blue storm" To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] [camlp4 extension] pa_refutable : request for comments In-Reply-To: <1198614473-sup-1388@ausone.local> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <527cf6bc0712250936k7b7c713eg7ec4a34da4fd2f26@mail.gmail.com> <1198614473-sup-1388@ausone.local> X-Spam: no; 0.00; camlp:01 expr:01 expr:01 constructors:01 subtleties:01 camlp:01 storm:98 wrote:01 rec:01 rec:01 parsing:01 caml-list:01 patt:01 patt:01 tuple:02 On 12/25/07, Nicolas Pouillard wrote: > > There are 6 repetitive lines of code in my refutable_mono function : > > let binds_patt binds _loc = > > let patt_of_id (id, _loc) = <:patt< $lid:id$ >> in > > Ast.PaTup _loc (Ast.paCom_of_list (List.map patt_of_id binds)) in > > let binds_expr binds _loc = > > let expr_of_id (id, _loc) = <:expr< $lid:id$ >> in > > Ast.ExTup _loc (Ast.exCom_of_list (List.map expr_of_id binds)) in > > Is there an better way to do this ? > > In fact I think this part is wrong. What's happen if you get no variable or > just one in the pattern? You will try to build a nil-tuple or a > singleton-tuple and that's forbidden. > > Here is the untested code for patterns: > > let binds_patt binds _loc = > let patt_of_id (id, _loc) = <:patt< $lid:id$ >> in > match binds with > | [] -> <:patt< () >> > | [c] -> patt_of_id c > | c :: cs -> <:patt< ( $patt_of_id c$, $list:List.map patt_of_id cs$ ) >> > in > > The cool thing is that by making explicit the tuple (by having more than one > element) one avoid resorting to concrete constructors and can use the $list:$ > special antiquotation that will insert the paCom_of_list call. That's right. I fixed (or at least tried to) that in my new version, http://bluestorm.info/tmp/pa_refutable-0.4.ml.html : let binds = (id_folder#patt patt)#get_binds in let (binds_patt, binds_expr) = let patt_of_id (id, _loc) = <:patt< $lid:id$ >> in let expr_of_id (id, _loc) = <:expr< $lid:id$ >> in match binds with [ [] -> ( <:patt< () >> , <:expr< () >> ) | [hd] -> ( patt_of_id hd, expr_of_id hd ) | [hd::tl] -> ( <:patt< ( $patt_of_id hd$, $list:List.map patt_of_id tl$ ) >>, <:expr< ( $expr_of_id hd$, $list:List.map expr_of_id tl$ ) >> ) ] in <:binding< $binds_patt$ = match $expr$ with [ $patt$ -> $binds_expr$ | _ -> $refutable_err patt$ ] >> ; > > Lastly, i had to duplicate work in the grammar-modification part, > > because i didn't manage to use the "opt_rec" rule. I'm not aware of > > the subtleties of camlp4 parsing; is there another way ? > > I don't think there is any subtlety here, just replace: > > | "let"; "rec"; "refutable"; bi = binding -> > <:str_item< value rec $refutable bi$ >> > | "let"; "refutable"; bi = binding -> > <:str_item< value $refutable bi$ >> > > by something like: > > | "let"; r = opt_rec; "refutable"; bi = binding -> > <:str_item< value $rec:r$ $refutable bi$ >> Hm. I thought opt_rec wouldn't work, but it looks like i was wrong. I changed the code to use opt_rec and my test file works flawlessly. Thanks for your reply