[wg-camlp4] Request for feedback

Leo White lpw25 at cam.ac.uk
Wed Mar 13 21:32:22 GMT 2013


>>> we can also write:
>>>
>>>    ((@id arg) expr)
>>>
>>> which is equivalent to:
>>>
>>>    (expr (@id arg))
>>
>> As long as you meant
>>
>>      ([@id arg] expr)
>>
>> then this is also a good idea.
>
> No, I really meant (expr (@id arg)).
>

Sorry, what i meant was that it should be ([@id arg] expr) instead of
((@arg) expr). In other words, it should be square brackets like the
other attributes.

>
> I can see that there is a possibility to write awkward code, but I don't think people would actually do it.  We can try
> to find a better syntax, but I would find it sad to pick something more heavy only because the light syntax could
> theoretically allow people to write confusing code.
>
> I don't see "let % lwt" as a worst kind of code than: ...

I do think that 

  let % lwt x = ...

is potentially confusing. Maybe it would be better as

  let . lwt x = ...

since people nearly always write dots without spaces, and a dot
obviously can't be an operator. Another posibility would be

  let .% lwt x = ...

It does seems like we're going from having a single extension syntax to
having many extension syntaxes. I can see the benefit of "let % lwt"
since that will probably be a common extension point (the same goes for
"match % bit") but is there much to be gained from the other possible
keyword extensions. The [%foo expr] syntax provides a clear indication
of which parts are an extension, that is less clear for some other
constructs.

>> I don't think this is a good idea because you are parsing '%' as a
>> strange prefix operator, so that all of the following are allowed:
>>
>> (% foo expr) ( %foo expr ) ( % foo expr )
>>
>> ((* hello world*)%
>>    foo expr
>> )
>
> Again, we can try to fix that in the lexer/parser, or just publicize the "good style".  I don't think that the grammar
> is supposed to prevent people from writing un-readable code, just to allow and encourage them to write good one.

While "let % lwt" may be alright, I do think that

( % id expr )

is a bad idea. It looks too much like a prefix operator. Also, having a
two character delimiter that isn't a single token is different from
every other two character delimiter in the langauge. It also means that
you can't use precedence to resolve conflicts in the parser. Is there
any real benefit in using (%id expr) instead of [%id expr]?


More information about the wg-camlp4 mailing list