Last Updated:

Example of programs in turbo Prologue language

Let the facts about the books, their authors, and the number of pages be asked. It is necessary to make a rule about which novel can be considered large, and implement this on the Turbo-Prologue. Below is one of the options for solving the task.

Example 1. Work with facts, rules, and variables

% Description of user
domains title, author = symbol
pages = integer

% Description of predicates user
book(title, pages)
written(author, title)

% Facts
wrote (bitter, "MOTHER").
wrote (Sholokhov, "QUIET DON").
book ("QUIET DON", 1250).
book (MOTHER, 310).
/* The rule that determines
which book is considered a great novel */

big_novel (Title) :-
wrote(_, Title), %The author in this case does not care
about the book (Title, Pages),
Pages > 300.

This implementation does not contain internal goals, as it is assumed that the user is working in a TP environment and can ask various questions in the dialogue mode. For example


When answering this question, the TP UNIFIES the values of the variables Who with the objects "author" and What with the objects "title". As a result, the answer is given:

Who=Bitter What="MOTHER"
Who=Sholokhov What="QUIET DON"

2 Solutions

Or this request:


Our database stores two novels that can be considered large because they are larger than 300 pages.

Therefore, the TP will issue the following decision:

Title="MOTHER" Title="QUIET DON"

2 Solutions

In the example above, the TP gives all alternative solutions. This is not always necessary and a special mechanism is provided in the TP - cutting off unnecessary decisions using the built-in predicate "!", and as a decision, the FIRST to
the section of the true result is made.

Let specify information about cars, their price, model and color. It is necessary to buy a bright car at a price not higher than 25,000. The following is a solution to this problem.

Example 2 Buying a bright car at a price of < 25000

buying a car(symbol, symbol)
car(symbol, symbol, integer)
color(symbol, symbol)

buy_car(Model, Color) :-
Car(Model, Color, Price),
colors(Color, bright),!,
% only bright cars
Price < 25000 are considered.

car (Muscovite, green, 25000).
car (Zaporozhets, red, 24000).
Car(corvette, black, 26000).
car (porsche, red, 54000).
colors (red, bright).
colors (black, dim).
colors (green, moderate).

In this implementation, only bright cars have priority. Sign! –clipping, acts on the predicates
of the car (Model, Color, Price), colors (Color, bright)
Therefore in response to an external request


The TP will issue a decision:

Model=Zaporozhets Color=Red
1 Solutions

But if the facts on the objects "Zaporozhets" and "Porsche" are reversed, then the answer of the TP will be negative, since all other bright cars are NOT CONSIDERED, and the price of "Porsche" is more than 25,000. This is the essence of cutting off and the programmer must himself monitor the correctness of the task described on the TP.