Re: Simple implementation of __FUNCTION

2012-11-06 Thread Simen Kjaeraas
On 2012-46-06 08:11, Don Clugston d...@nospam.com wrote: It fails because you're asking for the full function name, before its type has been determined. (There's no real return type 'auto', 'auto' just means 'work it out for me'). I don't think this is a bug. Although it might be solvable

Re: Simple implementation of __FUNCTION

2012-11-06 Thread r_m_r
I don't know how I missed this thread. I was having the same 'forward reference' error and after a brief chat on #D IRC, thought it might be a compiler bug and reported it as such: http://d.puremagic.com/issues/show_bug.cgi?id=8963 . Should I close this issue? Any thoughts on possible

Re: Simple implementation of __FUNCTION

2012-11-06 Thread Rob T
On Tuesday, 6 November 2012 at 07:46:47 UTC, Don Clugston wrote: It fails because you're asking for the full function name, before its type has been determined. (There's no real return type 'auto', 'auto' just means 'work it out for me'). In our case, the function name that is returned is

Re: Simple implementation of __FUNCTION

2012-11-05 Thread Rob T
On Friday, 2 November 2012 at 22:33:37 UTC, Rob T wrote: I discovered it fails to compile when inside a function with auto as the return type. auto test() { throw new Exception( mixin(__FUNCTION) ); return 0; } Error: forward reference to test but this works int test() { throw new

Re: Simple implementation of __FUNCTION

2012-11-05 Thread Don Clugston
On 06/11/12 07:09, Rob T wrote: On Friday, 2 November 2012 at 22:33:37 UTC, Rob T wrote: I discovered it fails to compile when inside a function with auto as the return type. auto test() { throw new Exception( mixin(__FUNCTION) ); return 0; } Error: forward reference to test but this

Re: Simple implementation of __FUNCTION

2012-11-04 Thread Damian
On Saturday, 3 November 2012 at 17:04:31 UTC, Rob T wrote: On Saturday, 3 November 2012 at 11:09:48 UTC, Jacob Carlborg wrote: I think it would be worth to but in Phobos anyway. I suppose it works as a temp solution until a real one is finally implemented, or maybe the mixin behaviour is

Re: Simple implementation of __FUNCTION

2012-11-04 Thread Rob T
On Sunday, 4 November 2012 at 13:57:07 UTC, Damian wrote: On Saturday, 3 November 2012 at 17:04:31 UTC, Rob T wrote: On Saturday, 3 November 2012 at 11:09:48 UTC, Jacob Carlborg wrote: I think it would be worth to but in Phobos anyway. I suppose it works as a temp solution until a real one

Re: Simple implementation of __FUNCTION

2012-11-03 Thread Jacob Carlborg
On 2012-11-02 23:33, Rob T wrote: That looks better. Not sure what the down side would be if any. Unrelated to either form, I discovered it fails to compile when inside a function with auto as the return type. auto test() { throw new Exception( mixin(__FUNCTION) ); return 0; }

Re: Simple implementation of __FUNCTION

2012-11-03 Thread Rob T
On Saturday, 3 November 2012 at 11:09:48 UTC, Jacob Carlborg wrote: I think it would be worth to but in Phobos anyway. I suppose it works as a temp solution until a real one is finally implemented, or maybe the mixin behaviour is considered a bug and can be fixed?

Simple implementation of __FUNCTION

2012-11-02 Thread Rob T
Thanks to input from the D community, I've managed to implement a reasonable way to log the name of a calling function. This is used for basic execution monitoring and for automated logging of exception errors. Here's what I did. template __FUNCTION() { const char[] __FUNCTION =

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Adam D. Ruppe
On Friday, 2 November 2012 at 17:31:55 UTC, Rob T wrote: Thanks to input from the D community, I've managed to implement a reasonable way to log the name of a calling function. Huh, that's pretty brilliant! The ONLY thing left that I would like to have, is ability to display the function

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Alex Rønne Petersen
On 02-11-2012 18:31, Rob T wrote: Thanks to input from the D community, I've managed to implement a reasonable way to log the name of a calling function. This is used for basic execution monitoring and for automated logging of exception errors. Here's what I did. template __FUNCTION() {

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Regan Heath
On Fri, 02 Nov 2012 18:06:19 -, Alex Rønne Petersen a...@lycus.org wrote: On 02-11-2012 18:31, Rob T wrote: Thanks to input from the D community, I've managed to implement a reasonable way to log the name of a calling function. This is used for basic execution monitoring and for

Re: Simple implementation of __FUNCTION

2012-11-02 Thread H. S. Teoh
On Fri, Nov 02, 2012 at 07:06:19PM +0100, Alex Rønne Petersen wrote: On 02-11-2012 18:31, Rob T wrote: [...] template __FUNCTION() { const char[] __FUNCTION = __traits(identifier, __traits(parent, {})); } Example use in code: throw new Exception( Error: Function ,

Re: Simple implementation of __FUNCTION

2012-11-02 Thread mist
Sweet! You may also find my pull request for phobos ( #863, fullyQualifiedTypename ) useful for adding function signature once it gets finalised and merged. On Friday, 2 November 2012 at 17:31:55 UTC, Rob T wrote: Thanks to input from the D community, I've managed to implement a reasonable

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Jacob Carlborg
On 2012-11-02 18:31, Rob T wrote: Thanks to input from the D community, I've managed to implement a reasonable way to log the name of a calling function. This is used for basic execution monitoring and for automated logging of exception errors. Here's what I did. template __FUNCTION() {

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Rob T
On Friday, 2 November 2012 at 17:55:33 UTC, Adam D. Ruppe wrote: The ONLY thing left that I would like to have, is ability to display the function signature along with the name. template __FUNCTION_SIGNATURE() { const char[] __FUNCTION_SIGNATURE = typeof(__traits(parent, {})).stringof; }

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Philippe Sigaud
By changing this to a standard function: const(char[]) __FUNCTION() @property { return __traits(identifier, __traits(parent, {})); } ... the calling syntax is slightly easier on the eye: void main() { writefln( File: %s, Func: %s, Line: %d, __FILE__, mixin(__FUNCTION), __LINE__ );

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Jonathan M Davis
On Friday, November 02, 2012 22:34:15 Philippe Sigaud wrote: By changing this to a standard function: const(char[]) __FUNCTION() @property { return __traits(identifier, __traits(parent, {})); } ... the calling syntax is slightly easier on the eye: void main() { writefln( File: %s,

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Timon Gehr
On 11/02/2012 10:34 PM, Philippe Sigaud wrote: By changing this to a standard function: const(char[]) __FUNCTION() @property { return __traits(identifier, __traits(parent, {})); } ... the calling syntax is slightly easier on the eye: void main() { writefln( File: %s, Func: %s, Line:

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Philippe Sigaud
On Fri, Nov 2, 2012 at 10:59 PM, Jonathan M Davis jmdavisp...@gmx.com wrote: Is there any downside to this? Identifiers starting with __ are reserved for the compiler/language. It should be __FUNCTION__ if it's built-in, but if it's in the library, I see no reason to name it in a way that

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Rob T
On Friday, 2 November 2012 at 21:34:23 UTC, Philippe Sigaud wrote: By changing this to a standard function: const(char[]) __FUNCTION() @property { return __traits(identifier, __traits(parent, {})); } ... the calling syntax is slightly easier on the eye: void main() { writefln( File:

Re: Simple implementation of __FUNCTION

2012-11-02 Thread Rob T
On Friday, 2 November 2012 at 22:33:37 UTC, Rob T wrote: Unrelated to either form, I discovered it fails to compile when inside a function with auto as the return type. auto test() { throw new Exception( mixin(__FUNCTION) ); return 0; } Error: forward reference to test but this