[wg-camlp4] On domain-specific foreign syntaxes

Alain Frisch alain.frisch at lexifi.com
Thu Jan 31 16:48:10 GMT 2013


On 01/31/2013 05:27 PM, Leo White wrote:
>>  - Against the idea that the syntactic aspect of quotations has
>> anything to do with the notion of extension node to be expanded to AST
>> fragments by some code.  They are just independent notions:
>
> Just because quotations do not need to be part of an extension and
> extensions do not need to use quotations does not change the fact that
> they are frequently used together, so a convenient syntax would be
> appreciated.
>
> I really don't understand your objection to including all of the following:
>
> * A quotation syntax: {x{ string }x}
> * A template syntax: {:lid expr}
> * A convenient quotation template syntax: {:lid x| |x}

Ok, so:
   {:lid x|..|x}
is strictly equivalent to:
   {:lid {x{...}x} }
?

Also also equivalent to:
   {:lid "..."}
as long as the string "..." does not contain any special character?

(i.e. the various forms are not distinguished in the Parsetree.)

I won't fight against this syntactic sugar, but I don't like it because:

   1. It adds even more syntax (to be supported by editors, in 
particular), even with a new character (I find the choice of |
as part of a delimiter cognitively dangerous since it is usually used as 
in separator in OCaml syntax).

   2. It creates confusion by conflating two concepts (and I'm not sure 
they will be so commonly used together), and encourage a style of 
expanders based on concrete syntax which, IMO, should rather be discouraged.

> Just
> because you don't like that use case doesn't make it not common.

It is not common at all: the system does not exist yet.  During the 
migration from camlp4 to ppx, it is not bad that people have to think 
twice before choosing a design which forces to combine "expander + 
quotation".

It seems to me that the cases where concrete foreign syntax might be 
useful (copy/paste of large chunks of code) do not necessarily require a 
very compact syntax, and that for shorter "expanders" with a 
high-density of anti-quotations, avoiding concrete syntax is preferable.

But if there is enough demand and if it can help in the transition, I 
won't fight any more against the combined "expander + quotation" 
approach. (I will just cross my fingers so that the developers of tools 
I'll like to use don't force me to use concrete syntax + anti-quotations 
for no good reason.)

>>    begin(:sedlex) match lexbuf with
>>    | ... -> e1
>>    end
>
> I think that this was better as a template:
>
> {:sedlex  match lexbuf with
>     | ... -> e1
> }

Ok, just a different syntax.


-- Alain


More information about the wg-camlp4 mailing list