QP_cons_*()

Synopsis

     #include <quintus/quintus.h>
     
     void QP_cons_list(term, head, tail)
     QP_term_ref term;
     QP_term_ref head;
     QP_term_ref tail;
     
     void QP_cons_functor(term, name, arity, arg1, ... ,arg_arity)
     QP_term_ref   term;
     QP_atom       name;
     int           arity;
     QP_term_ref   arg1, ... , arg_arity;
     

Description

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

QP_cons_list() assigns to term a reference to a list whose head is the term referred to by head and whose tail is the term referred to by tail.

QP_cons_functor() assigns to term a reference to a compound term whose functor is the atom represented by name and whose arity is the integer arity. The arguments of the compound term are terms referred to by arg1, arg2, etc. The call to this function should make sure that the number of arguments passed is equal to the arity of the compound term.

Note that the following are equivalent:

QP_cons_list(term, head, tail)

dot = QP_atom_from_string("."); QP_cons_functor(term, dot, 2, head, tail)

However, the former is likely to be more efficient.

Examples

float_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()