- Documentation
- Reference manual
- Packages
- A C++ interface to SWI-Prolog
- A C++ interface to SWI-Prolog (Version 2)
- The class PlTerm (version 2)
- Constructors (version 2)
- Overview of accessing and changing values (version 2)
- Converting PlTerm to native C and C++ types (version 2)
- Unification (version 2)
- Comparison (version 2)
- Analysing compound terms (version 2)
- Miscellaneous (version 2)
- The class PlTermString (version 2)
- The class PlCodeList (version 2)
- The class PlCharList (version 2)
- The class PlCompound (version 2)
- The class PlTail (version 2)
- The class PlTerm (version 2)
- A C++ interface to SWI-Prolog (Version 2)
- A C++ interface to SWI-Prolog
2.10.12 The class PlTail (version 2)
The class PlTail is both for analysing and constructing
lists. It is called PlTail as enumeration-steps make the
term-reference follow theātail' of the list.
- PlTail :: PlTail(PlTerm list)
- A
PlTailis created by making a new term-reference pointing to the same object. AsPlTailis used to enumerate or build a Prolog list, the initial list term-reference keeps pointing to the head of the list. - int PlTail::append(const PlTerm &element)
- Appends element to the list and make the
PlTailreference point to the new variable tail. If A is a variable, and this function is called on it using the argument"gnat", a list of the form[gnat|B]is created and thePlTailobject now points to the new variable B.This function returns
trueif the unification succeeded andfalseotherwise. No exceptions are generated.The example below translates the main() argument vector to Prolog and calls the prolog predicate entry/1 with it.
int main(int argc, char **argv) { PlEngine e(argv[0]); PlTermv av(1); PlTail l(av[0]); for(int i=0; i<argc; i++) PlCheckFail(l.append(argv[i])); PlCheckFail(l.close()); PlQuery q("entry", av); return q.next_solution() ? 0 : 1; } - int PlTail::close()
- Unifies the term with
and returns the result of the unification.[] - int PlTail::next(PlTerm &)
- Bind t to the next element of the list
PlTailand advancePlTail. Returnstrueon success andfalseifPlTailrepresents the empty list. IfPlTailis neither a list nor the empty list, atype_erroris thrown. The example below prints the elements of a list.PREDICATE(write_list, 1) { PlTail tail(A1); PlTerm e; while(tail.next(e)) cout << e.as_string() << endl; return true; }