A computer setup displaying a "Hello World" program written in Prolog on the screen. Various desktop items including a smart watch, a smartphone, a toy dragon figure, a mouse, and headphones are arranged neatly around the computer.

Hello World in Prolog Language

Introduction to Hello World Program in PROLOG Programming Language

Prolog is a logic programming language that deduces new facts from a knowledge base consisting of fac

ts and rules.Developers widely use it in artificial intelligence, natural language processing, and other fields Let’s start with the classic “Hello, World!” example in Prolog.

In Prolog, the “Hello, World!” program showcases the basic structure of the language. Prolog programs consist of facts and rules that define the logic, and queries that generate the output. Here’s a step-by-step explanation of how to write and execute a simple program :

:- initialization(main).
main :- 
    write('Hello, World!').
Screenshot of a Prolog program with the code :- initialization(main). main :- write('Hello, World!'). and the output 'Hello, World!' displayed in the console.
Prolog ‘Hello, World!’ Program: Successfully executed with output displayed.

Let’s break it down:

:- initialization(main).

This line tells Prolog to run the main predicate when the program starts. It’s like saying, “Hey Prolog, when you load this file, start with the main function!

  • Purpose: This line tells Prolog to execute the main predicate as soon as the program starts.
  • How it works: Think of it as setting the entry point for your program. When Prolog loads this file, it sees the initialization directive and knows it should run the main predicate automatically.
  • Analogy: It’s similar to the main function in languages like C or Java, where the program execution begins.
main :- 
    write('Hello, World!').
  • Purpose: This defines what the main predicate does.
  • Structure:
    • main :- starts the definition of the main predicate. In Prolog, predicates are like functions or procedures in other languages.
    • write('Hello, World!'). is the action performed by the main predicate. The write/1 predicate outputs the given string to the console.
  • Execution: When main is called (as specified by the initialization directive), it executes the write command, which prints “Hello, World!” to the screen.

This simple program helps you understand the fundamental structure of Prolog programs, using facts and rules to define the logic and queries to produce the desired output.


Discover more from PiEmbSysTech - Embedded Systems & VLSI Lab

Subscribe to get the latest posts sent to your email.

Leave a Reply

Scroll to Top

Discover more from PiEmbSysTech - Embedded Systems & VLSI Lab

Subscribe now to keep reading and get access to the full archive.

Continue reading