Proposal: new variable definition operator

Daniel Keep daniel.keep.lists at gmail.com
Fri Apr 20 18:42:25 PDT 2007



jovo wrote:
> renoX Wrote:
>> I've already tried to suggest ':=' for type inference (before the implementation), without much success obviously..
> 
> It's so logical next step. It goes sooner or later.
> Perhaps Java will bring it into mainstream first.
> 
>> Worse, D use 'auto' instead of 'var' like Scala does.
> 
> Yes, auto looks arhaick even now. It's so verbose: 
> "Type inference goes on!". Who cares. Wrong emphasis.
> 
> It is actually needed even without type inference. We need
> way to say loudly: "here new variable goes in!" when it can
> be mixed with other code. Nothing better then an operator
> can do, C proved that.
> 
> Interestingly enough, here are Strustrup's words:
> "It cannot be overemphasized that assignment and initialization
> are different operations" 
> (The C++ Programing Language, Special 3rd Edition, page 283)
> 
> And it can be introduced without any code breakage.
> Just allow for now.
> 
> jovo

Just want to nitpick one thing: you seem to think that "auto" is the
type inference keyword.  It isn't.  In D, a declaration is made up of
four parts: the storage class, the type, the identifier and the initialiser.

Obviously the identifier always needs to be there.  If omitted, the
initialiser is just type.init.

Storage class and type are the interesting ones.  In C, you could always
omit the storage class if it was just a regular variable, but always had
to specify the type.  D allows you to omit the type if and only if you
specify the storage class.  Guess what the default storage class is?

auto.

Type inference in D isn't "type inference triggered by keyword", it's
"type inference by omission."  "auto" is only required so that the D
grammar can tell it's supposed to be an declaration.

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list