Prolog Online Compiler / Interpreter
Write and run Prolog programs online directly from your browser with our free Online Prolog Compiler / Interpreter. Practice facts, rules, queries, recursion, and logical reasoning without installing SWI-Prolog, GNU Prolog, or configuring a local Prolog environment.
How to Use This Prolog Compiler
- Write or paste your Prolog code
Enter your facts, rules, predicates, and supported goals in the Code Editor. You can experiment with relationships, recursion, list processing, unification, and logical conditions. - Click the Run button
Select Run to execute your Prolog program. If your code contains a syntax error, undefined predicate, or another execution issue, review the returned feedback and update the relevant code. - Check the Output screen
Program results and execution messages appear in the Output panel. Use the available controls to copy, download, or delete the output before running another logic program.
Key Features
- Free Online Prolog Compiler / Interpreter: Write and execute Prolog logic programs directly from a modern web browser.
- Zero Installation: No need to install SWI-Prolog, GNU Prolog, or configure a local Prolog environment for supported programs.
- Instant Logic Execution: Click Run and quickly view results or interpreter feedback.
- Facts and Rules: Practice defining knowledge using facts, predicates, and logical rules.
- Unification and Backtracking: Experiment with two of Prolog’s core mechanisms for solving logical goals.
- Recursion and List Processing: Test recursive predicates and common list-processing patterns.
- Dark and Light Mode: Switch the Code Editor theme for comfortable coding in different lighting conditions.
- Output Controls: Copy, download, or clear generated output directly from the Output panel.
1. How do I define facts and rules in this Prolog compiler?
A fact states something that is true, while a rule describes a relationship that is true when other conditions are satisfied.
Here, parent(alice, bob). is a fact, while grandparent/2 is a rule that uses two parent/2 relationships.
2. Do I need to install SWI-Prolog or GNU Prolog to use this tool?
No. You can use this Online Prolog Compiler / Interpreter directly in your browser without installing SWI-Prolog or GNU Prolog for supported programs.
A local Prolog environment may still be preferable for large knowledge bases, external libraries, advanced debugging, constraint programming packages, or applications that require unrestricted system access.
3. How do I print output in Prolog using write and nl?
Standard Prolog commonly uses write/1 to display a value and nl/0 to print a new line.
In environments that support the initialization directive, the main predicate is called when the program starts. Exact startup behavior can depend on the Prolog implementation used by the online compiler.
4. How do I run a query or test a goal in this online Prolog compiler?
In an interactive Prolog shell, a query may look like:
However, a browser-based compiler may execute code as a script rather than exposing a separate interactive query prompt. In that case, you can call the goal from an entry predicate:
This approach lets you test facts, rules, unification, and query results directly in the Output panel.