caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Camlp4 documentation
@ 2009-05-23 12:24 Jon Harrop
  2009-05-23 13:13 ` Re : [Caml-list] " Matthieu Wipliez
  0 siblings, 1 reply; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ messages in thread

* Re: [Caml-list] Camlp4 documentation
  2005-02-18  8:04 ` [Caml-list] Camlp4 documentation Alex Baretta
@ 2005-02-18  8:54   ` Alex Cowie
  0 siblings, 0 replies; 7+ messages in thread
From: Alex Cowie @ 2005-02-18  8:54 UTC (permalink / raw)
  To: Ocaml

Alex Baretta wrote:

> Martin Jambon wrote:
>
>> On Thu, 17 Feb 2005, Christian Szegedy wrote:
>>
>>
>>> Feel free to write your CamlP4 extension ;)
>>
>>
>>
>> :-)
>> But there are few things to know/discover before starting.
>>
>> Is anyone interested in a kind of highly practical tutorial on
>> how to extend the syntax of OCaml with Camlp4?
>> I could possibly start writing one if there is enough demand.
>>
>>
>> Martin
>>
>
> Why yes! Yet, it's terribly sad that DdR chose to forcibly impose upon 
> the Camlp4 metaprogrammer to use the revised syntax. This is probably 
> the main obstacle, together with the relative lack of documentation, 
> to the diffusion of Camlp4, IMHO.
>
> Alex
>
For me, the use of revised syntax has been a disincentive to using 
Camlp4 metaprogramming.  I have always wondered whether a traditional 
syntax version of Camlp4 was technically feasible.  Any comments?

Alex Cowie

--
School of Computer and Information Science
University of South Australia


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Camlp4 documentation
  2005-02-17 22:39 Camlp4 documentation (was: Immediate recursive functions) Martin Jambon
@ 2005-02-18  8:04 ` Alex Baretta
  2005-02-18  8:54   ` Alex Cowie
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Baretta @ 2005-02-18  8:04 UTC (permalink / raw)
  To: Ocaml

Martin Jambon wrote:
> On Thu, 17 Feb 2005, Christian Szegedy wrote:
> 
> 
>>Feel free to write your CamlP4 extension ;)
> 
> 
> :-)
> But there are few things to know/discover before starting.
> 
> Is anyone interested in a kind of highly practical tutorial on
> how to extend the syntax of OCaml with Camlp4?
> I could possibly start writing one if there is enough demand.
> 
> 
> Martin
> 

Why yes! Yet, it's terribly sad that DdR chose to forcibly impose upon 
the Camlp4 metaprogrammer to use the revised syntax. This is probably 
the main obstacle, together with the relative lack of documentation, to 
the diffusion of Camlp4, IMHO.

Alex

-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-05-23 19:55 UTC | newest]

Thread overview: 7+ 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
  -- strict thread matches above, loose matches on Subject: below --
2005-02-17 22:39 Camlp4 documentation (was: Immediate recursive functions) Martin Jambon
2005-02-18  8:04 ` [Caml-list] Camlp4 documentation Alex Baretta
2005-02-18  8:54   ` Alex Cowie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).