If Term is not instantiated, it is bound to a term with functor Functor and arity Arity.
This predicate regards atomic terms (number, atom or string) as terms with arity 0 and functor equal to the term.
To query only the arity of a term, arity/2 can be used instead of functor/3.
Success:
functor(f(1,2),f,2).
functor(f(1,2),F,A). (gives F=f, A=2).
functor(T,f,3). (gives T=f(_g50, _g52, _g54)).
functor(T,.,2). (gives T=[_g48 | _g50]).
functor([],F,A). (gives F=[], A=0).
functor("s",F,A). (gives F="s", A=0).
Fail:
functor(f(1,2),f,3).
functor("compound(g)",compound,1).
functor(f(1,2),"f",2).
Error:
functor(T,F,A). (Error 4).
functor("f",[f],X). (Error 5).
functor(X,[a],Y). (Error 5).
functor(f(1,2),f,-1). (Error 6).