QP_put_*()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;
QP_put_variable()
QP_put_atom()
QP_atom_from_string().
QP_put_integer()
QP_put_float()
QP_put_functor()
functor/3 with its first argument
unbound and its second and third argument bound.
QP_put_list()
QP_put_nil()
[].
QP_put_term()
QP_put_db_reference()
QP_get_db_reference(). Any reference to another term that
term1 contained is lost.
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);
}
}
QP_term_type(), QP_get_*(),
QP_new_term_ref()