Suggestion: Change precedence of 'new'

Unknown W. Brackets unknown at simplemachines.org
Wed Apr 9 21:14:56 PDT 2008


I think the problem is in supporting this syntax:

auto x = new package.module.Class;

In which case, differing it from this is difficult:

auto y = new package.module.Class.propertyMethod;

Anyway, I believe the docs say that it is always an error to rely on 
order of operations... perhaps I'm wrong.

-[Unknown]


Bill Baxter wrote:
> Sometimes it's handy to invoke a function on a class right after 
> creating it:
> 
>     new Thread(&func).run();
> 
> Unfortunately that doesn't work in D right now.  You have to put 
> parentheses around the new expression because it has lower precedence 
> than dotExpression:
> 
>      (new Thread(&func)).run();
> 
> I don't recall how it works in C++, but at least in Java, the first 
> version works.
> 
> I'm not a grammar guru, so can anyone who is say whether the above 
> change would be possible?
> 
> Maybe it would muck up construction based on fully qualified names?   So 
> that
> 
>   new thread.Thread(&func)
> 
> would have to become
> 
>   new (thread.Thread(&func)
> 
> If so that would suck.  But Java is able to make it work somehow, and 
> the construct seems to be used quite heavily there (I've been looking at 
> a lot of SWT code lately...)
> 
> --bb



More information about the Digitalmars-d mailing list