qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
177 stars 25 forks source link

LES3: Implicit underscore in numeric custom literals? #76

Closed qwertie closed 4 years ago

qwertie commented 5 years ago

Before today my plan was that 1234x and x"1234" would be semantically identical, but on further reflection, perhaps some would like to be able to distinguish numeric literals from string literals that use the same type marker (in this example, x).

To that end we could decree that the type marker on 1234x is _x. You could think of the underscore as a reminder of suffixness, i.e. "_x" means "something followed by x". In this way it is still possible to express it in string form as _x"1234", it's just a bit longer, but x"1234" has a different type marker and therefore, conceptually, has a different data type. The underscore could also act as a signal to the LES printer, telling it "I want this string to be printed in numeric style if possible".

IIRC, the old plan was to use n as the type code on unadorned numbers, so 1234 means n"1234". If we adopt this idea then 1234 would mean _"1234" instead.

As LESv3 does not support negative numbers in numeric format, it is necessary to write negative literals in string form: _"-123". So the downside of this proposal is that explicitly-typed negative literals would become one character longer: _i32"-1234". (LES newbies take note: you can write -1234 of course, but that is not a negative 1234 literal, it is a positive 1234 literal with a negation operator applied to it.) CC @jonathanvdc

qwertie commented 5 years ago

I also wonder if I erred by using '++suf as the name of post-increment (and similarly for other suffix operators). I kinda think 'suf++ would read better. But now that I've made this proposal, I wonder if '_++ would be a good name for post-increment, as _++ is a bit similar to this proposal, with _ acting as a placeholder, this time for an expression, to remind you that the ++ appears afterward.

qwertie commented 4 years ago

This has been implemented for v28.0.