On Monday, 17 March 2014 at 09:17:33 UTC, Yuriy wrote:
Hello, I'm new to D, so please excuse me if i'm wrong anywhere.
Ever since i've learned C++ and started practicing templates
metaprogramming (after reading Andrei's book) i wished there
was a language to be low-level as C++, productive as if
interpreted (e.g. Python), and expressive as... well... here
comes D! It's features are great, and specifically now i want
to talk about UDA. This feature is what i lacked in C++, but as
you know, appetite comes with eating, so i think there's still
room for improvement in UDAs.
The problem is current UDAs can't modify definition they're
attached to. The solution is somewhere near Python's
decorators, but of course, using compile-time templates or
mixins.
Here's an example:
template MyAttr(string name, T)
{
}
@MyAttr class MyClass
{
... class body
}
Which should evaluate to something like:
class __MyClassTmpThatWillBeRemovedInCompileTime
{
... class body
}
mixin(MyAttr!("MyClass",
__MyClassTmpThatWillBeRemovedInCompileTime));
Next, MyAttr can modify the class, rename it, ignore it (in
this case MyClass will not be available further), define
something else instead of it.
I could try and modify dmd to support it at least as a
prototype, but before, i'd like to know whether such feature
was already considered and rejected. Thanx.
Seems you want something similar to AST macros [1].
[1] http://wiki.dlang.org/DIP50
--
/Jacob Carlborg