digitalmars.D.learn - Get vars in current scope at compile time?
- Tofu Ninja (4/4) Dec 19 2014 Is there some way to get a list of the variables that are in the
- Rikki Cattermole (2/6) Dec 19 2014 No way to do this.
- bearophile (6/7) Dec 20 2014 But perhaps it's worth supporting as future enhancement with a
- Rikki Cattermole (31/37) Dec 20 2014 Short answer, I'm not keen on the idea, at least not yet.
Is there some way to get a list of the variables that are in the current scope via traits? Some things like allMembers? I would like to be able to call this from a mixin to grab the locals in the scope that the mixin is being dropped into.
Dec 19 2014
On 20/12/2014 10:09 a.m., Tofu Ninja wrote:Is there some way to get a list of the variables that are in the current scope via traits? Some things like allMembers? I would like to be able to call this from a mixin to grab the locals in the scope that the mixin is being dropped into.No way to do this.
Dec 19 2014
Rikki Cattermole:No way to do this.But perhaps it's worth supporting as future enhancement with a __traits. What are the use cases? Bye, bearophile
Dec 20 2014
On 20/12/2014 11:03 p.m., bearophile wrote:Rikki Cattermole:Short answer, I'm not keen on the idea, at least not yet. I would far more comfortable once I've categorized the different types of CTFE implements there can be. Since nobody has really done this before. What makes me more uncomfortable to is DIP50. Looking over it again, this is getting rather close to macro systems in LISP family of language who do have full AST access/modification capabilities. So in other words, its just asking for trouble without some proper thought. Long answer, lets consider this code: void myfunc() { int x, y, z; myvalues(); } void myvalues(string file = __FILE__, string func = __FUNCTION__, int line = __LINE__)() { __traits(functionValues, file, func, line, "z") = __traits(functionValues, file, func, line, "x") + __traits(functionValues, file, func, line, "y") } This was meant to be a little off from what was asked. Because I know this will be wanted eventually. Its nasty ambiguous code. A better way might be to pass in a super function state e.g. void myvalues(SSTATET)(SSTATET SSTATE = __SUPERSTATE__) { with(SSTATE) { z = x + y; } } Same idea, but could be used for e.g. mixin templates and what have you. Want all members of SSTATE? __traits(allMembers to the rescue! Either way, not really D.learn material.No way to do this.But perhaps it's worth supporting as future enhancement with a __traits. What are the use cases? Bye, bearophile
Dec 20 2014