Discussion:
allMembers trait for module
ketmar via Digitalmars-d
2014-10-14 10:10:23 UTC
Permalink
Hello.

i really really wonder if the following program should ouput what it
outputs:

version = wtf;
string listit(alias mod) () {
foreach (m; __traits(allMembers, mod)) {
pragma(msg, m);
}
return "";
}
enum s = listit!(mixin(__MODULE__));

i see this:

object
wtf
listit
s

the question is: wtf "wtf" is doing here?!

two supplement questions:

1. if it's intended to work like this, why we don't have
isVersionSymbol trait?

2. where is isModuleSymbol trait, for that matter? hacks with
'compiles' aren't funny (and can stop working any time).

and the main question: who i need to kill for such traits to be
approved for acception?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141014/ce741862/attachment.sig>
ketmar via Digitalmars-d
2014-10-14 10:59:51 UTC
Permalink
On Tue, 14 Oct 2014 13:10:23 +0300
ketmar via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

mkay, mkay, we have an easy solution to sort out "non-module" symbols:

enum isModuleMember(alias mod, alias id) =
is(typeof(__traits(getMember, mod, id)));

string listit(alias mod) () {
foreach (m; __traits(allMembers, mod)) {
static if (isModuleMember!(mod, m)) {
pragma(msg, m);
}
}
return "";
}

but i still want to know the specie of the alien! bounty of Great
Nothing to the brave person who will do reliable isModuleSymbol
(isModuleSymbol!mod == true) and isVersionSymbol (i bet you can't do
that without nasty hacks! actually, i'm not sure if it's even doable).

our CTFE Lisp implementation still not lispy enough...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141014/62b37be8/attachment.sig>
Loading...