SP_read_from_string() #include <sicstus/sicstus.h>
int
SP_read_from_string(SP_term_ref t,
const char *string,
SP_term_ref values[])
Assigns to tt the result of reading a term from the its
textual representation string. Variables that occur in the
term are bound to the corresponding term in val.
0 (zero).
values may be NULL, which is treated as an empty
vector.
Nonzero on success, and 0 otherwise.
The variables in the term are ordered according to their first
occurence during a depth first traversal in increasing argument
order. That is, the same order as used by
terms:term_variables_bag/2 (see lib-terms). Variables that
do not have a corresponding entry in vals are ignored. Entries
in vals that do not correspond to a variable in the term are
ignored.
The string should be encoded using the SICStus Prolog internal encoding.
This example creates the term foo(X,42,42,X) (without error
checking):
SP_term_ref x = SP_new_term_ref();
SP_term_ref y = SP_new_term_ref();
SP_term_ref term = SP_new_term_ref();
SP_term_ref vals[] = {x,y,x,0}; // zero-terminated
SP_put_variable(x);
SP_put_integer(y,42);
SP_read_from_string(term, "foo(A,B,B,C).", vals);
#if 0
A corresponds to vals[0] (x),
B to vals[1] (y),
C to vals[2] (x).
A and C therefore both are bound to
the variable referred to by x.
B is bound to the term referred to by y (42).
So term refers to a term foo(X,42,42,X).
#endif
See Reading a goal from a string, for an example of using
SP_read_from_string() to call an arbitrary goal.