functor
likes(mary, pizza)
, likes/2
is the functor. In a more
complex structure, like
persondata(name(smith, john), date(28, feb, 1963))
persondata/2

There is also a builtin predicate called functor
, used
to extract the name part and arity of a structure.
This builtin predicate takes three arguments:
functor(Term, Name, Arity)
.
It succeeds if Term
is a term
with functor name Name
and arity
Arity
. Examples:
? functor(likes(mary, pizza), Name, Arity). Name = likes Arity = 2 ? functor(likes(X, Y), Name, Arity). X = _G180 Y = _G181 Name = likes Arity = 2 ? functor(likes, Name, Arity). Name = likes Arity = 0 ? functor(X, likes, 2). X = likes(_G232, _G233)
Sometimes there are reasons to want to have the functor name somewhere other
than at the start of the structure. For example, in the expression
X < Y
, "<
/2" is the functor, and so
"<
" is the functor name:
? functor(2 < 4, Name, Arity). Name = (<), Arity = 2. ? 2 < 4. true. ? <(2, 4). true.See op to find out how this works.
The term functor is used in a different sense in mathematics and in functional programming, and a different way again in philosophy.