next up previous contents index
Next: An example: defining write1 Up: Analysing Terms via the Previous: Exchanging text using length   Contents   Index

Reading a list

The functions from this section are intended to read a Prolog list from C. Suppose we expect a list of atoms, the following code will print the atoms, each on a line:


\begin{code}
foreign_t
pl_write_atoms(term_t l)
{ term_t head = PL_new_term_ref(...
...se
PL_fail;
}
\par return PL_get_nil(list); /* test end for [] */
}
\end{code}

intPL_get_listterm_t +l, term_t -h, term_t -t If l is a list and not [] assign a term-reference to the head to h and to the tail to t. intPL_get_headterm_t +l, term_t -h If l is a list and not [] assign a term-reference to the head to h. intPL_get_tailterm_t +l, term_t -t If l is a list and not [] assign a term-reference to the tail to t. intPL_get_nilterm_t +l Succeeds if represents the atom [].



Dr. Richard Botting 2001-12-12