Programming of Facts
Programmer declares Facts by writing Predicate first and then fact or facts is/are provided inside the brackets. Code statement is ended with full stop ‘.’ operator. It is very easy to convert every day English statements into facts of Prolog language. For example:
Ahmad, Usama and Khurram are good boys. Ahmad and Usama are smart boys. Maria is a good girl.
Open a Visual Prolog editor after clicking the ‘VIP 32′ icon from the programs menu. Open the new file to write code.
Press the save button to save the file in the desired folder and drive directory.
Open the SWI Prolog compiler after clicking the ‘Prolog’ icon from the Programs menu.
These are the steps to compile the desired file:
- Click on the ‘Consult’ submenu after pressing the ‘File’ menu to compile the desired file.
- Select the option ‘Alternate Prolog Source’ from combo box having a label ‘Files of type’.
- Press on the icon of desired Prolog file to compile.
Prolog source code will be compiled and user can write queries.
Queries can be written in simple and compound formats. Simple query format is written to match a single goal where as a compound query format is written to match more than one goal. It is also very easy to write a query using Prolog. Fact is replaced with variable or written as such inside the Predicate to execute the query after compiling the program. Query syntax is shown below.
? Predicate (Variable, Variable).
? good (Name, Gender).
Compiler will display answer after matching the fact.
Two or more simple queries are concatenated by using AND operator to write a Syntax is shown below.
? Predicate (Variable, Variable), Predicate (Variable).
? good (Name, Gender), smart (Name).
Example
Develop a Prolog program for a building that has a kitchen, an office, a hall, a store and a basement. These are the things placed at kitchen, such as apple, cracker and knife. Desk and computers are placed at office. Vacuum cleaner, wiper and washing machine are placed at store. Kitchen has two doors opening in office and hail. Hall has a door for stairs going down to basement.
- Executes simple queries to search the rooms, location of things and doors.
- Executes compound queries to search the location of things that are edible.
Similarly simple queries can be written to check the locations of things in other rooms, such as to check desk and washing machine locations. Conversely it can be checked that what are the things placed inside the rooms other than the kitchen, such as in office and store.
Related posts:
- Programming of Rules and Programming to Fail a Goal Programming of Rules Rules are relationships of facts by providing...
- Programming to Use Rules Inside the Rules and Data Structure and Cut Predicate Programming to Use Rules Inside the Rules Variables declared by...
- Prolog Programming Prolog is a declarative programming language used most widely for...
- Programming of Arithmetic Operators and Predicates and Programming to use Append Using Structures Programming of Arithmetic Operators and Predicates Prolog is used to...
- Fundamentals of VB 6.0 Programming and Programming to Display a String Fundamentals of VB 6.0 Programming VB 6.0 helps a programmer...