示例#1
0
            public bool RetractAll(BaseTerm t, VarStack varStack)
            {
                // remark: first-argument indexing is not affected by deleting clauses

                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(true);
                }

                ClauseNode c     = pd.ClauseList;
                ClauseNode prevc = null;
                bool       match = false;

                while (c != null)
                {
                    BaseTerm cleanTerm = c.Term.Copy();

                    if (cleanTerm.IsUnifiableWith(t, varStack)) // match found -- remove this head from the chain
                    {
                        match = true;                           // to indicate that at least one head was found

                        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

                                break;
                            }
                            else
                            {
                                pd.SetClauseListHead(c.NextClause);
                            }
                        }
                        else // not the first
                        {
                            prevc.NextClause = c.NextClause;
                            prevc            = c;
                        }
                    }
                    else
                    {
                        prevc = c;
                    }

                    c = c.NextClause;
                }

                if (match)
                {
#if arg1index
                    pd.DestroyFirstArgIndex(); // rebuilt by ResolveIndices()
#endif
                    pd.AdjustClauseListEnd();
                    ResolveIndices();
                }

                return(true);
            }