Availability:C-language interface function
int PL_unify_list(term_t
?l, term_t -h, term_t -t)Unify l with a list-cell (./2
). If successful,
write a reference to the head of the list into h and a
reference to the tail of the list into t. This reference may
be used for subsequent calls to this function. Suppose we want to return
a list of atoms from a char **
. We could use the example
described by
PL_put_list(),
followed by a call to PL_unify(),
or we can use the code below. If the predicate argument is unbound, the
difference is minimal (the code based on PL_put_list()
is probably slightly faster). If the argument is bound, the code below
may fail before reaching the end of the word list, but even if the
unification succeeds, this code avoids a duplicate (garbage) list and a
deep unification.
foreign_t
pl_get_environ(term_t env)
{ term_t l = PL_copy_term_ref(env);
term_t a = PL_new_term_ref();
extern char **environ;
char **e;
for(e = environ; *e; e++)
{ if ( !PL_unify_list(l, a, l) ||
!PL_unify_atom_chars(a, *e) )
PL_fail;
}
return PL_unify_nil(l);
}