digitalmars.D.learn - Listing all functions in a module
- Phil (4/4) Mar 23 2014 Is it possible to enumerate all functions in a module? I'd like
- Phil (3/7) Mar 23 2014 Ah, allMembers does the trick. Probably could have spent a bit
- Rikki Cattermole (17/24) Mar 23 2014 Well I just made this for you, so here it is anyway:
- Philippe Sigaud (4/5) Mar 23 2014 I wonder whether we could have a 'D recipes' page on the wiki, since
- Rikki Cattermole (7/13) Mar 23 2014 I don't know.
- Philippe Sigaud (6/13) Mar 23 2014 Ah, I found one:
- Philippe Sigaud (3/5) Mar 23 2014 There, here it is:
- Phil (3/3) Mar 23 2014 I'm a bit confused about how this example works. I thought
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (2/5) Mar 23 2014 foreach() over a tuple is unrolled at compile time.
- Adam D. Ruppe (3/4) Mar 23 2014 http://wiki.dlang.org/Cookbook
- Phil (4/8) Mar 23 2014 Thanks, that's very helpful; it answered my next question which
Is it possible to enumerate all functions in a module? I'd like my test program to find the functions in a fibrary with a particular attribute defined, but I can't find any way to do this. I've looked in std.traits; maybe I'm missing something.
Mar 23 2014
On Sunday, 23 March 2014 at 12:20:51 UTC, Phil wrote:Is it possible to enumerate all functions in a module? I'd like my test program to find the functions in a fibrary with a particular attribute defined, but I can't find any way to do this. I've looked in std.traits; maybe I'm missing something.Ah, allMembers does the trick. Probably could have spent a bit longer googling that one before posting!
Mar 23 2014
On Sunday, 23 March 2014 at 12:28:06 UTC, Phil wrote:On Sunday, 23 March 2014 at 12:20:51 UTC, Phil wrote:Well I just made this for you, so here it is anyway: module mymodule; import std.stdio : writeln; void main() { foreach(m; __traits(allMembers, mymodule)) { static if (__traits(isStaticFunction, __traits(getMember, mymodule, m))) { writeln(m); } } } void myfunc() { } Output: main myfuncIs it possible to enumerate all functions in a module? I'd like my test program to find the functions in a fibrary with a particular attribute defined, but I can't find any way to do this. I've looked in std.traits; maybe I'm missing something.Ah, allMembers does the trick. Probably could have spent a bit longer googling that one before posting!
Mar 23 2014
On Sun, Mar 23, 2014 at 1:31 PM, Rikki Cattermole <alphaglosined gmail.com> wrote:Well I just made this for you, so here it is anyway:I wonder whether we could have a 'D recipes' page on the wiki, since some question appear regularly. Does one already exist?
Mar 23 2014
On Sunday, 23 March 2014 at 12:45:13 UTC, Philippe Sigaud wrote:On Sun, Mar 23, 2014 at 1:31 PM, Rikki Cattermole <alphaglosined gmail.com> wrote:I don't know. Other than the Rosetta code stuff, I believe there is nothing [0]. However we need to work on D idioms and patterns as well as examples of code. If your wanting to lead please do :) [0] http://rosettacode.org/wiki/Category:DWell I just made this for you, so here it is anyway:I wonder whether we could have a 'D recipes' page on the wiki, since some question appear regularly. Does one already exist?
Mar 23 2014
On Sun, Mar 23, 2014 at 1:52 PM, Rikki Cattermole <alphaglosined gmail.com> wrote:Ah, I found one: http://wiki.dlang.org/Cookbook Obviously, I didn't know this page existed.I wonder whether we could have a 'D recipes' page on the wiki, since some question appear regularly. Does one already exist?I don't know. Other than the Rosetta code stuff, I believe there is nothing [0]. However we need to work on D idioms and patterns as well as examples of code.If your wanting to lead please do :)Well, I'm trying to understand how to add a new recipe, with the correct tag.
Mar 23 2014
There, here it is: http://wiki.dlang.org/Finding_all_Functions_in_a_Module Feel free to edit it!If your wanting to lead please do :)Well, I'm trying to understand how to add a new recipe, with the correct tag.
Mar 23 2014
I'm a bit confused about how this example works. I thought foreach was a runtime loop, so how does nesting static ifs inside it work?
Mar 23 2014
On Sunday, 23 March 2014 at 14:22:07 UTC, Phil wrote:I'm a bit confused about how this example works. I thought foreach was a runtime loop, so how does nesting static ifs inside it work?foreach() over a tuple is unrolled at compile time.
Mar 23 2014
On Sunday, 23 March 2014 at 12:45:13 UTC, Philippe Sigaud wrote:I wonder whether we could have a 'D recipes' page on the wiki,http://wiki.dlang.org/Cookbook Doesn't have much, but there's a start there.
Mar 23 2014
On Sunday, 23 March 2014 at 12:31:47 UTC, Rikki Cattermole wrote:Well I just made this for you, so here it is anyway: ... static if (__traits(isStaticFunction, __traits(getMember, mymodule, m))) ...Thanks, that's very helpful; it answered my next question which was going to be why __traits(someTrait, nameOfSymbolInAnotherModule) didn't work.
Mar 23 2014