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.2 required=5.0 tests=AWL,SPF_SOFTFAIL 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 61570BBAF for ; Sat, 23 May 2009 19:37:27 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmsFABvRF0rUNQVcdWdsb2JhbACXYwEMCgsHEbk/gj2BTgU X-IronPort-AV: E=Sophos;i="4.41,237,1241388000"; d="scan'208";a="40424207" Received: from postbode02.versateladsl.be ([212.53.5.92]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 23 May 2009 19:37:27 +0200 Received: (qmail 16378 invoked by uid 0); 23 May 2009 17:37:05 -0000 Received: from unknown (HELO poincare.swapping.umh.ac.be) ([94.109.196.49]) (envelope-sender ) by smtp.versateladsl.be (qmail-ldap-1.03) with SMTP for < >; 23 May 2009 17:37:05 -0000 Received: from [127.0.0.1] (helo=localhost ident=trch) by poincare.swapping.umh.ac.be with esmtp (Exim 4.69) (envelope-from ) id 1M7v9t-0004qU-DD; Sat, 23 May 2009 19:37:21 +0200 Date: Sat, 23 May 2009 19:37:21 +0200 (CEST) Message-Id: <20090523.193721.593663251733925547.Christophe.Troestler+ocaml@umons.ac.be> To: mwipliez@yahoo.fr Cc: caml-list@inria.fr Subject: Re: Re : [Caml-list] Camlp4 documentation From: Christophe TROESTLER In-Reply-To: <862878.58359.qm@web23603.mail.ird.yahoo.com> References: <200905231324.45256.jon@ffconsultancy.com> <862878.58359.qm@web23603.mail.ird.yahoo.com> X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons X-Mailer: Mew version 6.2.51 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; camlp:01 christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 matthieu:01 expr:01 wiki:01 toploop:01 camlp:01 assertion:01 dynlink:01 ocaml:01 syntax:01 On Sat, 23 May 2009 13:13:23 +0000, Matthieu Wipliez wrote: > > A tuple is represented as <:expr< ($e$) >> Well, at the moment, the better is to complement the information on the wiki with personal experiments in the toploop (and occasionally read the Camlp4 sources). For example, for the above assertion: #directory "+camlp4";; #load "dynlink.cma";; (* OCaml >= 3.11.0 *) #load "camlp4of.cma";; open Camlp4.PreCast;; let _loc = Loc.ghost;; open Syntax;; # let f e = <:expr< ($e$) >>;; val f : 'a -> 'a = With such a signature, you can imagine that f is just the identity function and you can confirm it with a few experiments. To match a tuple, first look how they are represented: let e = <:expr< x,y,z >>;; val e : Camlp4.PreCast.Syntax.Ast.expr = Camlp4.PreCast.Syntax.Ast.ExTup (, Camlp4.PreCast.Syntax.Ast.ExCom (, Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "x")), Camlp4.PreCast.Syntax.Ast.ExCom (, Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "y")), Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "z"))))) Tuples are thus constructed with "ExTup" which is matched by $tup$ : # match e with <:expr< $tup:t$ >> -> t;; - : Camlp4.PreCast.Syntax.Ast.expr = Camlp4.PreCast.Syntax.Ast.ExCom (, Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "x")), Camlp4.PreCast.Syntax.Ast.ExCom (, Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "y")), Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "z")))) Then you probably want the individual components that are separated by comas. You can easily write your own function but looking at the Camlp4 sources, you will find that it is already provided : # match e with <:expr< $tup:t$ >> -> Ast.list_of_expr t [];; - : Camlp4.PreCast.Syntax.Ast.expr list = [Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "x")); Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "y")); Camlp4.PreCast.Syntax.Ast.ExId (, Camlp4.PreCast.Syntax.Ast.IdLid (, "z"))] Hope it helps, C.