Next: , Previous: , Up: cpg-bif   [Contents][Index]


12.3.87 SP_read_from_string()

Synopsis

#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.

Arguments

term

The SP_term_ref to assign.

string

The string to read from.

values

The SP_term_refs to bind variables to. The vector is terminated by 0 (zero). values may be NULL, which is treated as an empty vector.

Return Value

Nonzero on success, and 0 otherwise.

Description

The variables in the term are ordered according to their first occurrence 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.

Examples

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.

See Also

Creating Prolog Terms.



Send feedback on this subject.