PCPF Experiment No - 11 Prolog: Steps For Installing SWI Prolog in Windows

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

PCPF EXPERIMENT NO – 11

PROLOG
Steps for installing SWI Prolog in Windows.

 Using an Internet browser navigate to SWI-PROLOG  home page: https://www.swi-


prolog.org/ 

 Mouse over Download.

 Click SWI-Prolog
This will take you download page: https://www.swi-prolog.org/Download.html

 Under Binaries click on the (64-bit) version.

 For this example it currently is SWI-Prolog 8.3.6-1 for Microsoft Windows (64 bit)

 a. Select I understand
b. Click Download swipl-8.3.6-1.x64.exe

 This will open a Save As dialog on Windows. Select a directory and click Save.

 Then click Yes.
This will start the installation wizard.

Note : If there was a previous version of SWI-Prolog installed a dialog will ask


Do you want to uninstall the old version before installing the new one?
Any option is valid.
 Click Next

 Click Next
 Click Next

 Click Install and finally


 Click Finish

B) Steps to write, compile & execute Prolog code using simple example.

 Double-click the Prolog program icon.


 Then a SWI Command Prompt will appear on the screen where you will execute your
queries.
 In the command prompt click on File and then NEW.
 A EDITOR will appear on the screen.
 Create a knowledge base.
 After that hover your mouse on compile button and the select option Compile buffer.
 If any error it will display.
 Once your file is successfully compiled then click on Make.
 This action will execute your program.
 Write the queries in the SWI command prompt.
 You can execute the queries on window for the following code. .
C) Steps to execute a predicate from Prolog prompt.

 Write a knowledge base in a EDITIOR


 Decide the output which you want to find using predicate.
 Write the function in the SWI Command prompt to find the output.
 The function used to find your output is your required predicate.
 Depending on the queries whether it is true or false.

D) Observe trace in Prolog for same example and also for predicate.
THEORY :

Recursion in any language is a function that can call itself until the goal has been succeed. Recursion
is an extremely powerful tool and one which is widely used in Prolog programming. In Prolog,
recursion appears when a predicate contain a goal that refers to itself. In Prolog and in any language,
a recursive definition always has at least two parts.

A first fact that acts like a stopping condition and a rule that call itself simplified. At each level the first
fact is checked. If the fact is true then the recursion ends, if not the recursion continue.
A recursive rule must never call itself with the same arguments, if that happens then the program will
never end.

Lists in Prolog are themselves terms, and consist of a sequence of terms separated from one-another
by commas and enclosed at each end by matching square brackets.

For example : : [1], [1,2,3,4], [a,b,c]

[ ] represents the empty list.

The first element of a list is called the head of the list, and the remainder is called the tail of the list.
Note that the last element of every non-empty list is the empty list; although the normal Prolog
notation suppresses this fact.

Because of the importance of the distinction between the head and tail of a list, Prolog provides a
convenient notation that can be used to match against the head and tail of any list.

[X | Y]
Where X will match against the head, and Y against the tail.

To demonstrate and illustrate these concepts we having following codes as follows :

 Program to find the length of the list in Prolog.

CODE :

OUTPUT :

 Program to append two lists in Prolog.

CODE :

OUTPUT :

 Program to solve the Tower of Hanoi for n number of disk.

CODE :

OUTPUT :

CONCLUSION :

You might also like