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)
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)
+-Term =..
+-List
=../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)
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)
<
, >
, 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.