May 28, 2006
Jarrett Billingsley wrote:
> "Norbert Nemec" <Norbert@Nemec-online.de> wrote in message news:e596k7$2k4o$1@digitaldaemon.com...
> 
>> Maybe that common confusion could be lifted by introducing a new storage class (e.g. "local" or "var") indicating a "plain old local variable". This would be the default for any variable declared with a type and without storage class, but it would be useful in declaring a type-induced variable that is not intended to be an auto variable.
> 
> We already have it; it's called "auto"  ;)  That's exactly what auto means - a plain old variable, one which is not accessible once the scope ends.  It's already the default storage class for variables declared without one. That's why we use auto to indicate type inference for most variables, because they're plain old local variables, and that's the default storage class.

Sorry, but I disagree:
before type inference came along, "auto" already had a meaning. It said:
"This is *not* a plain old local variable but one that is deleted
automatically at end of scope." (In your terms, "auto" always meant RAII
in D)

> The problem is just when it comes to auto classes.  Either we come up with a new keyword for the behavior of auto classes, i.e. "raii":
> 
> raii Foo f = new Foo();
> 
> // Type inference
> raii g = new Goo();

What you suggest here, is to change the meaning of "auto" and then introduce a new keyword for what was "auto" before. At the moment, "auto" means RAII. What we need is a keyword for non-RAII storage class.

Up to now, such a keyword was not necessary. With type inference, it became necessary.
May 28, 2006
"Norbert Nemec" <Norbert@Nemec-online.de> wrote in message news:e5cl29$iat$1@digitaldaemon.com...

> Sorry, but I disagree:
> before type inference came along, "auto" already had a meaning. It said:
> "This is *not* a plain old local variable but one that is deleted
> automatically at end of scope." (In your terms, "auto" always meant RAII
> in D)

And before RAII classes came along, 'auto' already had a meaning then too!

'auto' only has special meaning for class references.  auto is also the default storage class for regular local variables, and is not a D-ism - it's from C.

What I'm proposing is that the class 'auto' is very different from the regular 'auto', and as such, they should have different keywords.  The class 'auto' is more like a separate storage class, and if D gains the ability for RAII classes to have lifetimes dependent upon an owning class, that will be even more of a reason to have a separate storage class for RAII classes.

> What you suggest here, is to change the meaning of "auto" and then introduce a new keyword for what was "auto" before. At the moment, "auto" means RAII. What we need is a keyword for non-RAII storage class.

Currently, 'auto' is not consistent - it means one thing for non-class-references and another for class references.  What I'm suggesting is that "auto" go back to the way it was before RAII classes were introduced; that is, it's just a "plain old local variable which is not accessible after this scope exits."  With this new behavior, it will work as such:

auto int v = 0; // identical to just "int v = 0", just as it is now.
auto w = 5;  // same as it is now.
auto x = new X(); // Type inference; not a RAII class, like now.

And with the new 'raii' keyword (or equivalent):

raii Y y = new Y(); // Same as current "auto Y y = new Y();"
raii z = new Z(); // Type inference with RAII; currently impossible


May 28, 2006
Maybe something along the lines of one older proposal ?

// use 'auto' for type inference

auto k = Foo(2);          // raii; could be on the stack
auto l = new Foo(2);      // on the heap, gc'd

auto i = 1;               // raii in a way; on the stack
auto j = new int(1);      // on the heap, gc'd


That would mean one couldn't use static opCall, but it's usually used to fake ctors anyway...

/+
  To everyone: please don't suggest the 'raii' keyword... It's totally counter-intuitive in this case.
+/



-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d-pu s+: a-->----- C+++$>++++ UL P+ L+ E--- W++ N++ o? K? w++ !O !M V? PS- PE- Y PGP t 5 X? R tv-- b DI- D+ G e>+++ h>++ !r !y
------END GEEK CODE BLOCK------

Tomasz Stachowiak  /+ a.k.a. h3r3tic +/
1 2
Next ›   Last »