Idea for @annotations

Jacob Carlborg doob at me.com
Mon Aug 1 01:33:32 PDT 2011


On 2011-08-01 07:42, %u wrote:
> An idea for a potential use of annotations:
>
> How about being able to annotate _anything_ with a template?
>
> It would be the equivalent of Python's annotations: the template's
> first parameter would be an alias to the thing being annotated, and
> its return value would be the code generated for that element. Of
> course, if there's no transformation being done, then it should
> simply "return" the alias itself.
>
> This would allow you to say something like:
>
> auto memoize(alias Fn, T...)(T args) { /* memoize code here */ }
>
> @memoize
> int fib(int n) { ... }
>
> which would be somewhat (but not completely) "equivalent" to
>
> mixin memoize!(function int(int n) { ... });
>
>
> And more trivial things like @property would simply be
> template property(alias A) { alias A property; }
> with their sole effect being extra information found with
> reflection.
>
>
> Implementing this would obviously be difficult as I would assume,
> but does it sound like a reasonable idea?

I have been thinking that exact same thing. I would love to see that in 
the compiler.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list