I have an identifier that is passed around in various dynamic structures. To help debug, I’d like to have visible various related information, but without filling my program with various debug related predicates – could i use attribute variables, somehow, to centralize the printing of debug information across the many predicates that process the identifier?
What i have in mind is something like an aspectual capability, where i can define a “point-cut” – a location in the code where, when reached, some predicate is called – without including an explicit call at that location.
Key is that all this is defined outside of the program in a separate aspectual-module.
I thought that attribute variables could be a mechanism for this.
A number of solutions are possible but the most appropriated one depends on the details of the code that you want to instrument. I know a few using Logtalk’s categories for hot patching and using the event-driven programming support. The low level SWI-Prolog machinery that is used for tracing also may provide a solution.
Hot patching via a category is used to limit transfer amounts and events are used to generate logging messages. Note that there are other AOP examples in the distribution (e.g. blocks and searching).
I also failed to mention in my previous message SWI-Prolog support for wrapping predicates:
This is really nice, how easily event broadcast can be used for modularizing aspectual functionality.
Any idea what the overhead is for such a feature – although, as long as its for debugging it would matter – i presume that it can be swiched off (selectively?).
Usually you only generate events for selected objects (senders) and messages so it can be as selective as you want. But, as your main use case is debugging, I would not worry much about performance. After debugging, you can simply comment out the calls to define_events/5 and turn off events globally if not used for anything else (actually, that’s the default). Similar for using categories to implement aspects via hot patching, which is also disallowed by default.