Prolog – Hello World

prolog hello world

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 βˆ’

hello world

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.

select working directory

Now we can see in the prolog console, it shows that we have successfully changed the directory.

prolohg console

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 βˆ’

prolog console

Next Topic : Click Here

This Post Has One Comment

Leave a Reply