* Camlp4 documentation @ 2009-05-23 12:24 Jon Harrop 2009-05-23 13:13 ` Re : [Caml-list] " Matthieu Wipliez 0 siblings, 1 reply; 5+ messages in thread From: Jon Harrop @ 2009-05-23 12:24 UTC (permalink / raw) To: caml-list Are the constructions listed here: http://caml.inria.fr/pub/docs/manual-camlp4/manual010.html valid for the new camlp4 as well? For example, <:expr< ( $list:el$ ) >> to deconstruct a tuple. If not, is there equivalent up-to-date documentation anywhere? -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re : [Caml-list] Camlp4 documentation 2009-05-23 12:24 Camlp4 documentation Jon Harrop @ 2009-05-23 13:13 ` Matthieu Wipliez 2009-05-23 17:37 ` Christophe TROESTLER 0 siblings, 1 reply; 5+ messages in thread From: Matthieu Wipliez @ 2009-05-23 13:13 UTC (permalink / raw) To: caml-list Most of them are. A tuple is represented as <:expr< ($e$) >> for instance, as can be seen on the Wiki page Abstract Syntax Tree: http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree Cheers, Matthieu ----- Message d'origine ---- > De : Jon Harrop <jon@ffconsultancy.com> > À : caml-list@inria.fr > Envoyé le : Samedi, 23 Mai 2009, 14h24mn 45s > Objet : [Caml-list] Camlp4 documentation > > > Are the constructions listed here: > > http://caml.inria.fr/pub/docs/manual-camlp4/manual010.html > > valid for the new camlp4 as well? > > For example, <:expr< ( $list:el$ ) >> to deconstruct a tuple. > > If not, is there equivalent up-to-date documentation anywhere? > > -- > Dr Jon Harrop, Flying Frog Consultancy Ltd. > http://www.ffconsultancy.com/?e > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Re : [Caml-list] Camlp4 documentation 2009-05-23 13:13 ` Re : [Caml-list] " Matthieu Wipliez @ 2009-05-23 17:37 ` Christophe TROESTLER 2009-05-23 19:22 ` Jon Harrop 0 siblings, 1 reply; 5+ messages in thread From: Christophe TROESTLER @ 2009-05-23 17:37 UTC (permalink / raw) To: mwipliez; +Cc: caml-list 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 = <fun> 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 (<abstr>, Camlp4.PreCast.Syntax.Ast.ExCom (<abstr>, Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "x")), Camlp4.PreCast.Syntax.Ast.ExCom (<abstr>, Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "y")), Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "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 (<abstr>, Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "x")), Camlp4.PreCast.Syntax.Ast.ExCom (<abstr>, Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "y")), Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "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 (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "x")); Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "y")); Camlp4.PreCast.Syntax.Ast.ExId (<abstr>, Camlp4.PreCast.Syntax.Ast.IdLid (<abstr>, "z"))] Hope it helps, C. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Camlp4 documentation 2009-05-23 17:37 ` Christophe TROESTLER @ 2009-05-23 19:22 ` Jon Harrop 2009-05-23 19:55 ` Christophe TROESTLER 0 siblings, 1 reply; 5+ messages in thread From: Jon Harrop @ 2009-05-23 19:22 UTC (permalink / raw) To: caml-list On Saturday 23 May 2009 18:37:21 Christophe TROESTLER wrote: > Tuples are thus constructed with "ExTup" which is matched by $tup$ : How did you determine that they are matched with $tup$? > Hope it helps, It does, thank you. -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Camlp4 documentation 2009-05-23 19:22 ` Jon Harrop @ 2009-05-23 19:55 ` Christophe TROESTLER 0 siblings, 0 replies; 5+ messages in thread From: Christophe TROESTLER @ 2009-05-23 19:55 UTC (permalink / raw) To: jon; +Cc: caml-list On Sat, 23 May 2009 20:22:38 +0100, Jon Harrop wrote: > > On Saturday 23 May 2009 18:37:21 Christophe TROESTLER wrote: > > Tuples are thus constructed with "ExTup" which is matched by $tup$ : > > How did you determine that they are matched with $tup$? Frankly I can't remember. Possibly in camlp4 sources or in a discussion. Regards, C. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-05-23 19:55 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-05-23 12:24 Camlp4 documentation Jon Harrop 2009-05-23 13:13 ` Re : [Caml-list] " Matthieu Wipliez 2009-05-23 17:37 ` Christophe TROESTLER 2009-05-23 19:22 ` Jon Harrop 2009-05-23 19:55 ` Christophe TROESTLER
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox