Terms can be constructed using functions from the PL_put_*()
and
PL_cons_*()
families. This approach builds the term‘inside-out’,
starting at the leaves and subsequently creating compound terms.
Alternatively, terms may be created‘top-down’, first
creating a compound holding only variables and subsequently unifying the
arguments. This section discusses functions for the first approach. This
approach is generally used for creating arguments for PL_call()
and
PL_open_query().
true
or false
in the term
reference See also PL_put_atom(), PL_unify_bool()
and PL_get_bool().char*
with
various encodings. The flags argument is a bitwise or
specifying the Prolog target type and the encoding of chars.
A Prolog type is one of PL_ATOM
, PL_STRING
,
PL_CODE_LIST
or PL_CHAR_LIST
. A representation
is one of
REP_ISO_LATIN_1
, REP_UTF8
or REP_MB
.
See
PL_get_chars()
for a definition of the representation types. If
len is -1
chars must be
zero-terminated and the length is computed from chars using strlen().Put a string, represented by a length/start pointer pair in the term reference. The data will be copied. This interface can deal with 0-bytes in the string. See also section 12.4.24.
uint64_t
values with the highest
bit set to 1. Without unbounded integer support, too large values raise
a
representation_error
exception.PL_unify_*()
functions or use PL_cons_functor()..
/2
,
while on SWI-Prolog version 7 this is [|]
/2
.TRUE
. Note that in classical Prolog systems or in
SWI-Prolog using the option --traditional, this is the
same as
PL_put_atom_chars("[]")
.
See section 5.1.term_t
objects as the arity of
the functor. To create the term animal(gnu, 50)
, use:
{ term_t a1 = PL_new_term_ref(); term_t a2 = PL_new_term_ref(); term_t t = PL_new_term_ref(); functor_t animal2; /* animal2 is a constant that may be bound to a global variable and re-used */ animal2 = PL_new_functor(PL_new_atom("animal"), 2); PL_put_atom_chars(a1, "gnu"); PL_put_integer(a2, 50); PL_cons_functor(t, animal2, a1, a2); }
After this sequence, the term references a1 and a2 may be used for other purposes.
char **
. The
list is built tail-to-head. The PL_unify_*()
functions can
be used instead to build a list head-to-tail.
void put_list(term_t l, int n, char **words) { term_t a = PL_new_term_ref(); PL_put_nil(l); while( --n >= 0 ) { PL_put_atom_chars(a, words[n]); PL_cons_list(l, a, l); } }
0
to leave the tag unbound. The keys
vector is a vector of atoms of at least len long. The values
is a term vector allocated using PL_new_term_refs()
of at least len long. This function returns TRUE
on success, FALSE
on a resource error (leaving a resource
error exception in the environment),
-1
if some key or the tag is invalid and -2
if there are duplicate keys.