Next: , Previous: cpg-ref-SP_raise_exception, Up: cpg-bif

12.3.87 SP_read_from_string()


     #include <sicstus/sicstus.h>
     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.


The SP_term_ref to assign.
The string to read from.
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.


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_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).

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.