Download Turbo Prolog for Windows and Start Programming in Prolog
---> ServiceClient failure for DeepLeo[/ERROR]
turboprologdosboxdownloadwindows
Example 3: Rules and Variables
The third example shows how to use rules and variables in Turbo Prolog. Rules are statements that define some logic or relation between facts or other rules. Variables are symbols that represent unknown or variable values that can be instantiated by facts or queries.
To write this program in Turbo Prolog, you need to type:
program rules_and_variables.
% Facts
parent(john,peter).
parent(john,mary).
parent(peter,jack).
parent(mary,jane).
% Rules
grandparent(X,Y) :- parent(X,Z), parent(Z,Y).
% Queries
goal
grandparent(john,X), write('John is the grandparent of '), write(X), nl,
grandparent(Y,jack), write('Jack is the grandchild of '), write(Y), nl.
This program consists of three parts: a program declaration, a set of facts, and a set of rules. The program declaration tells Turbo Prolog the name of the program, which is rules_and_variables in this case.
The facts are parent(john,peter), parent(john,mary), parent(peter,jack), and parent(mary,jane), which describe who is the parent of whom.
The rule is grandparent(X,Y) :- parent(X,Z), parent(Z,Y), which defines who is the grandparent of whom. The rule says that X is the grandparent of Y if X is the parent of Z and Z is the parent of Y. The variables X, Y, and Z can be instantiated by any fact that matches the rule.
The queries are grandparent(john,X) and grandparent(Y,jack), which ask for who is the grandparent of whom. The variables X and Y represent unknown values that match with any fact or rule that satisfies the query.
To run this program, you need to save it with Ctrl+S or F2, compile it with Ctrl+C or F9, and execute it with Ctrl+R or F10. You will see something like this printed on the screen:
John is the grandparent of jack
John is the grandparent of jane
Jack is the grandchild of john
Example 4: Lists and Recursion
The fourth example shows how to use lists and recursion in Turbo Prolog. Lists are data structures that store a sequence of elements of any type. Recursion is a technique that allows a rule to call itself until a base case is reached.
To write this program in Turbo Prolog, you need to type:
program lists_and_recursion.
% Facts
list([1,2,3,4,5]).
% Rules
sum([],0).
sum([HT],S) :- sum(T,S1), S is H + S1.
% Queries
goal
list(L), sum(L,S), write('The sum of '), write(L), write(' is '), write(S), nl.
This program consists of three parts: a program declaration, a fact, and a set of rules. The program declaration tells Turbo Prolog the name of the program, which is lists_and_recursion in this case.
The fact is list([1,2,3,4,5]), which defines a list of numbers.
The rules are sum([],0) and sum([HT],S) :- sum(T,S1), S is H + S1, which define how to calculate the sum of a list of numbers. The first rule says that the sum of an empty list is zero. The second rule says that the sum of a non-empty list is the sum of its head (the first element) and the sum of its tail (the rest of the list). The second rule uses recursion to call itself until the list becomes empty.
The query is list(L), sum(L,S), which asks for the sum of a list. The variable L represents any list that matches with the fact, and the variable S represents any value that matches with the rule.
To run this program, you need to save it with Ctrl+S or F2, compile it with Ctrl+C or F9, and execute it with Ctrl+R or F10. You will see something like this printed on the screen:
The sum of [1,2,3,4,5] is 15
Example 5: Input and Output
The fifth example shows how to use input and output in Turbo Prolog. Input and output are operations that allow a program to interact with the user or other programs by reading and writing data. Turbo Prolog provides some built-in predicates that perform input and output, such as read, write, nl, see, and tell.
To write this program in Turbo Prolog, you need to type:
program input_and_output.
% Queries
goal
write('Enter your name: '), read(Name), nl,
write('Enter your age: '), read(Age), nl,
write('Hello '), write(Name), write(', you are '), write(Age), write(' years old.'), nl.
This program consists of two parts: a program declaration and a goal clause. The program declaration tells Turbo Prolog the name of the program, which is input_and_output in this case.
The goal clause tells Turbo Prolog what to do when it runs the program, which is to ask the user for their name and age and print a greeting message on the screen.
The predicates are write('Enter your name: '), read(Name), nl, write('Enter your age: '), read(Age), nl, write('Hello '), write(Name), write(', you are '), write(Age), write(' years old.'), nl, which perform input and output operations. The predicate write(X) writes the value of X on the screen. The predicate read(X) reads a value from the keyboard and assigns it to X. The predicate nl writes a newline character on the screen. The variables Name and Age represent unknown values that are instantiated by the user input.
To run this program, you need to save it with Ctrl+S or F2, compile it with Ctrl+C or F9, and execute it with Ctrl+R or F10. You will see something like this on the screen:
Enter your name: Alice
Enter your age: 25
Hello Alice, you are 25 years old.
Conclusion
Turbo Prolog is an implementation of the Prolog language that can be used for artificial intelligence software development. Turbo Prolog is no longer supported by Borland, but it can be run on Windows with DOSBox, an x86 emulator with DOS. Turbo Prolog has some features that make it easy and powerful to program in Prolog, such as the Turbo Prolog editor and debugger.
In this article, we showed you how to download and install Turbo Prolog and DOSBox on Windows, and how to run Turbo Prolog on Windows with DOSBox. We also showed you some basic examples of Turbo Prolog programming and how to use facts, queries, rules, variables, lists, recursion, input, and output.
If you want to learn more about Turbo Prolog and DOSBox, you can check out some of the sources that we used for this article. You can find them at the end of this page. They include articles, tutorials, manuals, and videos that will give you more information and guidance on how to use Turbo Prolog and DOSBox.
Turbo Prolog is a great tool for learning and practicing Prolog programming and artificial intelligence concepts. It is also a fun and nostalgic way to experience one of the most popular and powerful Prolog systems of the 1980s. We hope you enjoyed this article and found it useful.
Sources:
DOSBox, an x86 emulator with DOS
Turbo Prolog Installation in Window - YouTube
WinWorld: Turbo Prolog 2.x
Turbo Prolog User's Guide
Turbo Prolog Reference Guide
Prolog / Run PROLOG with DOSBOX on Win10 - YouTube
Plata Quemada - Trailer - YouTube
Conclusion
Turbo Prolog is an implementation of the Prolog language that can be used for artificial intelligence software development. Turbo Prolog is no longer supported by Borland, but it can be run on Windows with DOSBox, an x86 emulator with DOS. Turbo Prolog has some features that make it easy and powerful to program in Prolog, such as the Turbo Prolog editor and debugger.
In this article, we showed you how to download and install Turbo Prolog and DOSBox on Windows, and how to run Turbo Prolog on Windows with DOSBox. We also showed you some basic examples of Turbo Prolog programming and how to use facts, queries, rules, variables, lists, recursion, input, and output.
If you want to learn more about Turbo Prolog and DOSBox, you can check out some of the sources that we used for this article. You can find them at the end of this page. They include articles, tutorials, manuals, and videos that will give you more information and guidance on how to use Turbo Prolog and DOSBox.
Turbo Prolog is a great tool for learning and practicing Prolog programming and artificial intelligence concepts. It is also a fun and nostalgic way to experience one of the most popular and powerful Prolog systems of the 1980s. We hope you enjoyed this article and found it useful. ca3e7ad8fd