1.4.11 The class PlTail
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 PlTail is created by making a new term-reference pointing to the same object. As PlTail is 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 PlTail
reference 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 the PlTail object now points to the new variable B.This function returns
TRUE
if the unification succeeded andFALSE
otherwise. 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++) l.append(argv[i]); 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 PlTail
and advance
PlTail. Returns
TRUE
on success andFALSE
if PlTail represents the empty list. If PlTail is neither a list nor the empty list, atype_error
is thrown. The example below prints the elements of a list.PREDICATE(write_list, 1) { PlTail tail(A1); PlTerm e; while(tail.next(e)) cout << (char *)e << endl; return TRUE; }