A query to the Prolog interpreter consists of one or more goals. For example, in

?- lectures(john, Subject), studies(Student, Subject).

there are two goals, lectures(john, Subject) and studies(Student, Subject). A goal is something that Prolog tries to satisfy by finding values of the variables (in this case Student and Subject) that make the goal succeed. These value(s) are then said to be bound to the variable(s). If Prolog is unable to do this, the goal fails (and Prolog will print "false" in response to the query). If all the goals in a query succeed, Prolog prints the bindings necessary to make the query succeed. (If you then, in SWI Prolog, type a semicolon (;) Prolog will backtrack and look for another set of bindings that will satisfy the goals in the query.

Sometimes it is not necessary to bind variables in order to satisfy a goal. For example, there is no variable to bind, when the goal is likes(mary, pizza) and the Prolog database already contains likes(mary, pizza). In this case, Prolog will print "true" in response to the query, rather than printing bindings.

Goals occur in rules as well as in queries. In

happy(Dog) :-
is_dog(Dog) and go_for_walk(Dog) are the two goals that form the body of the rule.