The following predicates define the hook types supported by XSB. They must be imported from xsb_hook.
These hooks are called just before XSB exits. You can register as many hooks as you want and all of them will be called on exit (but the order of the calls is not guaranteed). Exit hooks are all 0-ary and must be registered as such:
:- add_xsb_hook(xsb_exit_hook(my_own_exit_hook)).
These hooks are called whenever the program asserts a clause. An assert hook must be a unary predicate, which expects the clause being asserted as a parameter. For instance,
:- add_xsb_hook(xsb_assert_hook(my_assert_hook(_))).registers my_assert_hook/1 as an assert hook. One can register several assert hooks and all of them will be called (but the order is not guaranteed).
These hooks are called whenever the program retracts a clause. A retract hook must be a unary predicate, which expects as a parameter a list of the form [Head,Body], which represent the head and the body parts of the clause being retracted. As with assert hooks, any number of retract hooks can be registered and all of them will be called in some order.