Aspect oriented programming: Difference between revisions

m
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
28
+-/p:([echo)i.5 NB. show the right argument to p:
0 1 2 3 4
8
28
+-/([echo)p:i.5 NB. show the right argument to +-/
2 3 5 7 11
8
28
+&(-([echo))/p:i.5 NB. show the right and left arguments to +-
11
_4
9
_6
8
(-~([echo))~/p:i.5 NB. show the left arguments to -
7
18
5
23
3
26
2
8
28</lang>
-&([echo)/p:i.5 NB. show both the right and left arguments to -
11
7
_4
5
9
3
_6
2
288</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