Interesting user mistake
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 4 06:38:26 PDT 2015
On Thursday, 3 September 2015 at 18:31:59 UTC, Meta wrote:
> On Thursday, 3 September 2015 at 17:12:31 UTC, H. S. Teoh 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.
>>
>> On that note, though, the unary + operator is totally useless
>> in D... maybe we should get rid of that instead? (Then "=+"
>> will automatically be an error.)
>>
>>
>> T
>
> Worse than useless; it doesn't even behave as you would expect.
>
> import std.stdio;
>
> void main()
> {
> auto a = -1;
> writeln(+a); //Prints -1
> writeln(-a); //Prints 1
> }
>
> At least unary - does something.
I didn't realize that a unary + operator existed. I would have
assumed that +a as an expression would be illegal. It doesn't
even mean anything.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list