Hello. I am wondering whether backtracking also applies to the constraint store. I have the mental model that the constraint store is by design independent from Prolog's tree-like execution, i.e. if a branch adds constraints to the store that happen to trigger constraint rules deleting constraints or adding new constraints, and this branch eventually fails, then even when backtracking to another branch, the store is left in this modified state. Am I wrong?
Yes you are wrong, constraints are backtracked too.
In the example about even/odd here: https://github.com/gares/mlws18/blob/master/slides.pdf the constraint store is modified "under a not", hence you clearly want to restore the previous state which was not not-satisfiable.
Enrico Tassi said:
Yes you are wrong, constraints are backtracked too.
Great, I needed this feature :rofl: thanks for the answer!
The only hack I have to make something survive backtracking is the safe
thing:
https://github.com/LPCIC/elpi/blob/master/src/builtin.elpi#L472-L483
But it is very limited. Maybe if you explain a bit more in details what you want to do I can provide better guidance.
To make it clear: I needed constraints to backtrack as well :wink: so everything is fine. But thanks for the pointer to safe
in case I need something to persist :+1:
Ah ok, now it makes way more sense ;-)
Last updated: Oct 13 2024 at 01:02 UTC