Online Prolog Compiler
Write, run and test Prolog code online, right in your browser. This free online Prolog compiler needs no installation or signup — just type your code and click Run.
Prolog is a logic programming language where you describe facts and rules and let the engine find answers. It is used in AI, linguistics and teaching logic.
How to use the Prolog compiler
- Write or paste your Prolog code in the editor.
- If your program reads input, open the I/O tab and type it into the STDIN box (one value per line).
- Click Run — the output and any errors appear in the output panel.
Sample: read input in Prolog
parent(tom, bob).
parent(bob, ann).
grandparent(X, Z) :- parent(X, Y), parent(Y, Z).
:- initialization(main).
main :- grandparent(tom, Who), write(Who), nl.
Paste this into the editor, type your name in the STDIN box and click Run.
More Prolog examples to try
Recursion: factorial
Prolog solves problems with recursive rules instead of loops.
:- initialization(main).
factorial(0, 1).
factorial(N, F) :- N > 0, N1 is N - 1, factorial(N1, F1), F is N * F1.
main :- factorial(5, F), format("5! = ~w~n", [F]), halt.
Lists and member
Finds every solution with findall.
:- initialization(main).
likes(asha, python).
likes(asha, prolog).
likes(ravi, java).
likes(meena, python).
main :-
findall(P, likes(P, python), People),
format("Python fans: ~w~n", [People]),
halt.
Common Prolog errors and how to fix them
Unknown procedure: foo/1- The predicate is not defined, or is defined with a different number of arguments. Check spelling and arity.
Arguments are not sufficiently instantiated- A variable is used in arithmetic (
is,>) before it has a value. Reorder the goals so it is bound first. Program runs but prints nothing- Prolog needs an entry point. Add
:- initialization(main).and endmainwithhalt. Clauses of foo/1 are not together- Keep all clauses of the same predicate next to each other in the file.
Frequently asked questions
Is this online Prolog compiler free?
Yes. It is completely free to use, with no signup required to write and run code.
Do I need to install anything?
No. It all works from your web browser, so there is nothing to download or set up — it works on Windows, macOS, Linux, Chromebooks and phones.
How do I give input to my Prolog program?
Before clicking Run, type the input into the STDIN box under the I/O tab, one value per line. Your program reads it as standard input, just like typing in a terminal.
Is this good for learning Prolog?
Yes. It is ideal for practising exercises, testing small programs and trying out ideas from tutorials, because you can run code instantly without configuring an environment.
Other online compilers
Python Compiler Java Compiler C Compiler C++ Compiler C# Compiler JavaScript Compiler TypeScript Compiler SQL Compiler React.js Compiler HTML Compiler Go Compiler Rust Compiler R Compiler PHP Compiler Kotlin Compiler Swift Compiler Scala Compiler Dart Compiler Ruby Compiler Perl Compiler
Editor powered by OneCompiler.