prolog

In prolog, functors vs predicates, and goals


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 1

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.

EDIT 2

The web site The Power of Prolog by Markus Triska (just saw that he is the user @mat) and its accompanying videos on YouTube like Prolog Terms have helped me greatly.


Solution

  • I try to explain this to my students in the following way: What is father(X,Y) in the following cases (independent from the missing context...)?

    ?- isA(father(X,Y)).
    

    and

    ?- father(X,Y).
    

    In the first case, it's the father functor that constructs a binary term, in the second case, it's a binary predicate.

    The confusion (that they look the same) is also used actively when you go beyond plain Prolog and to things like:

    ?- X = father, X(tim,john).
    

    or using father/2 in a findall query.