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!').

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
mainpredicate 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
mainpredicate automatically. - Analogy: It’s similar to the
mainfunction in languages like C or Java, where the program execution begins.
main :-
write('Hello, World!').
- Purpose: This defines what the
mainpredicate does. - Structure:
main :-starts the definition of themainpredicate. In Prolog, predicates are like functions or procedures in other languages.write('Hello, World!').is the action performed by themainpredicate. Thewrite/1predicate outputs the given string to the console.
- Execution: When
mainis called (as specified by the initialization directive), it executes thewritecommand, 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.




