The Trail class is used to manage variable bindings during the execution of Prolog-like predicates.
The trail maintains a stack of trail entries, where each entry represents a variable and its previous value. When a variable is bound to a new value, it is trailed by pushing a trail entry onto the stack. When backtracking occurs, the trail is used to unbind variables back to a certain point, restoring their previous values. During execution the choicepoint created by non-deterministic predicates determines the point (trail index) to which variables are unbound when backtracking occurs. If the user program does repeated searches then the program should call unbind_to(0) to reset all variables back to their initial values before starting the next search. Even if the user program does a complete search there may be variables that are still bound at the end of the search. This can happen either because the user program can determine some initial variable bindings before the first predicate call is made or because the initial predicates in the call chain are deterministic.