public static void UnbindToMarker(VarStack varStack, int marker) { for (int i = varStack.Count - marker; i > 0; i--) // unbind all vars that got bound by Unify { Variable v = varStack.Pop() as Variable; if (v != null) { v.Unbind(); } } }
public bool Retract(BaseTerm t, VarStack varStack, BaseTerm where) { string key = t.Key; if (predefineds.Contains(key)) { IO.Error("retract of predefined predicate {0} not allowed", key); } PredicateDescr pd = this[key]; if (pd == null) { return(false); } InvalidateCrossRef(); ClauseNode c = pd.ClauseList; ClauseNode prevc = null; BaseTerm cleanTerm; int top; while (c != null) { cleanTerm = c.Head.Copy(); top = varStack.Count; if (cleanTerm.Unify(t, varStack)) // match found -- remove this term from the chain { if (prevc == null) // remove first clause { if (c.NextClause == null) // we are about to remove the last remaining clause for this predicate { predTable.Remove(key); // ... so remove its PredicateDescr as well #if arg1index pd.CreateFirstArgIndex(); // re-create #endif ResolveIndices(); } else { pd.SetClauseListHead(c.NextClause); } } else // not the first { prevc.NextClause = c.NextClause; prevc = c; pd.AdjustClauseListEnd(); #if arg1index pd.CreateFirstArgIndex(); // re-create #endif } return(true); // possible bindings must stay intact (e.g. if p(a) then retract(p(X)) yields X=a) } Variable s; for (int i = varStack.Count - top; i > 0; i--) // unbind all vars that got bound by the above Unification { s = (Variable)varStack.Pop(); s.Unbind(); } prevc = c; c = c.NextClause; } ResolveIndices(); return(false); }