On 30/03/2011 20:28, Ary Manzana wrote:
I think :: is not used in the language.

In a recent article about D I saw:

mixin(__traits(identifier, T) ~ " " ~
to!string(tolower(__traits(identifier, T)[0])) ~
__traits(identifier, T)[1..$] ~ ";");

What if foo::bar were an alias for __traits(foo, bar) ?

The code would look like this:

mixin(T::identifier ~ " " ~
to!string(tolower(T::identifier[0])) ~
T::identifier[1..$] ~ ";");

What do you think?

Another uses:

__traits(int, isArithmetic) ==> int::isArithmetic
__traits(C, isAbstractClass) ==> C::isAbstractClass

__traits(hasMember, S, "m") ==> S::hasMember("m")

Well, you get the idea...

:: might be applied to other compile time uses, but I just came up with
this...

Hmn, interesting idea! I noticed, however, that the "foo" and "bar" in your example are actually swapped...

__traits(foo, bar) ==> foo::bar

should be

__traits(foo, bar) ==> bar::foo

For many the uses of __traits I can recall off the top of my head, it certainly seems to be both elegant and intuitive. One sore thumb would be __traits(compiles, ...) which I believe gets used quite frequently in Phobos.

Clarifications and my lack of insight into the complete breadth of __traits's capabilities and variations aside, I think this is the best suggestion for the replacement of the much maligned experimental keyword that I have seen posted since Don's suggestion of a magic namespace[1]. I'm not 100% sure if this :: syntax could also tidy up is() expressions too, but if it can, I can imagine it having a lot of support. If language design was a democracy, I'd certainly vote for it ^^

A...

[1] Search the NG for "Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'."

Reply via email to