- int PL_term_type(term_t)
- Obtain the type of a term, which should be a term returned by one of the
other interface predicates or passed as an argument. The function
returns the type of the Prolog term. The type identifiers are listed
below. Note that the extraction functions
PL_get_*()
also
validate the type and thus the two sections below are equivalent.
if ( PL_is_atom(t) )
{ char *s;
PL_get_atom_chars(t, &s);
...;
}
or
char *s;
if ( PL_get_atom_chars(t, &s) )
{ ...;
}
VersionĀ 7 added PL_NIL
, PL_BLOB
,
PL_LIST_PAIR
and PL_DICT
. Older versions
classify PL_NIL
and PL_BLOB
as PL_ATOM
,
PL_LIST_PAIR
as PL_TERM
and do not have dicts.
PL_VARIABLE | A variable or attributed
variable |
PL_ATOM | A Prolog atom |
PL_NIL | The constant [] |
PL_BLOB | A blob (see section
12.4.10.2) |
PL_STRING | A string (see section
5.2) |
PL_INTEGER | A integer |
PL_RATIONAL | A rational number |
PL_FLOAT | A floating point number |
PL_TERM | A compound term |
PL_LIST_PAIR | A list cell ([H|T] ) |
PL_DICT | A dict (see section
5.4)) |
The functions PL_is_<type> are an alternative to PL_term_type().
The test PL_is_variable(term)
is equivalent to
PL_term_type(term)
== PL_VARIABLE
, but the first is considerably faster. On the
other hand, using a switch over PL_term_type()
is faster and more readable then using an if-then-else using the
functions below. All these functions return either TRUE
or FALSE
.
- bool PL_is_variable(term_t)
- Returns non-zero if term is a variable.
- bool PL_is_ground(term_t)
- Returns non-zero if term is a ground term. See also ground/1.
This function is cycle-safe.
- bool PL_is_atom(term_t)
- Returns non-zero if term is an atom.
- bool PL_is_string(term_t)
- Returns non-zero if term is a string.
- bool PL_is_integer(term_t)
- Returns non-zero if term is an integer.
- bool PL_is_rational(term_t)
- Returns non-zero if term is a rational number (P/Q).
Note that all integers are considered rational and this test thus
succeeds for any term for which PL_is_integer()
succeeds. See also
PL_get_mpq()
and PL_unify_mpq().
- bool PL_is_float(term_t)
- Returns non-zero if term is a float. Note that the
corresponding
PL_get_float()
converts rationals (and thus integers).
- bool PL_is_callable(term_t)
- Returns non-zero if term is a callable term. See callable/1
for details.
- bool PL_is_compound(term_t)
- Returns non-zero if term is a compound term.
- bool PL_is_functor(term_t,
functor_t)
- Returns non-zero if term is compound and its functor is functor.
This test is equivalent to PL_get_functor(),
followed by testing the functor, but easier to write and faster.
- bool PL_is_list(term_t)
- Returns non-zero if term is a compound term using the list
constructor or the list terminator. See also PL_is_pair()
and
PL_skip_list().
- bool PL_is_pair(term_t)
- Returns non-zero if term is a compound term using the list
constructor. See also PL_is_list()
and PL_skip_list().
- bool PL_is_dict(term_t)
- Returns non-zero if term is a dict. See also PL_put_dict()
and PL_get_dict_key().
- bool PL_is_atomic(term_t)
- Returns non-zero if term is atomic (not a variable or
compound).
- bool PL_is_number(term_t)
- Returns non-zero if term is an rational (including integers)
or float.
- bool PL_is_acyclic(term_t)
- Returns non-zero if term is acyclic (i.e. a finite tree).