yank unary '+'?
    Don 
    nospam at nospam.com
       
    Sun Dec  6 12:46:39 PST 2009
    
    
  
Walter Bright wrote:
> Andrei Alexandrescu wrote:
>> Is there any good use of unary +? As an aside, Perl programs do use it 
>> occasionally for syntactic disambiguation :o).
> 
> An internet search reveals:
> 
> 1. symmetry
I think it makes sense for literals. Not for anything else though.
Since + is a no-op, it just causes confusion.
> 2. compatibility with C and many other languages that use it
That matters only if those other languages actually have a use for it.
> 3. used with operator overloading to convert a user defined type to its 
> preferred arithmetic representation (a cast can't know what the 
> 'preferred' type is)
 > 5. to coerce default integral promotion rules (again, cast(int) won't
 > always produce the same result)
This one is interesting, and might be the strongest argument, but I 
don't understand it. An example would be interesting.
> 4. to create DSL languages, like Spirit, as Kenny points out
If we are to have a feature specifically for DSL languages, it's not 
hard to come up with something more useful...
(From memory, Spirit uses it as the nearest available approximation to 
postfix +).
> 6. to visually emphasize that a literal is positive
Yes, I think this is the strongest. But this doesn't need unary + in 
general, I don't think. Just for numeric literals.
    
    
More information about the Digitalmars-d
mailing list