Introduction

There are two ways of looking at Prolog data structures. One is the proper "object-level" logical way, in which you think of arguments as values. The other is the "meta-logical" way, in which you see them not as lists or trees (or whatever your object-level data types are), but as "terms".

Prolog has the following built-in operations that operate on terms as such:


functor(+Term, -Name, -Arity)
is true when Term is a term, and the principal function symbol of Term is Name, and the arity (number of arguments) of Term is Arity. Alternatively, you may think of this as being true when Term is a term and the principal functor of Term is Name/Arity. All constants, including numbers, are their own principal function symbols, so functor(1.3, 1.3, 0) is true. This may be used to find the functor of a given term, or to construct a term having a given functor.
arg(+Argnum, +Term, -Arg)
is true when Term is a non-variable, Argnum is a positive integer, and Arg is the Argnumth argument of Term. Argument numbering starts at 1. This can only be used to find Arg; Argnum and Term must be given.
+-Term =.. +-List
is true when Term is a term, List is its principal function symbol and the list of the remaining arguments. Use of =../2 can nearly always be avoided, and should be whenever possible, as it is very slow and uses memory unnecessarily (see bas-eff-bdm).
copy_term(+Term, -Copy)
unifies Copy with an alphabetic variant of Term that contains all new variables (see lib-tma-subsumes). That is, copy_term/2 makes a copy of Term by replacing each distinct variable in Term by a new variable that occurs nowhere else in the system, and unifies Copy with the result.
compare(-Order, +Term1, +Term2)
compares Term1 and Term2 with respect to Order, which may be one of <, >, or =. If Order is =, the comparison is actually done with respect to the ==/2 operator on terms.

The system also includes the term comparison predicates ==/2, \==/2, @</2, @>/2, @>/2, @=</2. See ref-lte for more details.