Suggestion: Change precedence of 'new'

Bill Baxter dnewsgroup at billbaxter.com
Wed Apr 9 22:55:54 PDT 2008


Robert Fraser wrote:
> Unknown W. Brackets wrote:
>> I think the problem is in supporting this syntax:
>>
>> auto x = new package.module.Class;
> 
> The argument (as far as I can tell) is that it would be supported only 
> if trailing parentheses were supplied, so that expression would have to 
> be written as "new package.module.Class().propertyMethod;".

That makes sense.  So the rule would be that 'new' munches all the 
dot-separated identifiers to its right till it hits something besides a 
dot or an identifier.

Here's another one from actual D code ported from Java:

     (new class Runnable {
         public void run() {
             if (canvas.isDisposed()) return;
             render();
             canvas.swapBuffers();
             canvas.getDisplay().timerExec(15, this);
         }
     }).run();

In Java the parens around that whole mess aren't necessary.

--bb



More information about the Digitalmars-d mailing list