functor/3 meta-logical

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

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 ref-lte-act