Interesting user mistake
Mint via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 4 11:55:01 PDT 2015
On Friday, 4 September 2015 at 17:17:26 UTC, Andrei Alexandrescu
wrote:
> On 09/03/2015 01:08 PM, H. S. Teoh via Digitalmars-d wrote:
>> [...]
>>
>> Is there a way for the lexer to check for the specific
>> character
>> sequence '=', '+', whitespace and not others (e.g. '=',
>> whitespace,
>> '+')? IOW, "a =+ b" will be prohibited, but "a = + b" will be
>> allowed.
>> If so, I agree with this.
>
> Yah, space is relevant there. That's why the check is easiest
> done during tokenization. -- Andrei
Given ` a =+ b `, I see no issue with the statement assuming 'b'
is of some type T that overloads the unary + operator. ie. ` a =
b.opUnary!"+" `
And while the expression could also be written as ` a = +b `,
there's a number of situations where it's hard to control the
formatting (ie. generated mixin code). That, and I can't think of
any other C-like language where ` =+ ` would produce an error.
A simple solution would be to just have unary + perform integer
promotion, as it does in C.
More information about the Digitalmars-d
mailing list