QP_put_*()

Synopsis

These C functions can be used to create new Prolog terms from C.

     #include <quintus/quintus.h>
     
     void QP_put_variable(term)
     QP_term_ref     term;
     
     void QP_put_atom(term, atom)
     QP_term_ref     term;
     QP_atom         atom;
     
     void QP_put_integer(term, integer)
     QP_term_ref     term;
     long int        integer;
     
     void QP_put_float(term, float)
     QP_term_ref     term;
     double          float;
     
     void QP_put_functor(term, name, arity)
     QP_term_ref     term;
     QP_atom         name;
     int             arity;
     
     void QP_put_list(term)
     QP_term_ref     term;
     
     void QP_put_nil(term)
     QP_term_ref     term;
     
     void QP_put_term(term1, term2)
     QP_term_ref     term1;
     QP_term_ref     term2;
     
     void QP_put_db_reference(term, ref)
     QP_term_ref     term1;
     QP_db_reference ref;
     

Description


QP_put_variable()
assigns to term a reference to a new unbound Prolog variable.
QP_put_atom()
assigns to term a reference to the atom represented by atom. atom is assumed to be the canonical representation of a Prolog atom, either obtained from Prolog or returned by QP_atom_from_string().
QP_put_integer()
assigns to term a reference to integer tagged as a Prolog term.
QP_put_float()
assigns to term a reference to the floating point number float tagged as a Prolog term.
QP_put_functor()
assigns to term a reference to a new compound term whose functor is the atom represented by name and whose arity is arity. All the args of the compound term are unbound. This is similar to the Prolog builtin functor/3 with its first argument unbound and its second and third argument bound.
QP_put_list()
assigns to term a reference to a new list whose head and tail are both unbound.
QP_put_nil()
assigns to term a reference to the atom [].
QP_put_term()
assigns to term1 a reference to the term that term2 references. Any reference to another term that term1 contained is lost.
QP_put_db_reference()
assigns to term a reference to the Prolog db_reference represented by ref. ref must have been a reference obtained through QP_get_db_reference(). Any reference to another term that term1 contained is lost.

Examples

flt_to_chars() is a C function that converts a floating point number to a list of characters. Note the use of QP_put_integer().

                                     
foo.pl
foreign(flt_to_chars, flt_to_chars(+float, -term)).
                                      
foo.c
#include <quintus/quintus.h> void flt_to_chars(flt, chars) double flt; QP_term_ref chars; { char buffer[28], *p; int len; QP_term_ref term_char = QP_new_term_ref(); QP_put_nil(chars); sprintf( buffer , "%.17e" , flt ); /* move to end of buffer */ for (p=buffer, len=0; *p; p++, len++); while ( len-- ) { QP_put_integer(term_char, *--p); QP_cons_list(chars, term_char, chars); } }

See Also

QP_term_type(), QP_get_*(), QP_new_term_ref()