I am beginning to learn Prolog. I have various books and I even bought the standard. I like things like standards because they define things precisely. But I can't understand some concepts. In particular the difference between functors and predicates, and what is a goal exactly ? Typically the books use a terminology which is varying and sometimes not precise enough adding to the confusion.
In the standard a predication is defined as "a predicate with arity N and a sequence of N arguments" and a predicate as "an identifier together with an arity". Thus when they write something like father(Father, Child)
in The Art of Prolog 2nd, they call father/2
a predicate.
OK but when I check the syntax, we talk about compound terms (not predicates or predications) which are formed of a functor name and arguments. So I checked the definitions in the Standard and saw that a functor is "an identifier together with an arity", the same definition as predicate, and a compound term as "a functor of arity N, N positive, together with a sequence of N arguments".
Thus what is the relation between functors and predicates ? Syntactically they look the same. Why father(Father, Child)
couldn't be called a compound term (I guess it is indeed, syntactically) with functor father/2
instead of predicate father/2
? When do we use one terminology or the other ?
And to put the cherry on top, a goal is "a predication which is to be executed". Do we talk about goals inside the Prolog program or only in the query ? In The Art of Prolog, it is written that "goals are atoms or compound terms". Thus could we talk about goals everywhere in the Prolog program ? My readings make me feel that it is used in the query only. But I'm not sure.
In a query, I guess mother(X, Y)
is a goal and mother/2
a predicate but is mother(X, Y), male(Y)
a goal ? Or composed of two goals ? It is said that a goal can be an atom or a compound term. But if we look at ,
in functional notation then we have a compound term and then a single goal composed of two sub-goals ? I don't understand.
To put it briefly, I don't know when to call things predicate (predication), functor (compound term) or goal.
EDIT
Having read the comments, the answer and other questions (28972038 and 15807506), I came to the conclusion that we have a situation similar to the one in Lisp-like languages : the same notation is used for "executable" code and data. Thus everything is written as terms and a lot of them are compound terms which involves functors and arguments. This is the syntax of data. And the same syntax is used for clauses (facts and rules) which compose a Prolog program. We talk about functors when we focus on the data side of things and predicates when we focus on the "executable" (or interpretable ) side of things, the meaning of the logic program. The focus in question usually depends on the context in which the constructs are used.
:-/2
and two arguments: head and body. Both head and body are again Prolog terms. In addition, I would like to add thatfather/2
is a pretty ambiguous name for a predicate with two arguments:father_child/2
would be much better, because it makes clear what the arguments actually mean. – matwrite_canonical/1
in ISO-compliant Prolog systems to see the canonical syntax of a term. For example:?- write_canonical(my_rule(X, Y) :- father_child(X, Y)).
, yielding::-(my_rule(A,B),father_child(A,B))
. – mat