

Keyword procedure describes the behavior of predicate, indicating that is will always succeed with only one solution, so no backtracking is required. specifies that factorial is a predicate of arity 2, with known first and unknown second argument.

In main.cl the only added line factorial : (integer N, integer F) procedure (i,o). Factorial: Example for versionsĬreate a new project with UI Strategy “Console” and replace contents of files main.cl and main.pro with given code. end implement main goal mainExe:: run ( main : :run ). clauses run ():- console : : init (), stdio : : write ( "Hello, World!" ), programControl:: sleep ( 1000 ), succeed (). clauses classInfo ( className, classVersion ). Implement main open core constants className = "main". Which makes the predicate of interest evaluate to true (or which refutes the negation of this predicate, which is the same). Given this predicate and the set of rules provided in the program, Prolog engine tries to find a set of variable bindings The purpose of executing Prolog program is evaluation of a single predicate. Perform these service functions as a side effect. They are implemented as predicates without particular meaning which always evaluate successfully and Predicates with multiple arguments can act in several directions depending on which of their argumentsĪlready have a binding and which have none.įinally, to be a general-purpose language, Prolog has to provide a variety of service functions, for example, input/output routines. Prolog has a variety of built-in predicates which act as functions in other languages. While predicates with multiple arguments express the relations between them. Unary predicates express properties of their arguments, (true is a built-in predicate,Īnother important part of Prolog are predicates.

Pure Prolog programs describe relations between processed entities using Horn clauses.Ĭlause is a rule of form Head :- Body., which reads as “to show/solve Head, show/solve Body”.īody consists of several calls to predicates (rule’s goals), combined with conjunction and disjunction.Ĭlauses with empty body are called facts and are equivalent to rules Head :- true.

Prolog was created in 1972 in an attempt to combine the use of logic with knowledge representation. Prolog (from “PROgramming in LOGic”) is a general-purpose programming language.
