Aspect oriented programming: Difference between revisions

m
→‎{{header|J}}: make example slightly easier for a casual reader to follow
m (→‎{{header|J}}: make example slightly easier for a casual reader to follow)
Line 204:
For example, the phrase <code>([echo)</code> prints a value to the screen but is otherwise an identity function. (We could replace <code>echo</code> with an arbitrarily elaborate logging statement if we wished.) And, we can insert this statement into the middle of an expression to gain insight into its progress.
 
Thus, <lang> <-/p:i.5 NB. a mysterious expression
┌─┐
│8│
-/p:([echo)i.5 NB. show the right argument to p:
└─┘
<-/p:([echo)i.5 NB. show the right argument to p:
0 1 2 3 4
┌─┐
8
│8│
-/([echo)p:i.5 NB. show the right argument to -/
└─┘
<-/([echo)p:i.5 NB. show the right argument to -/
2 3 5 7 11
┌─┐
8
│8│
(-([echo))/p:i.5 NB. show the right arguments to -
└─┘
<(-([echo))/p:i.5 NB. show the right arguments to -
11
_4
9
_6
┌─┐
8
│8│
(-~([echo))~/p:i.5 NB. show the left arguments to -
└─┘
<(-~([echo))~/p:i.5 NB. show the left arguments to -
7
5
3
2
┌─┐
8
│8│
-&([echo)/p:i.5 NB. show both the right and left arguments to -
└─┘
<-&([echo)/p:i.5 NB. show both the right and left arguments to -
11
7
Line 233 ⟶ 243:
_6
2
┌─┐
8</lang>
│8│
└─┘
<([echo)-/p:i.5 NB. show the right argument to <
┌─┐
│8│
8└─┘</lang>
 
Or, generally speaking, J provides us with the ability to wrap arbitrary statements with information gathering statements while allowing the original expression to proceed. (And, if we enable debugging, this information gathering can examine the surrounding context, gathering and reporting information on the calling environment, inspecting the local symbol table, the names of routines, the defining script(s), etc.)
6,962

edits