yank unary '+'?
KennyTM~
kennytm at gmail.com
Sun Dec 6 12:47:23 PST 2009
On Dec 7, 09 04:30, Don wrote:
> KennyTM~ wrote:
>> On Dec 7, 09 00:23, Andrei Alexandrescu wrote:
>>> Is there any good use of unary +? As an aside, Perl programs do use it
>>> occasionally for syntactic disambiguation :o).
>>>
>>> Andrei
>>
>> Yes, when you want to port the Boost Spirit parser :o) (OK that's an
>> abuse.)
>>
>> Well the unary + can help to emphasize "it's a positive number", and
>> 1.0e+10 is already a form of "unary +" (not the operator).
>>
>> Removing the unary + doesn't lose much, but it doesn't gain much
>> either, and with it already present in all other languages, I don't
>> see a good reason to change it.
>
> I think + should be added to the syntax for numeric literals, and in all
> other cases unary + should be dropped.
> Ie,
> x = +0.78; should remain legal.
> But
> y = +x; should not.
> And likewise,
> x = +(+0.78); should be illegal.
>
> Overloading + is odd, too. Currently:
> +x;
> creates a "has no effect" error if x is a built-in type. But if x has an
> overloaded unary +, it might have side-effects. So it useful ONLY for
> operator abuse!
>
>
import std.math;
auto theta1 = +PI/6;
auto theta2 = -PI/8;
More information about the Digitalmars-d
mailing list