Thread overview
One of us is crazy: Me or {function here}.stringof
Nov 13, 2009
Nick Sabalausky
Nov 13, 2009
Nick Sabalausky
Nov 13, 2009
Bill Baxter
Nov 14, 2009
Don
November 13, 2009
AKA ".stringof strikes again", or ".attackof.stringof"...

Not sure if this is right or not:

------------------------------
void foo(){}
pragma(msg, foo.stringof);
------------------------------

Outputs "foo()", but shouldn't it just be "foo" instead? Or am I overlooking something?

And on top of that, giving foo a parameter:

------------------------------
void foo(int i){}
pragma(msg, foo.stringof);
------------------------------

Error: function main.foo (int) does not match parameter types ()
Error: expected 1 arguments, not 0

WTF?

Ok, so maybe that stupid optional-parens function-invocation "feature" is kicking in where it's not wanted. D's standard way to refer to a function itself is supposed to be '&':

------------------------------
void foo(int i){}
pragma(msg, &foo.stringof);
------------------------------
main.d(2): Error: function main.foo (int) does not match parameter types ()
main.d(2): Error: expected 1 arguments, not 0
main.d(2): Error: "foo()"c is not an lvalue
main.d(2): Error: pragma msg string expected for message, not '&"foo()"c'

FFPPJTTdD!!!!!

Associativity problem?

------------------------------
void foo(int i){}
pragma(msg, (&foo).stringof);
------------------------------
& foo

Argh! (Not to be confused with "Args!")

Sooooooooo.......

If I'm writing a template that takes in a varadic list of variables and functions, and does something with their names, what's the right way to do that (if any)? Trivial example:

------------------------------
template makeBools(idents...)
{
    const char[] foo = "bool _generated_from_"~idents[0].stringof~"_name;" ~
        foo!(idents[1..$]);
}
int i;
void func1(){}
void func2(int x){}
mixin(makeBools!(i, func1, func2)); // Thoroughly fucks up.
------------------------------

I suppose I could resort to passing in string literals, but I'd really rather not have to.


November 13, 2009
"Nick Sabalausky" <a@a.a> wrote in message news:hdj3dk$1r5k$1@digitalmars.com...
> AKA ".stringof strikes again", or ".attackof.stringof"...
>

Ok, *now* I see all the reports of this on bugzilla, now that I searched for just "stringof" and dug through the pile of results, instead of searching for both "stringof" and "function"...Real pain for metaprogramming...


November 13, 2009
On Fri, Nov 13, 2009 at 12:05 AM, Nick Sabalausky <a@a.a> wrote:
> "Nick Sabalausky" <a@a.a> wrote in message news:hdj3dk$1r5k$1@digitalmars.com...
>> AKA ".stringof strikes again", or ".attackof.stringof"...
>>
>
> Ok, *now* I see all the reports of this on bugzilla, now that I searched for just "stringof" and dug through the pile of results, instead of searching for both "stringof" and "function"...Real pain for metaprogramming...

At any rate I think a single stringof for a function is not sufficient.
You might want any of:
    foo
    foo(int, int)
    foo(int a, int b)
There should probably be some __traits functions for getting these
different things, if there aren't already.
--bb
November 14, 2009
Bill Baxter wrote:
> On Fri, Nov 13, 2009 at 12:05 AM, Nick Sabalausky <a@a.a> wrote:
>> "Nick Sabalausky" <a@a.a> wrote in message
>> news:hdj3dk$1r5k$1@digitalmars.com...
>>> AKA ".stringof strikes again", or ".attackof.stringof"...
>>>
>> Ok, *now* I see all the reports of this on bugzilla, now that I searched for
>> just "stringof" and dug through the pile of results, instead of searching
>> for both "stringof" and "function"...Real pain for metaprogramming...
> 
> At any rate I think a single stringof for a function is not sufficient.
> You might want any of:
>     foo
>     foo(int, int)
>     foo(int a, int b)
> There should probably be some __traits functions for getting these
> different things, if there aren't already.
> --bb
Funny thing --  .stringof was a direct response from Walter to my 'meta.nameof' module.
It included  nameOf(xxx), qualifiedNameOf(xxx) and prettyNameOf(xxx), which were the 3 cases you listed above.