Hello World (Prolog)
Prolog is a logic programming language that deduces new facts from a knowledge base consisting of facts and rules. The following rule prints a "Hello World!" message:
<<hello_world.pl>>= hello_world :- write('Hello World!').
write/1 is a built-in predicate which writes a Prolog term to the standard output stream and always succeeds.
Now start the Prolog interpreter which will prompt you to enter a query. Type the following to load the source file:
?- consult(hello_world). % hello compiled 0.00 sec, 612 bytes Yes
consult/1 is another built-in predicate that will load the given file as a Prolog program.
Now make the following query:
?- hello_world. Hello World! Yes
The "Yes" is the response to your query and indicates that Prolog could deduce
hello_world. This is because
write always succeeds.
You could just as well have queried directly in the interpreter without writing a rule:
?- write('Hello World!'). Hello World! Yes