Explain the Structure of PROLOG Program
Basic Structure of PROLOG Program:
domains /* ...domain statements...*/ predicates /* ...predicate statements...*/ goal /* ...subgoal1, subgoal, etc...*/ clauses /* ...clauses(rules and facts)...*/
A PROLOG program is divided into three main sections:
This section includes all facts and rules that make up a program. Facts and rules with the same name must be placed together. A collection of clauses defining a predicate is called a procedure. During execution, the user is prompted to type in a goal after a goal. To find a solution for the entered goal, PROLOG starts at the top of the clauses section, looking at each fact and rule sequentially as it searches for a possible match. For subsequent processing, the PROLOG system places internal pointers next to each clause that matches the current goal or subgoal.
A predicate consists of one or more clauses. Clauses that belong to the same predicate must follow one another. In general, a predicate may be declared as –
predicate_name(arg1, arg2, arg3,..., argn)
If there are no arguments then there is no need for parentheses also. Only the predicate_name is sufficient, it begins with a lowercase letter followed by a sequence of letters, digits and the special character underscore(_). A predicate_name can be a maximum of 250 characters in length.
A user can use problem-related meaningful names to domains even though for PROLOG the same as in-built domains. Usually, user-defined domain names are specified but the PROLOG system doesn’t understand this. So, the user includes within the domains section information about these user-defined domains.