//public bool HasNext() //{ // if (c == null) // the first call of hasNext should find the first response // Find(); // return c != null; //} //public Unifier Next() //{ // if (c == null) Find(); // Unifier b = c; // Find(); // find next response // return b; //} void Find() { while (listOutter != null && listOutter.Count != 0) { while (list.Count != 0) { IListTerm candidate = AsSyntax.AsSyntax.CreateList(list); list.Remove(list.ElementAt(list.Count - 1)); c = un.Clone(); if (c.UnifiesNoUndo(sublist, candidate)) { return; // found another sublist, c is the current response } } listOutter = listOutter.GetNext(); if (listOutter == null || listOutter.IsVar()) // the case of lists with tail { break; } list = listOutter.GetAsList(); } if (!triedEmpty) { triedEmpty = true; c = un.Clone(); if (c.UnifiesNoUndo(sublist, AsSyntax.AsSyntax.CreateList())) { return; // found another sublist, c is the current response } } c = null; // no more sublists found }
//public bool HasNext() //{ // if (c == null) // the first call of hasNext should find the first response // Find(); // return c != null; //} //public Unifier Next() //{ // if (c == null) // Find(); // Unifier b = c; // Find(); // find next response // return b; //} void Find() { while (list.MoveNext()) { IListTerm l = list.Current; if (l.IsVar()) // the case of the tail of the list { break; } c = un.Clone(); if (c.UnifiesNoUndo(sublist, AsSyntax.AsSyntax.CreateList(l))) { return; // found another sublist, c is the current response } } c = null; // no more sublists found }
public override bool HasSubsetAnnot(Literal p, Unifier u) { if (annotations == null) { return(true); } if (!p.HasAnnot()) { return(false); } ITerm thisTail = null; IListTerm pAnnots = p.GetAnnots().CloneLTShallow(); VarTerm pTail = pAnnots.GetTail(); ITerm pAnnot = null; IListTerm pAnnotsTail = null; IEnumerator <ITerm> en = pAnnots.ListTermIterator(); bool enReset = false; IEnumerator <IListTerm> en2 = annotations.ListTermIterator(); // use this iterator to get the tail of the list while (en2.MoveNext()) { IListTerm lt = en2.Current; ITerm annot = lt.GetTerm(); if (annot == null) { break; } if (lt.IsTail()) { thisTail = lt.GetTail(); } if (annotations.IsVar() && !enReset) { enReset = true; en = pAnnots.ListTermIterator(); pAnnot = null; } bool ok = false; while (true) { if (pAnnot != null && u.UnifiesNoUndo(annotations, pAnnot)) { ok = true; en.Dispose(); pAnnot = en.Current; break; } else if (pAnnot != null && pAnnot.CompareTo(annot) > 0) { break; } else if (en.MoveNext()) { pAnnot = en.Current; } else { break; } } if (!ok && pTail != null) { if (pAnnotsTail == null) { pAnnotsTail = (IListTerm)u.Get(pTail); if (pAnnotsTail == null) { pAnnotsTail = new ListTermImpl(); u.Unifies(pTail, pAnnotsTail); pAnnotsTail = (IListTerm)u.Get(pTail); } } pAnnotsTail.Add((ITerm)annot.Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... ok = true; } if (!ok) { return(false); } } if (thisTail != null) { u.Unifies(thisTail, pAnnots); } return(true); }