C++ Resyntaxed

renoX renosky at free.fr
Thu Mar 13 07:27:13 PDT 2008


bearophile Wrote:
> This is a short article I have just found on Reddit that shows a possible alternative syntax for C++:
> "A Modest Proposal: C++ Resyntaxed", Ben Werther & Damian Conway:
> http://www.csse.monash.edu.au/~damian/papers/HTML/ModestProposal.html
> 
> It says:
> >The language was designed to ensure that the new syntax was LALR(1) parsable, grammatically unambiguous and required no semantic feedback from parser to tokenizer.<
> 
> That reminds me of D :-)

For the second part yes, but not for the first part :-(

[cut]
> Notes:
> - I presume ^ comes from Pascal.
> - This new syntax uses := and = instead of = and == as in Pascal.

Which is a bad idea here, I know nobody who is confused by =,== instead of := and = more than 5 minutes after an explanation, so let's keep the shortest notation.

> - I like -> to denote a function, but how to denote a delegate?
Easy: use func param -> return for functions and delegate param -> return, not just -> alone (or maybe -> alone is for functions)..

[cut]
> Again they seem more readable to me.
> (This syntax has other differences too, that you can see in the article, but those ones are quite easy to spot and nice).

To me also, this syntax is more readable than C++ or D's one.

I don't agree with some of their decision:
- obj declaration feels weird  for variable, they should have used 'var' like Scala which works both for variable and for objects variable.
- ':=' for assignment: no that's the most usual case, use the shorter '='
- obj <variable_name> : <type>; and obj <variable_name> = <default> : <type>; I prefer Limbo's syntax which works nicely with and without type inference.
var <variable_name> : <type>;   // initialised to <type>'s default value
var <variable_name> : <type> = <value>;   // initialised to <value>
var <variable_name> := <value>;    // type inferred from <value>

Maybe ^ could be used instead of return like in Smalltalk and @ could be used instead of ^ to mean 'pointer to'.

Regards,
renoX





More information about the Digitalmars-d mailing list