next up previous
Next: Interaction with the Up: The Foreign Include Previous: Analysing Terms via

Instantiating and Constructing Terms

Terms are instantiated as in Prolog itself by unification. Variables can be unified with atomic data, with a functor and with other terms. New terms are first constructed as a single unbound variable.

term_t
PL_new_term()
  Create a new term. The term is an unbound variable living on the global stack. In the current implementation it lives until Prolog backtracks to before this call. Garbage collection might change this in the future.
atomic_t
PL_new_atom( char *)
  Create a Prolog atom from a C char *. The contents of the char * are copied to the Prolog heap.
atomic_t
PL_new_string( char *)
  Create a Prolog string, living on the global stack. The contents of the char * are copied into Prolog's data area.
atomic_t
PL_new_integer( long)
  Create a Prolog integer from a C long. Note that the integer is truncated to 28 bits. No checks on this are performed.
atomic_t
PL_new_float( double)
  Create a Prolog float living on the global stack from double.
functor_t
PL_new_functor( atomic_t, int)
  Create a Prolog functor identifier form atomic (which should be an atom) and int, the arity. Arity is valid for any . Arity = 0 is used internally, but none of the interface functions use it.
int
PL_unify( term_t, term_t)
  Unify two terms. Return value is TRUE or FALSE .
int
PL_unify_atomic( term_t, atomic_t)
  Unify a term with an atomic value.
int
PL_unify_functor( term_t, functor_t)
  Unify a term with a functor. The unification simply succeeds if term is already instantiated to a term with functor functor. If term is variable it will be instantiated to the most general term of functor (e.g. a term with all arguments unbound variables). Otherwise FALSE is returned.

If this call succeeds the arguments can be further instantiated by calling PL_arg() and recursively unifying the returned terms.

An example of using these functions is shown in figure gif.



next up previous
Next: Interaction with the Up: The Foreign Include Previous: Analysing Terms via



Passani Luca
Tue Nov 14 08:58:33 MET 1995