//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 SubListStdLibIterator(Reasoner ts, Unifier un, ITerm[] args, ITerm sublist) { this.ts = ts; this.un = un; this.args = args; this.sublist = sublist; this.c = null; listOutter = (IListTerm)args[1]; list = listOutter.GetAsList(); triedEmpty = false; }