Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write custom decorators in D? Similar to python,

Tags:

d

In python you have a function decorators. Is it possible to do something similar in D? something like:

@memoize("expensiveCalc")
int expensiveCalc(string foo){
    ///bar
}
like image 598
carboncomputed Avatar asked Dec 02 '13 18:12

carboncomputed


1 Answers

Yes, it is possible. However, in D it is called an "user defined attribute" (UDA). It has been introduced in D relatively recently, and since then people use it more and more to annotate their functions.

like image 69
DejanLekic Avatar answered Sep 29 '22 18:09

DejanLekic