Re: Trying to get current function name results in compiler error with __traits

2018-12-07 Thread Sepheus via Digitalmars-d-learn
On Friday, 7 December 2018 at 02:37:34 UTC, Arun Chandrasekaran 
wrote:
I'm trying to get the current function name and apparently the 
commented line errors out.


What am I doing wrong?

https://run.dlang.io/is/EGsRU2

```
#!/usr/bin/rdmd

void main()
{
import std.experimental.all;
void foo() {
// __traits(identifier, mixin(__FUNCTION__)).writeln; 
// compilation error

__FUNCTION__.split('.')[$-1].writeln;
}
__traits(identifier, mixin(__FUNCTION__)).writeln;
__FUNCTION__.split('.')[$-1].writeln;
foo();
}
```


Looks like this will do the trick https://run.dlang.io/is/cX3S37



Re: Trying to get current function name results in compiler error with __traits

2018-12-06 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 07 Dec 2018 02:37:34 +, Arun Chandrasekaran wrote:
> I'm trying to get the current function name and apparently the commented
> line errors out.
> 
> What am I doing wrong?

Referring to nested functions is weird.

Dotted identifiers let you traverse aggregates. Modules, C++ namespaces 
(ugh), enums, structs, identifiers, unions, that sort of thing. They 
*don't* let you traverse functions to refer to symbols defined inside 
those functions.

*Separately*, nested functions have names that look like dotted 
identifiers. But you can't use that to refer to them, because that would 
make it *very* awkward to do symbol lookup.

For example:

struct Foo { int bar; }
Foo test()
{
void bar() { }
writeln(&test.bar);
return Foo();
}

Should the `writeln` line invoke the `test` function, get the `bar` field 
from its result, and take its address? Or should it take the address of 
the nested function `bar`?


Trying to get current function name results in compiler error with __traits

2018-12-06 Thread Arun Chandrasekaran via Digitalmars-d-learn
I'm trying to get the current function name and apparently the 
commented line errors out.


What am I doing wrong?

https://run.dlang.io/is/EGsRU2

```
#!/usr/bin/rdmd

void main()
{
import std.experimental.all;
void foo() {
// __traits(identifier, mixin(__FUNCTION__)).writeln; // 
compilation error

__FUNCTION__.split('.')[$-1].writeln;
}
__traits(identifier, mixin(__FUNCTION__)).writeln;
__FUNCTION__.split('.')[$-1].writeln;
foo();
}
```