functor/3
metalogical
Synopsis
functor(+Term, Name, Arity)
functor(Term, +Name, +Arity)
Succeeds if the principal functor of term Term has name
Name and arity Arity.
Arguments
 Term term

 Name atom

 Arity arity

Description
There are two ways of using this predicate:
 If Term is initially instantiated, then
 if Term is a compound term,
Name and Arity are unified with the name and arity of
its principal functor.
 if Term is an atom or number, Name is
unified with Term, and Arity is unified with 0.
 If Term is initially uninstantiated, Name and
Arity must both be instantiated, and
 if Arity is an integer in the range 1..255, then Name must
be an atom, and Term
becomes instantiated to the most general term having the specified
Name and Arity; that is, a term with distinct variables for all
of its arguments.
 if Arity is 0, then
Name must be an atom or a number, and it is unified with
Term.
Examples
 ? functor(foo(a,b), N, A).
N = foo,
A = 2
 ? functor(X, foo, 2).
X = foo(_1,_2)
Please note: _1
and _2
are anonymous variables. The term foo(_1,_2)
is the "most
general" term that has name foo and arity 2.
 ? functor(X, 2, 0).
X = 2
Exceptions
instantiation_error

Term and either Name or Arity are uninstantiated.
type_error

Name is not atomic when Arity is 0, or
Arity is not an integer.
representation_error

Term is uninstantiated and Arity is an integer > 255.
See Also
arg/3
, name/2
, =../2
reflteact