Red Code, Green Code (nwcpp video)

David B. Held dheld at codelogicconsulting.com
Wed May 9 22:51:58 PDT 2007


Pragma wrote:
> [...]
> One way I can see this working is to use a custom pragma() - I think I 
> managed to talk Gregor into trying it out in Rodin, at some point or 
> another.  The suggestion isn't a personal bias, it's just that they're 
> pretty much the ideal construct in D for supporting attributes.
> 
> struct ExceptionSafe{
>   static ExceptionSafe opCall(){
>     ExceptionSafe_this;
>     return _this;
>   }
> }
> 
> // attach the ExceptionSafe attribute to the function f()
> pragma(attr,ExceptionSafe()) void f(){
>   /* do something */
> }
> [...]

Interestingly enough, this may well be only the second reasonable 
application of AOP that I've encountered. ;)  The problem here is that 
we want to perform a certain check *on every function*, but we don't 
want to make it *look* like we are performing the check.  Implementing 
these attributes as aspects actually makes a lot of sense.  I wonder 
whether D should try to support AOP somehow...

Dave



More information about the Digitalmars-d mailing list