Reading Terms¶
Functions:¶
1. X_API int PL_get_name_arity(term_t ts, atom_t name, arity_t arity): : name is assigned the name and arity the arity if term ts, or the operaton fails.
1. X_API int PL_get_arg(int index, term_t ts, term_t a): : a is assigned the argument index from term ts
1. X_API int PL_get_compound_name_arity(term_t ts, atom_t ap, arity_t ip): : ap is assigned the name and ip the arity from term ts
1. X_API int PL_get_atom(term_t ts, atom_t *a): : *a is assigned the atom in term ts, or the operation fails
1. X_API int PL_get_integer(term_t ts, int *i): : *i is assigned the int in term ts, or the operation fails
1. X_API int PL_get_long(term_t ts, long *i):
: *i is assigned the boolean atom true
or false
in term ts, or the operation fails
1. X_API int PL_get_bool(term_t ts, int *i):
1. X_API int PL_get_int/4(term_t ts, int64_t *i): : *a is assigned the int64 in term ts, or the operation fails
1. X_API int PL_get_int64_ex(term_t ts, int64_t *i):
1. X_API int PL_get_intptr(term_t ts, intptr_t *a): : *a is assigned the intptr_t in term ts, or the operation fails
1. X_API int PL_get_uintptr(term_t ts, uintptr_t *a): : *a is assigned the uintptr_t in term ts, or the operation fails
1. X_API int PL_get_atom_chars(term_t ts, char a)*: : a is assigned the string representation of the atom in term ts, or the operation fails
1. X_API int PL_get_atom_nchars(term_t ts, size_t *len, char s): : a is assigned the string representation of the atom in term ts, and len its size, or the operation fails *
1. X_API int PL_get_functor(term_t ts, functor_t *f): : PL_get_chars converts a term t to a string.
From the SWI manual:
int PL_get_chars(term_t +t, char **s, unsigned flags) Convert the argument term t to a 0-terminated C-string. flags is a bitwise disjunction from two groups of constants. The first specifies which term-types should converted and the second how the argument is stored. Below is a specification of these constants. BUF_RING implies, if the data is not static (as from an atom), the data is copied to the next buffer from a ring of sixteen (16) buffers. This is a convenient way of converting multiple arguments passed to a foreign predicate to C-strings. If BUF_MALLOC is used, the data must be freed using free() when not needed any longer.
-
CVT_ATOM Convert if term is an atom
-
CVT_STRING Convert if term is a string
-
CVT_LIST Convert if term is a list of integers between 1 and 255
-
CVT_INTEGER Convert if term is an integer (using d)
-
CVT_FLOAT Convert if term is a float (using f)
-
CVT_NUMBER Convert if term is a integer or float
-
CVT_ATOMIC Convert if term is atomic
-
CVT_VARIABLE Convert variable to print-name
-
CVT_ALL Convert if term is any of the above, except for variables
-
BUF_DISCARDABLE Data must copied immediately
-
BUF_RING Data is stored in a ring of buffers
-
BUF_MALLOC Data is copied to a new buffer returned by malloc(3)
*f is assigned the functor of term ts, or the operation fails
1. X_API int PL_get_float(term_t ts, double *f): : *f is assigned the floating point number of term ts, or the operation fails
1. X_API int PL_get_string_chars(term_t t, char s, size_t len): : s is assigned the string representation of the term ts, and *len its size, or the operation fails
1. X_API int PL_get_string(term_t t, char s, size_t len): : s is assigned the string representation of the string in term ts, and *len its size, or the operation fails
1. X_API int PL_get_list(term_t ts, term_t h, term_t tl): : h is assigned the head of the pair term ts, and tl its tail, or the operation fails
1. X_API int PL_get_head(term_t ts, term_t h): : h is assigned the head of the pair term ts, or the operation fails