projog

3.52. functor(T,F,N)

Predicate functor(T,F,N) means "T is a structure with name (functor) F and N number of arguments".

Examples

?- functor(f(a,b,c(Z)),F,N).
F = f
N = 3
Z = UNINSTANTIATED VARIABLE

yes

?- functor(a+b,F,N).
F = +
N = 2

yes

?- functor([a,b,c],F,N).
F = .
N = 2

yes

?- functor(atom,F,N).
F = atom
N = 0

yes

?- functor(X,x,0).
X = x

yes

?- functor(X,x,1).
X = x(_)

yes

?- functor(X,x,2).
X = x(_, _)

yes

?- functor(X,x,3).
X = x(_, _, _)

yes

?- functor(x,x,0).

yes

?- functor(x,x,3).

no

?- functor(x(1,2,3),x,3).

yes

?- functor(x(1,2,3),y,3).

no

?- functor(x(1,2,3),x,0).

no

?- functor(x(1,2,3),x,1).

no

?- functor(x(1,2,3),x,2).

no

?- functor(x(1,2,3),x,4).

no

?- functor([a,b,c],'.',3).

no

?- functor([a,b,c],a,Z).

no

copy(Old, New) :- functor(Old, F, N), functor(New, F, N).

?- copy(sentence(a,b), X).
X = sentence(_, _)

yes