[Up] [Contents] [Index] [Summary]
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:
foreign_t
pl_write_atoms(term_t l)
{ term_t head = PL_new_term_ref(); /* variable for the elements */
term_t list = PL_copy_term_ref(); /* copy as we need to write */
while( PL_get_list(list, head, list) )
{ char *s;
if ( PL_get_atom_chars(head, &s) )
Sprintf("%s\n", s);
else
PL_fail;
}
return PL_get_nil(list); /* test end for [] */
}
- int PL_get_list(term_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.
- int PL_get_head(term_t
+l, term_t -h)
-
If l is a list and not
assign a term-reference
to the head to h.
- int PL_get_tail(term_t
+l, term_t -t)
-
If l is a list and not
assign a term-reference
to the tail to t.
- int PL_get_nil(term_t
+l)
-
Succeeds if represents the atom
.