Noeud: Meta-Logic, Noeud « Next »: , Noeud « Previous »: Information about the State of the Program, Noeud « Up »: Built-In Predicates



Meta-Logic

The predicates in this section are meta-logical and perform operations that require reasoning about the current instantiation of terms or decomposing terms into their constituents. Such operations cannot be expressed using predicate definitions with a finite number of clauses.

var(?X)
Tests whether X is a variable
nonvar(?X)
Tests whether X is not a variable. This is the opposite of var/1.
ground(?X)
Tests whether X is free of unbound variables.
atom(?X)
Checks that X is an atom.
integer(?X)
Checks that X is an integer.
number(?X)
Checks that X is a number.
atomic(?X)
Checks that X is an atom or number.
simple(?X)
Checks that X is a variable, an atom or a number.
compound(?X)
Checks that X is currently a term of arity > 0 i.e. a list or a structure.
functor(+Term,?Name,?Arity)
functor(?Term,+Name,+Arity)
The principal functor of term Term has name Name and arity Arity, where Name is either an atom or, provided Arity is 0, an integer. Initially, either Term must be instantiated, or Name and Arity must be instantiated to, respectively, either an atom and an integer in [0..256) or an atomic term and 0. In the case where Term is initially uninstantiated, the result of the call is to instantiate Term to the most general term having the principal functor indicated.
arg(+ArgNo,+Term,?Arg)
Initially, ArgNo must be instantiated to a positive integer and Term to a compound term. The result of the call is to unify Arg with the argument ArgNo of term Term. (The arguments are numbered from 1 upwards.)
+Term =.. ?List
?Term =.. +List
List is a list whose head is the atom corresponding to the principal functor of Term, and whose tail is a list of the arguments of Term. e.g.
          %>dyalog -s "?-product(0, n, n-1) =.. L. "
          Answer : L = [product,0,n,n - 1]
          %>dyalog -s "?-n-1 =.. L. "
          Answer : L = [-,n,1]
          %>dyalog -s "?-product =.. L. "
          Answer : L = [product]
          

If Term is uninstantiated, then List must be instantiated either to a list of determinate length whose head is an atom, or to a list of length 1 whose head is a number.

name(+Const,?CharList)
name(?Const,+CharList)
If Const is an atom or number then CharList is a list of the character codes of the characters comprising the name of Const. e.g.
          %>dyalog -s "?-name(product,L). "
          Answer : L = [0'p,0'r,0'o,0'd,0'u,0'c,0't]
          
          %>dyalog -s "?-name(1976,L). "
          Answer : L = [0'1,0'9,0'7,0'6]
          

If Const is uninstantiated, CharList must be instantiated to a list of characters. If CharList can be interpreted as a number, Const is unified with that number, otherwise with the atom whose name is CharList.

atom_chars(+Const,?CharList)
atom_chars(?Const,+CharList)
The same as name(Const,CharList), but Const is constrained to be an atom.
number_chars(+Const,?CharList)
number_chars(?Const,+CharList)
The same as name(Const,CharList), but Const is constrained to be a number.
term_subsumer(+Term1, +Term2, -General)
Binds General to the most specific term that generalizes Term1 and Term2. This process is sometimes called anti-unification, as it is the dual of unification.
          %>dyalog -s "?- term_subsumer(f(g(1,h(_))), f(g(_,h(1))), T). "
          Answer : T = f(g(B__2,h(A__2)))
          
          %>dyalog -s "?- term_subsumer(f(1+2,2+1), f(3+4,4+3), T). "
          Answer : T = f(B__2 + C__2,C__2 + B__2)