digitalmars.D - Yet another "compile-time reflection revisited" proposal
- RivenTheMage (37/37) Nov 29 2011 *1) Replace all symbol-related traits with ".metainfo" property*
- Jacob Carlborg (12/49) Nov 29 2011 It would be good if "compiles" could be a block, but that would be
- RivenTheMage (8/17) Nov 29 2011 It can be allowed to pass string as argument (just like in string mixins...
- Timon Gehr (7/44) Nov 29 2011 Yes, __traits should be replaced by a cleaner design eventually.
- RivenTheMage (1/4) Nov 29 2011 Before all, why typeid() is named typeID()? The return type is TypeInfo ...
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (3/7) Nov 29 2011 Leftover from C++.
- Timon Gehr (4/8) Nov 29 2011 It can be used to identify the type because it is a unique reference.
*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(...) *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; --- *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?
Nov 29 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
Nov 29 2011
On 30.11.2011 1:29:16, Jacob Carlborg wrote:It would be good if "compiles" could be a block, but that would be inconsistent with the rest. Something like this: meta.compiles { // code }It can be allowed to pass string as argument (just like in string mixins). And then: meta.compiles( q{ //code })This would basically implicitly import meta.d, like object.di?Yes.Would it be possible to extend somehow for a user?In my proposal - no, it's a part of D runtime.
Nov 29 2011
On 11/29/2011 09:11 PM, 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(...) *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; --- *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?Yes, __traits should be replaced by a cleaner design eventually. 'is'-expressions, typeid and std.traits are perfectly fine as they are now and I don't see any reason to make their syntax more complicated. instead of adding .metainfo we could also just add a bunch of enum members to the typeinfo obtained by typeid. (that would bundle static reflection and rtti). eg. typeid(A).isAbstractClass
Nov 29 2011
Yes, __traits should be replaced by a cleaner design eventually. 'is'-expressions, typeid and std.traits are perfectly fine as they are now and I don't see any reason to make their syntax more complicated.Before all, why typeid() is named typeID()? The return type is TypeInfo :)
Nov 29 2011
On 29-11-2011 23:43, RivenTheMage wrote:Leftover from C++. - AlexYes, __traits should be replaced by a cleaner design eventually. 'is'-expressions, typeid and std.traits are perfectly fine as they are now and I don't see any reason to make their syntax more complicated.Before all, why typeid() is named typeID()? The return type is TypeInfo :)
Nov 29 2011
On 11/29/2011 11:43 PM, RivenTheMage wrote:It can be used to identify the type because it is a unique reference. T a,b; assert(typeid(a) is typeid(b));Yes, __traits should be replaced by a cleaner design eventually. 'is'-expressions, typeid and std.traits are perfectly fine as they are now and I don't see any reason to make their syntax more complicated.Before all, why typeid() is named typeID()? The return type is TypeInfo :)
Nov 29 2011