This guide explains the basic usage of your computing environment and the runtime library. We will step by step show how a Prolog text can be created and executed that will display “Hello World!”. The current version of the Jekejeke Prolog runtime library does not provide an editor for Prolog texts. Instead you have to use an editor of your choice from your computing environment. A simple text editor will do.
A Prolog text contains facts, rules and directives. Our example
will only contain one rule for a predicate hello/0 which will
display the text “Hello World!”. The text will be represented by
an atom enclosed in single quotes (‘):
Picture 1: Creating a Prolog Text
When the Prolog text has been entered you usually will be able to
save it to your computing environment. By use of the extension
“.p” in the chosen file name you can indicate that the file is a
Prolog source. The Jekejeke Prolog interpreter assumes as a
default encoding UTF-8 for Prolog texts. There is not yet an
encoding option when consulting from files. Therefore it is
recommended to store Prolog texts either in UTF-8 or when possible
in 7-bit ASCII. 7-bit ASCII is also possible since it is a subset
You can now start-up the Jekejeke Prolog runtime library. It will
show the console window. For more details on starting the runtime
library see the installation guide. A quick check with the
listing/0 system predicate reveals that the current knowledge base
does not yet contain any user predicates:
Picture 3: The Initial Main Window
The system predicate consult/1 is suited to read in a Prolog text. As an argument we can use the source path of the Prolog text. A check with the listing/0 system predicate will indeed reveal that the Prolog source has been consulted:
hello :- write('Hello World!'), nl.
When the user predicate hello/0 is now called, it will in turn first call the system predicate write/1 and display the text “Hello World!”. Subsequently it will call the system predicate nl/0 which will issue a carriage return to the console:
We do not need to quite the runtime library to change the Prolog
text. One can simply turn to the text editor again and continue
editing the existing file hello.p. We want to change the hello/0
predicate into a hello/1 predicate:
Picture 4: Updating a Prolog Text
When the changed Prolog text has been saved, we can use the system predicate consult/1 to reread it. Before actually rereading the system predicate will remove all predicates it has previously read, so that hello/0 will disappear from the knowledge base.
hello(X) :- write('Hello '), write(X), nl.
The new predicate hello/1 will hello the given argument. We can test it directly in the console window of the runtime library: