functor/3 — builds structures and retrieves information about them
functor(Structure, Functor, Arity)
The principal functor of term
Structure has name
Functor and arity
Functor is an atom. Either
Structure must be instantiated to a term or an atom, or
Arity must be instantiated to an atom and a non-negative integer, respectively.
In the case where
Structure is initially unbound,
functor/3 will unify
Structure with a structured term of
Arity arguments, where the principal functor of the term is
Functor. Each argument of the new structure will be a new uninstantiated variable.
Structure is instantiated to a structured term,
Functor will be unified with the principal functor of
Arity will be unified with the arity.
functor/3 treats atoms as structured terms with arity 0. The principal functor of a list is ‘ . ‘ with arity 2.
?- functor(Structure,fish,2). Structure=fish(_123,_124) yes. ?- functor(city('SantaMonica','CA','USA'), Functor, Arity). Functor=city Arity=3 yes.