Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
TuProlog can be used in command line mode in the traditional edit-run cycle.
Create/edit a Prolog text file.
Run TuProlog on the Prolog text file.
Capture the output (copy-paste terminal window, pipe output to file, etc.).
3. IDE
There is a simple IDE (Integrated Development Environment) for TuProlog as described in the PDF manuel. This page provides some additional details. Here is the command from the manual.
java -jar 2p.jar
4. Java
If java cannot be found, then it needs to be installed or a complete path to java may be needed.
If 2p.jar cannot be found, then it needs to be downloaded and extracted or a complete path to 2p.jar is needed.
For more on installing and using TuProlog, see tuprolog .
6. IDE
The IDE is written in Java so is portable to Windows, Linux, Apple, etc. The IDE looks similar to what is pictured here.
In the IDE, the Prolog program text is referred to as the "Theory"
7. Hello world
Here is program in TuProlog to enumerate and output the values for three logical variables.
Here is the Prolog code.
Here is the output of the Prolog code.
8. IDE use
Copy the above text and paste it into the top edit area in the IDE. Note: One would normally type and make changes here.
Note that double quoted string literals will be automatically converted to singe quote string literals.
There are two edit buttons for "Undo Edit Action" and "Redo Edit Action".
9. Save the program text
Click the "Save" button to provide a name and save the text as a Prolog text file.
10. Run the program text
To "Run" the program one needs to do the following.
Click the "Get Theory" button to parse the program text for any issues.
In the command area following the "?-" below the text area, type a command, such as "solve.". TuProlog will attempt to solve the command.
For many programs that use fail to backtrack and find more solutions the "solution" tab will show the final result. For the above program this is "no".
Click the "output" tab to see the output.
11. Output
The output in the "output" tab is as follows.
X Y Z
-----
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
This the expected output.
12. Solution
To avoid the "no" in the "solution" one can add the following predicate to the program after the "go" predicate.
go.
This tells Prolog that after backtracking on a fail the last thing to try is the second "go" which succeeds.
The "solution" tab now displays the following text.