11.3.87 functor/3 [ISO]

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:

  1. If Term is initially instantiated, then
  2. If Term is initially uninstantiated, Name and Arity must both be instantiated, and

Exceptions

instantiation_error
Term and either Name or Arity are uninstantiated.
type_error
Name is not atomic, or Arity is not an integer, or Name is not an atom when Arity > 0.
domain_error
Arity is an integer < 0.
representation_error
Term is uninstantiated and Arity > 255.

Examples

     
     | ?- functor(foo(a,b), N, A).
     
     N = foo,
     A = 2
     
     | ?- functor(X, foo, 2).
     
     X = foo(_A,_B)
     | ?- functor(X, 2, 0).
     
     X = 2

See Also

arg/3, name/2, =../2, ref-lte-act.


Send feedback on this subject.