It really is not so difficult to do, because the Rights restriction rules support a "repository of restrictions", and the implementation of the rules can add , rewrite or delete from this store at runtime. This changes the state of the program and makes it difficult to track global states at runtime.
However, since CHR is integrated into the SWI, you can use the illogical operation nb_setarg / 3 to maintain the number of backtracks .
Notes from the document:
Compatible with GNU-Prolog setarg (A, T, V, false)
This implementation is thread safe, reentrant, and capable of handling exceptions.
EDIT
, , , , , CHR, , "" (= CHR). , , , , , .
:
invalid_state ==> increment_backtracks, fail.
guess <=> branch