Updated April 5, 2023
Introduction to Prolog Comments
The prolog comments are a programming feature to display information about coding or a piece of the coding. The prolog comment is a symbol or group of signs to display annotations of the source code and prolog program. They are part of the prolog source code but do not compile and run by the Prolog compiler and interpreter. The prolog comments are annotations used to understand the prolog program and source code to other programmers and users.
They are feature to write extra information on the prolog programming language to understand human and non-programmers. The prolog comment is used to make a readable program or part of the programming logic. They are structured comments for a single line or multiple lines of the expressions.
Syntax of Prolog Comments
The prolog comments are used for single or multiple lines of the “pl” file.
You can use either line comment or block comment with prolog programming.
The prolog line comment syntax is below:
% writes annotation and information
Explanation of the line comment:
- The percentage “%” symbol is necessary for the single-line comment.
- The comment information is in writing after the percentage sign.
The prolog block comment syntax is below:
/*
Write block or paragraph description of the source code
*/
Explanation of the block comment:
- The “/*” symbol is started the comment block to write.
- The “*/” symbol is ended the comment block.
- The comment information writes inside of the comment block.
The prolog line comment syntax with the console is below:
% relation (value1, value2, values).
Explanation of the block comment:
- The percentage “%” symbol is necessary for the single-line comment.
- Write temporary prolog code inside of the block comment.
- For example, you write relation and its values inside of the line comment, but it does not work in a console.
The prolog block comment syntax with a console is below:
/*
relation (value1, value2, values).
relation (value1, value2, values).
relation (value1, value2, values).
*/
Explanation of the block comment:
- The “/*” and “*/” symbols are used to start and end the comment block.
- Write temporary prolog code inside of the block comment.
- You write multiple relations and values inside of the block comment, but it does not work in a console.
How does a Comment Work in Prolog?
Given below shows how comment works in prolog:
Prolog comment works in the “pl” file
- Create a file with the “pl” extension.
Example: main.pl
- Write a single-line comment for one-line information.
% This statement writes about travel and places.
- You can write your code after the prolog comments.
travel (India, England).
Write block command for multiple line information.
/*
Write about a tutorial, study, method, and material relations.
You can write entities in the relations.
You can use any statement for student learning.
*/
You can write your code after the prolog comments.
tutorial (prolog, AI).
study (online, offline).
Prolog comment works in the console:
- Open prolog console or interpreter.
- Set the directory path of the “pl” file.
- Use the given prolog file.
[main].
- Write a single-line comment for one-line information.
- You can write your code after the prolog comments.
| ?- % this statement write about travel and places.
travel(India, England).
yes
| ?-
- Write block command for multiple line information.
- You can write your code after the prolog comments.
| ?- /*
write about a tutorial, study, method, and material relations.
you can write entities in the relations.
you can use any statement for student learning.
*/
tutorial(prolog, AI).
yes
Examples of Prolog Comments
Different examples are mentioned below:
Example #1
The single-line prolog comments example and the output shows below.
File: main.pl
% this statement writes about travel and places.
travel(India, England).
travel(world, space).
Code:
| ?- travel(world, space).
Output:
Example #2
The multiple line prolog comments example and the output shows below.
File: main.pl
% this statement writes same relation name with different entities.
% this “go” relation writes places and way entities.
go(school, college).
go(bus, car).
Code:
| ?- go(bus, car).
Output:
Example #3
The single-line prolog comments example and the output shows below.
File: main.pl
/*
write about a tutorial, study, method, and material relations.
you can write entities in the relations.
you can use any statement for student learning.
*/
tutorial(prolog, AI).
study(online, offline).
method(articles, videos).
material(books, files).
Code:
| ?- study(online, offline).
Output:
Example #4
The multiple line prolog comments example and the output shows below.
File: main.pl
/*
write about a tutorial, study, method, and material relations.
you can write entities in the relations.
you can use any statement for student learning.
*/
tutorial(prolog, AI).
study(online, offline).
/*
you can write entities in the relations.
you can use any statement for student learning.
*/
method(articles, videos).
material(books, files).
Code:
| ?- study(online, offline).
Output:
Example #5
The single-line prolog comment with console example and the output shows below.
Code:
% this statement writes about travel and places.
travel(India, England).
Output:
Example #6
The prolog block comment with console example and the output shows below.
Code:
/*
write about a tutorial, study, method, and material relations.
you can write entities in the relations.
you can use any statement for student learning.
*/
tutorial(prolog, AI).
Output:
Example #7
The prolog comments for relations are in the file example, and the output shows below.
File: main.pl
%study(online, offline).
/*
you can write entities in the relations.
you can use any statement for student learning.
method(articles, videos).
material(books, files).
*/
Code:
| ?- material(books, files).
yes
| ?- study(online, offline).
Yes
Output:
Example #8
The prolog line comments with console example, and the output shows below.
Code:
| ?- % material(books, files).
Output:
Example #9
The prolog block comment with console example and the output shows below.
Code:
| ?- /* material(books, files). */
Output:
Conclusion
The prolog comments are used to avoid complications of the source code to other users. In addition, the prolog comment helps to display extra information about the programming language.
Recommended Articles
We hope that this EDUCBA information on “Prolog Comments” was beneficial to you. You can view EDUCBA’s recommended articles for more information.