QP_compare()
#include <quintus/quintus.h> int QP_compare(term1, term2) QP_term_ref term1; QP_term_ref term2;
Compares the two terms referenced by term1 and term2. Both arguments are term1 before term2
The comparison uses the standard total ordering of Prolog terms
(also used by the built-in Prolog predicate compare/3
).
c_compare(term1, term2)
is an equivalent C version of the Prolog builtin
compare/3
:
foo.plforeign(c_compare, c, c_compare(+term, +term, +term)).
foo.c#include <quintus/quintus.h> int c_compare(t1, t2, t3) QP_term_ref t1, t2; { int res; QP_term_ref l_than = QP_new_term_ref(); QP_term_ref equal = QP_new_term_ref(); QP_term_ref g_than = QP_new_term_ref(); QP_put_atom(l_than, QP_atom_from_string("<")); QP_put_atom(equal, QP_atom_from_string("=")); QP_put_atom(g_than, QP_atom_from_string(">")); res = QP_compare(t2, t3); if ( res < 0) { return QP_unify(t1, l_than); } else if (res == 0) { return QP_unify(t1, equal); } else if (res > 0) { return QP_unify(t1, g_than); } }
QP_unify()
, compare/3