caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Camlp4 3.10.0+beta: lists without $list:...$
@ 2007-03-23  6:13 Martin Jambon
  2007-03-23 16:03 ` [Caml-list] " Markus Mottl
  2007-03-23 16:35 ` Nicolas Pouillard
  0 siblings, 2 replies; 8+ messages in thread
From: Martin Jambon @ 2007-03-23  6:13 UTC (permalink / raw)
  To: caml-list

I managed to create an object type using camlp4orf:

let ctyp_object _loc ml =
   let fields =
     List.fold_left
       (fun o (name, typ) ->
 	 let m = <:ctyp< $lid:name$ : $typ$ >> in
 	 <:ctyp< $o$; $m$ >>)
       <:ctyp< >> ml in
   <:ctyp< < $fields$ > >>

where ml is a list of method declarations of type (string * ctyp) list.
Before we just had to do this:

<:ctyp< < $list:ml$ > >>


Is there anything simpler than my solution? Is a shortcut available?


If not, I think there should really be one. By the way, there should also 
be some shortcut for building list patterns and expressions without 
List.fold_*. A library could do that.


Martin


PS: any progress on the manual? It's kind of hard to test new features 
when you don't know what they are.

--
Martin Jambon
http://martin.jambon.free.fr


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

* Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$
  2007-03-23  6:13 Camlp4 3.10.0+beta: lists without $list:...$ Martin Jambon
@ 2007-03-23 16:03 ` Markus Mottl
  2007-03-23 16:35 ` Nicolas Pouillard
  1 sibling, 0 replies; 8+ messages in thread
From: Markus Mottl @ 2007-03-23 16:03 UTC (permalink / raw)
  To: Martin Jambon; +Cc: caml-list

On 3/23/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> PS: any progress on the manual? It's kind of hard to test new features
> when you don't know what they are.

I agree with Martin.  I find it pretty hard to port my macro code to
the new preprocessor (especially converting it to the non-regular
syntax), both due to the lack of documentation, and possibly also
because some things may be more difficult to do now (maybe I'm wrong
on that).

Regards,
Markus

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com


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

* Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$
  2007-03-23  6:13 Camlp4 3.10.0+beta: lists without $list:...$ Martin Jambon
  2007-03-23 16:03 ` [Caml-list] " Markus Mottl
@ 2007-03-23 16:35 ` Nicolas Pouillard
  2007-03-23 19:00   ` Martin Jambon
  1 sibling, 1 reply; 8+ messages in thread
From: Nicolas Pouillard @ 2007-03-23 16:35 UTC (permalink / raw)
  To: Martin Jambon; +Cc: caml-list

On 3/23/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> I managed to create an object type using camlp4orf:
>
> let ctyp_object _loc ml =
>    let fields =
>      List.fold_left
>        (fun o (name, typ) ->
>          let m = <:ctyp< $lid:name$ : $typ$ >> in
>          <:ctyp< $o$; $m$ >>)
>        <:ctyp< >> ml in
>    <:ctyp< < $fields$ > >>
>
> where ml is a list of method declarations of type (string * ctyp) list.
> Before we just had to do this:
>
> <:ctyp< < $list:ml$ > >>
>
> Is there anything simpler than my solution? Is a shortcut available?

In fact there is some shortcuts but it was not for all constructions
(fixed now in CVS).

There is functions underlining these shortcuts like Ast.tySem_of_list
that join a list with semicolons.

I can explain briefly the change...

Before there was lists inside the tree. In order to allow a fully
reflective mechanism we now avoid these from the AST.

So there is now many more concrete syntax for any part of the AST
(match branches, let bindings, record field bindings...).

(p, None, e) -> <:match_case< $p$ -> $e$ >>
(p, Some guard, e) -> <:match_case< $p$ when $guard$ -> $e$ >>
(loc, field, true, typ) -> <:ctyp< { $lid:field$ : mutable $typ$ } >>
...

If m1 and m2 are to match branches (like (p, None, e) for the old one):

<:match_case< $m1$ | $m2$ >>

You want some default cases:

<:match_case< A -> 1 | $m1$ | B x -> x | $m2$ | _ -> assert False >>

So, when one wrote something like:

  let cases = List.mapi (fun i (_,e) -> <:patt< $int:string_of_int i$
>>, None, e) brs in
  let cases = cases @ [<:patt< _ >>, None, <:expr< raise Ulexing.Error >>] in
  let actions = <:expr< match __ulex_state_0 lexbuf with [ $list:cases$ ] >> in

We now can write:

  let cases = List.mapi (fun i (_,e) -> <:match_case< $`int:i$ -> $e$ >>) brs in
  <:expr< match __ulex_state_0 lexbuf with
                 [ $list:cases$
                 | _ -> raise Ulexing.Error ] } >>

Where the error case is inlined in the match directly.

This <:patt< $int:string_of_int i$ >>, None, e is a typical thing
where no syntax were available to it.
Now you can write <:match_case< $`int:i$ -> $e$ >> since any part of
the abstract syntax have a quotation in concrete syntax.

You can note that in `` [ $list:cases$ '' I used the $list:...$
antiquotation that was used to inject some list in a tree. In 3.10 you
can still do that, but  that's a sugar for a function call that will
join all your trees by the proper separator (bar here).

FYI, I've just added all the missing $list:$ sugars to the CVS version
(will be public soon).

> PS: any progress on the manual? It's kind of hard to test new features
> when you don't know what they are.

I agree, but there is still no progress on the documentation :(

BTW, have you read these slides
http://gallium.inria.fr/~pouillar/pub/camlp4/renovation-camlp4-longue.pdf

-- 
Nicolas Pouillard


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

* Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$
  2007-03-23 16:35 ` Nicolas Pouillard
@ 2007-03-23 19:00   ` Martin Jambon
  2007-03-24 12:21     ` Nicolas Pouillard
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Jambon @ 2007-03-23 19:00 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

On Fri, 23 Mar 2007, Nicolas Pouillard wrote:

> On 3/23/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> > I managed to create an object type using camlp4orf:
> >
> > let ctyp_object _loc ml =
> >    let fields =
> >      List.fold_left
> >        (fun o (name, typ) ->
> >          let m = <:ctyp< $lid:name$ : $typ$ >> in
> >          <:ctyp< $o$; $m$ >>)
> >        <:ctyp< >> ml in
> >    <:ctyp< < $fields$ > >>
> >
> > where ml is a list of method declarations of type (string * ctyp) list.
> > Before we just had to do this:
> >
> > <:ctyp< < $list:ml$ > >>
> >
> > Is there anything simpler than my solution? Is a shortcut available?
>
> In fact there is some shortcuts but it was not for all constructions
> (fixed now in CVS).
...
> You can note that in `` [ $list:cases$ '' I used the $list:...$
> antiquotation that was used to inject some list in a tree. In 3.10 you
> can still do that, but  that's a sugar for a function call that will
> join all your trees by the proper separator (bar here).
>
> FYI, I've just added all the missing $list:$ sugars to the CVS version
> (will be public soon).

Thanks.


> > PS: any progress on the manual? It's kind of hard to test new features
> > when you don't know what they are.
>
> I agree, but there is still no progress on the documentation :(
>
> BTW, have you read these slides
> http://gallium.inria.fr/~pouillar/pub/camlp4/renovation-camlp4-longue.pdf

OK, I am trying to convert my syntax extensions and everyday I hit a new
problem, which by default I report as a bug because if it's not documented
as an intentional incompatiblity, it must be a bug.

I started with pa_json_static.ml
(from http://martin.jambon.free.fr/json-static.html)
because it's fairly complete and doesn't use any dirty trick.
It manipulates all kinds of types, each of them as exprs, patts and ctyps.
So I guess once this works, it would be a big progress toward upgrading
all my stuff.

I'll publish the commented diffs as soon as I get a version that works,
but it would be much faster if you could do it for me. The thing is I
don't really know how I can help.

For now I am stuck with record type definitions:
With quotations in the revised syntax (command camlp4orf), how to create a
record field with an optional mutable flag?

  <:ctyp< $name$ : $opt:is_mutable$ $t1$ >>

gives a syntax error (well, that was yesterday night and it was late and
I don't have the details here, but you can check).
It's only needed because the $list:...$ is not supported for building my
whole record declaration, in version 3.10.0+beta that is.


Thanks

Martin

--
Martin Jambon
http://martin.jambon.free.fr


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

* Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$
  2007-03-23 19:00   ` Martin Jambon
@ 2007-03-24 12:21     ` Nicolas Pouillard
  2007-03-24 20:24       ` Martin Jambon
  2007-03-26  7:27       ` Hendrik Tews
  0 siblings, 2 replies; 8+ messages in thread
From: Nicolas Pouillard @ 2007-03-24 12:21 UTC (permalink / raw)
  To: Martin Jambon; +Cc: caml-list

On 3/23/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> On Fri, 23 Mar 2007, Nicolas Pouillard wrote:
>
> > On 3/23/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:

[...]

> >
> > BTW, have you read these slides
> > http://gallium.inria.fr/~pouillar/pub/camlp4/renovation-camlp4-longue.pdf

Oops I don't remember that was in French (sorry for those that can't read it)

> OK, I am trying to convert my syntax extensions and everyday I hit a new
> problem, which by default I report as a bug because if it's not documented
> as an intentional incompatiblity, it must be a bug.

Yes I understand your point, but that's why I pointed out these slides
that talk about many of these features, even if it's from a
presentation point of view.

> I started with pa_json_static.ml
> (from http://martin.jambon.free.fr/json-static.html)
> because it's fairly complete and doesn't use any dirty trick.
> It manipulates all kinds of types, each of them as exprs, patts and ctyps.
> So I guess once this works, it would be a big progress toward upgrading
> all my stuff.
>
> I'll publish the commented diffs as soon as I get a version that works,
> but it would be much faster if you could do it for me. The thing is I
> don't really know how I can help.

If I start traducing all camlp4 extensions (or the first of everyone),
I'm not done!

<just kidding>
Perhaps there is a need for some consulting services on camlp4 :)
</just kidding>

> For now I am stuck with record type definitions:
> With quotations in the revised syntax (command camlp4orf), how to create a
> record field with an optional mutable flag?
>
>   <:ctyp< $name$ : $opt:is_mutable$ $t1$ >>

Generally all flags: private, mutable, virtual, rec, .., to/downto now
have their own antiquotation.

<:expr< let $rec:is_rec$ f f = f in f >>
<:class_str_item< value $mutable:is_mutable$ x = 42 >>
<:ctyp< < meth1 : int ; meth2 : float $..:raw_variable$ > >>
...

However there is some exceptions to that rule.

A private type is a type surrounded by a node "private".
That's now the same thing for mutable types.

You can define this function if you want:

let mkmutable is_mutable = if is_mutable then <:ctyp< mutable $t$ >> else t

Or rewrite a little the code to take a better profit of this change.

BTW: camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml contains many of
your answers.

Best regards,

-- 
Nicolas Pouillard


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

* Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$
  2007-03-24 12:21     ` Nicolas Pouillard
@ 2007-03-24 20:24       ` Martin Jambon
  2007-03-26  6:48         ` Markus Mottl
  2007-03-26  7:27       ` Hendrik Tews
  1 sibling, 1 reply; 8+ messages in thread
From: Martin Jambon @ 2007-03-24 20:24 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

On Sat, 24 Mar 2007, Nicolas Pouillard wrote:

>> I'll publish the commented diffs as soon as I get a version that works,
>> but it would be much faster if you could do it for me. The thing is I
>> don't really know how I can help.
>
> If I start traducing all camlp4 extensions (or the first of everyone),
> I'm not done!

I would like you or anyone knowledgeable to translate one significant 
syntax extension. You know, some kind of Rosetta stone. You can take 
Markus' sexp syntax extension or ioxml if you prefer, it won't be much 
different.

Thanks for your efforts...


Martin

--
Martin Jambon
http://martin.jambon.free.fr


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

* Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$
  2007-03-24 20:24       ` Martin Jambon
@ 2007-03-26  6:48         ` Markus Mottl
  0 siblings, 0 replies; 8+ messages in thread
From: Markus Mottl @ 2007-03-26  6:48 UTC (permalink / raw)
  To: Martin Jambon; +Cc: Nicolas Pouillard, caml-list

On 3/24/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> I would like you or anyone knowledgeable to translate one significant
> syntax extension. You know, some kind of Rosetta stone. You can take
> Markus' sexp syntax extension or ioxml if you prefer, it won't be much
> different.
>
> Thanks for your efforts...

I'd grately appreciate such a "Rosetta stone", too.  I initially
wanted to use the new camlp4of to translate sexplib, but this
unfortunately seems to be a bad idea, since the non-regular syntax is
obviously currently not well-supported by the macros (see the notes
for bug 4238 in the bugtracker).  Even using camp4orf I ran into
numerous unexpected problems due to the severe lack of documentation.
Either the latter or a "Rosetta stone" would be extremely helpful...

Regards,
Markus

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com


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

* Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$
  2007-03-24 12:21     ` Nicolas Pouillard
  2007-03-24 20:24       ` Martin Jambon
@ 2007-03-26  7:27       ` Hendrik Tews
  1 sibling, 0 replies; 8+ messages in thread
From: Hendrik Tews @ 2007-03-26  7:27 UTC (permalink / raw)
  To: caml-list

"Nicolas Pouillard" <nicolas.pouillard@gmail.com> writes:

   <just kidding>
   Perhaps there is a need for some consulting services on camlp4 :)
   </just kidding>

<not kidding>
No, we just need documentation!
</not kidding>

How about annotating an ocaml grammar with all possible
quotations/antiquotations? Similar to
http://wwwtcs.inf.tu-dresden.de/~tews/ocamlp4/qo_doc.html ?

Couldn't we just start a wiki for that? I mean dump the rules of
the revised syntax into a wiki and then everybody who discovers a
working quotation or antiquotation can just insert it there?

Bye,

Hendrik


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

end of thread, other threads:[~2007-03-26  7:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-23  6:13 Camlp4 3.10.0+beta: lists without $list:...$ Martin Jambon
2007-03-23 16:03 ` [Caml-list] " Markus Mottl
2007-03-23 16:35 ` Nicolas Pouillard
2007-03-23 19:00   ` Martin Jambon
2007-03-24 12:21     ` Nicolas Pouillard
2007-03-24 20:24       ` Martin Jambon
2007-03-26  6:48         ` Markus Mottl
2007-03-26  7:27       ` Hendrik Tews

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).