Yet another "compile-time reflection revisited" proposal

Jacob Carlborg doob at me.com
Tue Nov 29 13:29:20 PST 2011


On 2011-11-29 21:11, RivenTheMage wrote:
> *1) Replace all symbol-related traits with ".metainfo" property*
>
> __traits(isAbstractClass, A) ==>  A.metainfo.isAbstractClass
>
> __traits(A.func, isVirtualFunction) ==>
> by name: A.metainfo.members["func"].isVirtualFunction
> by index: A.metainfo.members[N].isVirtualFunction
>
> __traits(hasMember, A, "func") ==>  A.metainfo.members.find("func")
>
> Aliasing should be posssible:
> ---
> alias A.metainfo.members mymeta;
> mymeta.find("func");
> ---
>
>
> *2) Replace rest of traits with "meta" keyword*
>
> __traits(compiles, ...) ==>  meta.compiles(...)

It would be good if "compiles" could be a block, but that would be 
inconsistent with the rest. Something like this:

meta.compiles
{
     // code
}

> *4) Add special extendable namespace, accesible through "meta" keyword*
>
> The namespace can be extented by special file "meta.d" which should be a part
> of D runtime. Actually, it's the same thing as std.traits, the intention is
> to put all reflection stuff under one roof.
>
> instead of:
> ---
> import std.traits;
> int foo();
> ReturnType!(foo) x;
> ---
>
> it would be:
> ---
> int foo();
> meta.ReturnType!(foo) x;
> ---

This would basically implicitly import meta.d, like object.di? Would it 
be possible to extend somehow for a user?

> *6) Replace identificator-related "is" expressions with ".metainfo" property*
>
> is(Identifier ...) ==>  Identifier.metainfo.isXXX(...)
>
>
> *7) Replace rest of "is" expressions with "meta.is"*
>
> is(...) ==>  meta.isXXX(...)
>
>
> *5) Replace "typeid" keyword with ".typeinfo" property*
>
> typeid(int) ==>  int.typeinfo
> typeid(typeof(x)) ==>  typeof(x).typeinfo
> typeid(i++) ==>  (i++).typeinfo
>
>
> Thoughts?

I like it.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list