functor(+Term, -Name, -Arity)
functor(-Term, +Name, +Arity)
Succeeds if the principal functor of term Term has name
Name and arity Arity.
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.
- otherwise, 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 atomic, and it is unified with Term.
- Term and either Name or Arity are uninstantiated.
- Name is not atomic, or
Arity is not an integer, or
Name is not an atom when Arity > 0.
- Arity is an integer < 0.
- Term is uninstantiated and Arity > 255.
| ?- functor(foo(a,b), N, A).
N = foo,
A = 2
| ?- functor(X, foo, 2).
X = foo(_A,_B)
| ?- functor(X, 2, 0).
X = 2
Send feedback on this subject.