An ordered set of instructions. It reads input, follows rules, and produces output.
Workspace
Prolog
logic programming rules search and symbolic reasoning
Definition first
What Prolog means
Prolog is a programming language for writing exact instructions, often used for logic programming rules search and symbolic reasoning. Start with one mental model: input goes through steps and becomes output.
main.plRun swipl -q -s main.plHabit Describe facts rules and queries before thinking procedurallyA value is data. A variable is the name you use to hold and reuse that data.
A named piece of work. It takes input, does one job, and can return a result.
SWI-Prolog is the place that actually runs code from main.pl.
First readable code
Program output
entry point output syntax writelnwriteln(42).
Output 42Language lineage
Prolog family tree
See where Prolog comes from, which languages feel close, and what to learn next.
Zero base path
Question bank
Search before practice
Pick a stage or search across the open programming bank. Jump straight to the matching drill.
Prolog practice 1
Prolog question 1. Choose the statement that matches printing a value.
Prolog practice 2
Prolog question 2. Choose the statement that matches naming a value.
Prolog practice 3
Prolog question 3. Choose the statement that matches reusable function.
Prolog practice 4
Prolog question 4. Choose the statement that matches basic collection.
Prolog practice 5
Prolog question 5. Choose the statement that matches printing a value.
Prolog practice 6
Prolog question 6. Choose the statement that matches naming a value.
Prolog practice 7
Prolog question 7. Choose the statement that matches reusable function.
Prolog practice 8
Prolog question 8. Choose the statement that matches basic collection.
Prolog practice 9
Prolog question 9. Choose the statement that matches printing a value.
Prolog practice 10
Prolog question 10. Choose the statement that matches naming a value.
Prolog practice 11
Prolog question 11. Choose the statement that matches reusable function.
Prolog practice 12
Prolog question 12. Choose the statement that matches basic collection.
Prolog practice 13
Prolog question 13. Choose the statement that matches printing a value.
Prolog practice 14
Prolog question 14. Choose the statement that matches naming a value.
Prolog practice 15
Prolog question 15. Choose the statement that matches reusable function.
Prolog practice 16
Prolog question 16. Choose the statement that matches basic collection.
Prolog practice 17
Prolog question 17. Choose the statement that matches printing a value.
Prolog practice 18
Prolog question 18. Choose the statement that matches naming a value.
Multiple choice
Prolog practice 1
Prolog question 1. Choose the statement that matches printing a value.
writeln(42).
Reference
Patterns for main.pl
swipl -q -s main.plentry point output syntax writeln
Program output
writeln(42).
- Run the smallest file first
- Print one known value
- Check the output before adding more code
variables assignment types fact
Values and names
total(42). show :- total(X), writeln(X).
- Give values readable names
- Keep one idea per line while learning
- Trace the value before changing it
function collection List
Functions and collections
add(A, B, R) :- R is A + B. scores([40, 2]). show :- scores(S), length(S, N), writeln(N).
- Keep functions small
- Return useful values
- Use the common collection before reaching for frameworks