reference to 'self' inside a function

Rob T rob at ucora.com
Tue Sep 18 16:21:12 PDT 2012


Actually I find the __traits system a bit convoluted and 
inconsistent with other similar features. There seems to be a 
real need to unify the different methods of reflection in D.

For example, I can do this without using __traits

int i;
writeln( i.stringof );

and I can do this

void function x() {};
writeln( x.stringof );

but it won't work for the main function

int main(char[][] args)
{
   writeln( main.stringof ); // compile error (bug?)
}

but this works

writeln(__traits( identifier, main ));

It seems that __traits(itentifier, ) and .stringof are two ways 
of getting access to the same information.

So why do we have __traits and the built in properties that 
overlap in functionality? Why is it inconsistently applied as 
seen with function main (although that could simply be a bug)? 
The situation is rather confusing.

I'll try the bug tracker to report the need for a "self" 
solution, and the inconsistent application of .stringof where it 
fails with main function.

I sure hope the situation will improve.

>
> I agree - except I wouldn't reserve 'self' as a keyword. I'd 
> probably extend the existing __traits mechanism, avoiding the 
> need for the dummy/parent hack. Possibly also create a shortcut 
> for nested __traits?
>
> It's not down to me though - I just wanted to give you 
> something to work with so you can get your project working.
>
> D has a bug tracker where you could post the feature request:
>
> http://d.puremagic.com/issues/enter_bug.cgi?product=D
>
> Good luck :)




More information about the Digitalmars-d mailing list