Online Prolog Compiler
Run Prolog online with SWI-Prolog 10.0. Write your facts and rules with a main predicate started by initialization(main, main), press Run, and see what it prints beside your code. Programs can read input with read_line_to_string as they run, and SWI-Prolog's libraries, such as lists and apply, are ready to use.
How to run Prolog code online
- This page opens with Prolog selected, so you can start typing straight away.
- Write your code in the editor, or open files from your computer: single files, or a whole project as a .zip.
- Press Run, or Ctrl+Enter. The output appears in the panel beside the editor, and when the program asks for input you type it there and press Enter.
- Share a copy with a link, or save your files to your computer.
SWI-Prolog 10.0 on Online IDE
- Your program runs with SWI-Prolog 10.0 as a script: with :- initialization(main, main). in the file, main runs once the file has loaded.
- read_line_to_string(user_input, Line) reads a line of input, and output shows as soon as it is written.
- number_string/2 turns text into a number, and findall/3 with between/3 collects every solution into a list.
- The libraries that come with SWI-Prolog, such as lists, apply and dcg/basics, are available, but packs cannot be installed.
Example: a Prolog program that reads input
:- initialization(main, main).
main :-
write('Enter a whole number: '),
read_line_to_string(user_input, Line),
( catch(number_string(N, Line), _, fail), integer(N), N > 0
-> findall(D, (between(1, N, D), N mod D =:= 0), Divisors),
format("Divisors of ~d: ~w~n", [N, Divisors])
; writeln('Please enter a whole number above zero.')
).
Features of this tool
- Simple and fastA clean, lightweight editor that opens instantly.
- Powered by AceThe Ace code editor, with syntax highlighting, autocompletion and bracket matching.
- Interactive programsType input into the terminal while your program runs.
- Several filesWork in tabs, open files or a .zip from your computer, and save the project back to disk.
- Made for learningHelpful for beginners to learn and practice programs.
- Light and dark themesPlus 39 editor themes, a choice of coding fonts, and Vim, Emacs or VS Code keys.
- Keep your outputCopy or download the program output in one click.
- Share by linkSave your code in the cloud and open it anywhere.
Frequently asked questions
Which Prolog does Online IDE use?
SWI-Prolog 10.0, running your file as a script with swipl.
How do I run a query?
Put it in a predicate and name that predicate in :- initialization(main, main). There is no interactive top level, so queries typed after ?- are not read.
Can a Prolog program read input?
Yes. read_line_to_string(user_input, Line) reads a line, and read/1 reads a term ending in a full stop. Type into the output panel while the program waits and press Enter.
Why is the file called main.pro?
Perl uses .pl too, so Prolog files here end in .pro. SWI-Prolog loads them the same way.
Contact us
For any feedback, queries or issues, please feel free to contact us or write to . We value your input and are committed to providing the best possible experience for our users.