Is D 0.163 D 1.0?

Chad J gamerChad at _spamIsBad_gmail.com
Tue Jul 25 15:19:29 PDT 2006


Lionello Lunesu wrote:
> 
> 
> I think "static opCall" is a hack to begin with. It's basically a 
> workaround for structs not having constructors. For classes, there's no 
> point in having a static opCall if Walter implements the "A()" construct.
> 

I disagree.  I like being able to use types as functions.
Here's one example where I do something similar to what you'd use nested 
functions for, but better - my forward referencing woes go away.

class F
{
     int result;
     int tempVar1;

     static int opCall( int x )
     {
         F f = new F(x);
         int result = f.result;
         delete f;
         return result;
     }

     this( int x )
     {
         internalFunc1();
         // do stuff
     }

     private void internalFunc1()
     {
         if ( maybe )
             internalFunc2();
         else return;
     }

     private void internalFunc2()
     {
         if ( maybe )
             internalFunc1();
         else return;
     }
}

void main()
{
     int x = 42;
     x = F(x);
}

Under the hood, it may also behave differently than nested functions, 
which could be advantageous.  I'm not sure that it is advantageous, but 
options are always nice.

That and you can make nice syntax sugars for alternative memory 
management methods like freelists, without messing with overriding 'new()'.

> 
> 
> I also prefer "var" to "auto" for the type inference. I don't think 
> anybody expects "var" to be dynamically typed. Well, maybe a few. And 
> then there's the "auto" from C++; it might confuse people if its meaning 
> were changed.
> 
> L.



More information about the Digitalmars-d mailing list