In this guide, we will discuss Hello World in Prolog Programming. In the previous section, we have seen how to install GNU Prolog. Now, we will see how to write a simple Hello World program in our Prolog environment.
Hello World Program
After running the GNU prolog, we can write hello world program directly from the console. To do so, we have to write the command as follows β
write('Hello World').
Note β After each line, you have to use one period (.) symbol to show that the line has ended.
The corresponding output will be as shown below β
Now let us see how to run the Prolog script file (extension is *.pl) into the Prolog console.
Before running *.pl file, we must store the file into the directory where the GNU prolog console is pointing, otherwise just change the directory by the following steps β
Step 1 β From the prolog console, go to File > Change Dir, then click on that menu.
Step 2 β Select the proper folder and press OK.
Now we can see in the prolog console, it shows that we have successfully changed the directory.
Step 3 β Now create one file (extension is *.pl) and write the code as follows β
main :- write('This is sample Prolog program'), write(' This program is written into hello_world.pl file').
Now letβs run the code. To run it, we have to write the file name as follows β
[hello_world]
The output is as follows β
Next Topic : Click Here
Pingback: How to install Prolog in your system | Adglob Infosystem Pvt Ltd