# Does Mathematica have a method for achieving the same goals that Aspect Oriented Programming does?

I imagine that this question has been asked before, yet I'm not able to find an answer using the form of the question I believe might be asked.

Is there a mechanism for duplicating the functionality of Aspect Oriented Programming (AOP).

For example, if one has an existing application that accesses a particular set of sensitive files, my desire would be to Log/Monitor/Intercept/Visualize access to and operations upon those files and their data.

Given my shallow faculty with Mathematica I envision that such might take the form:

Intercept[FileSystemScan, FunctionThatDecidesWhenBeforeAfterDuring, FunctionThatDecidesWhatToDo, FunctionThatHandlesErrors]

Intercept[AllFunctionsWithSignatureFooOptionallyIncludingContext,FunctionthatDecidesWhen,FunctionThatDecidesWhat,FunctionThatHandlesErrors]


Or something to that effect.

I looked at Trace, yet that doesn't seem to be exactly that for which I am looking. Yet, perhaps I just do not fully understand it.

• Have a look at UpValues – Sascha Sep 6 '16 at 18:07
• @Sascha Thanks much. I confess I am having some conceptual difficulty with Up and Down Values. – LibertyTrooper Sep 7 '16 at 17:37
• See (96) for discussion of up- and down-values. Up-values are a useful tool to crosscut advice into "call" join points where at least one of the join point arguments has a distinctive head. There is a widely used idiom known as the Villegas-Gayley trick that can wrap advice around a single function (i.e. with little or no crosscutting). – WReach Sep 9 '16 at 18:06
• Also look at Leonid's withUserDefs function. – jkuczm Sep 19 '16 at 14:06