[wg-camlp4] Meta Programming from the view of the implementaion
Alain Frisch
alain at frisch.fr
Thu Jan 31 12:28:18 GMT 2013
On 01/31/2013 12:48 PM, Leo White wrote:
>> >> and << are really not keywords of OCaml, and I wouldn't be
>> surprised they are actually used as operators. I prefer breaking
>> compatibility with camlp4 than with OCaml.
>
> Thinking about it "<:" is not entirely unproblematic. Since "[<" is a
> single token, [<:foo< .. >>] would be awkward for the lexer.
>
> Even if we abandon the camlp4 syntax for quotations
Hurrah :-)
>, I still think that
> {:lid {x{ string }x}} is too heavy and inflexible for traditional
> quotations. For example, a JSON quotation would look like:
>
> {:json {<{ {"streetAddress": "21 2nd Street"} }>}}
I would write this:
(:json {{ {"streetAddress": "21 2nd Street"} }})
And if we keep the "end marker" in the AST, this could be:
{json{ {"streetAddress": "21 2nd Street"} }json}
But maybe we should take a step back, and really ask ourselves why we
should use concrete JSON syntax here. Other possibilities:
1. Write the JSON AST directly as regular OCaml code:
Json.(M["streetAdress", S "21 2snd Street"])
(assuming module Json export constructors M and S.)
2. Use "parsed" OCaml syntax, with some -ppx filter mapping it to JSON AST:
(:json { streetAddress: "21 2snd Street" })
(which would expand to the version above)
3. Use a JSON parser (if we don't need "anti-quotations"):
parse_json "{\"streetAddress\": \"21 2nd Street\"}"
or:
parse_json {{ {"streetAddress: "21 2nd Street"} }}
From all the uses of Camlp4 I've seen listed since the beginning of
this discussion, I can imagine using at some point almost each of them,
except those which are basically "just" about quoting fragments of
external languages in their native syntax. I just don't see the real
benefits.
It would be useful to get feedback from users: do people actually use
pa_tyxml, pa_json, etc, and do they consider this is really better than
proposed alternatives?
Alain
More information about the wg-camlp4
mailing list