100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Prolog Quick Reference

A condensed reference for Prolog syntax, essential built-in predicates, operators, and list notation for quick lookup while coding.

PracticeBeginner8 min readJul 10, 2026
Analogies

Prolog Quick Reference

This reference collects the syntax and built-in predicates you reach for constantly once you're actually writing Prolog: how facts, rules, and queries are structured, the handful of built-ins (findall/3, member/2, append/3, length/2) that show up in nearly every program, and the operators and list notation that trip up newcomers coming from imperative languages. It's meant to be skimmed for a specific answer, not read start to finish — jump to the section you need.

🏏

Cricket analogy: A quick reference for built-in predicates is like a bowler's mental cheat sheet of field settings for common match situations — you don't derive the right slip cordon from first principles every over, you recall the standard setup instantly.

Core Syntax: Facts, Rules, and Queries

A fact is a clause with no body, written as head. — e.g., likes(mary, wine). A rule adds a body after :- (read 'if'), with comma-separated goals meaning conjunction: happy(X) :- likes(X, wine), likes(X, cheese). means X is happy if X likes wine and X likes cheese. A query is typed at the top-level prompt as ?- Goal. and either succeeds with variable bindings, fails, or (for multiple solutions) can be re-run with ; to request the next answer via backtracking. Semicolon (;) inside a rule body means disjunction (or), and every clause must end with a period followed by whitespace, a detail that trips up newcomers when a period gets attached to the end of a number like 3.14 or a filename atom.

🏏

Cricket analogy: A fact like likes(mary, wine). is a settled entry in the record book, no conditions attached, whereas a rule like happy(X) :- likes(X, wine), likes(X, cheese). is a conditional statistic such as 'a batter's average only counts if they faced at least 10 innings' — true only when its conditions hold.

prolog
% Fact
likes(mary, wine).
likes(mary, cheese).

% Rule: comma = conjunction
happy(X) :- likes(X, wine), likes(X, cheese).

% Rule with disjunction
weekend_plan(X) :- likes(X, hiking) ; likes(X, cinema).

?- happy(mary).
true.

?- happy(X).
X = mary ;
false.

Essential Built-in Predicates

member(X, List) succeeds once per occurrence of X in List and can also be used to generate list elements via backtracking. append(A, B, C) both concatenates (when A and B are bound) and splits a list into every possible prefix/suffix pair (when C is bound and A, B are unbound) — this dual-direction behavior is a hallmark of well-written Prolog predicates. length(List, N) computes or checks the length, and can even generate lists of a given length when List is unbound. findall(Template, Goal, List) collects every solution of Goal into List (with duplicates and no bindings preserved outside the call), while bagof/3 and setof/3 are similar but fail if there are no solutions and support grouping with ^/2 to ignore free variables, with setof/3 additionally sorting and deduplicating the results.

🏏

Cricket analogy: append/3 working both to concatenate and to split, depending on what's bound, is like a scorer who can both merge two innings' ball-by-ball logs into one file and, given the combined file, work backward to figure out every possible split point between the two innings.

prolog
% member/2 checks membership or generates elements
?- member(2, [1,2,3]).
true.
?- member(X, [1,2,3]).
X = 1 ;
X = 2 ;
X = 3.

% append/3 concatenates or splits, depending on binding
?- append([1,2], [3,4], C).
C = [1, 2, 3, 4].
?- append(A, B, [1,2,3]).
A = [], B = [1, 2, 3] ;
A = [1], B = [2, 3] ;
A = [1, 2], B = [3] ;
A = [1, 2, 3], B = [].

% findall vs setof
?- findall(X, member(X, [3,1,2,1]), L).
L = [3, 1, 2, 1].
?- setof(X, member(X, [3,1,2,1]), S).
S = [1, 2, 3].

Operators, Arithmetic, and List Notation

Lists are written [H|T] for head/tail decomposition, [1,2,3] as sugar for nested cons cells ending in [], and [] is the empty list, distinct from the atom nil used in some other Lisp-family languages. Arithmetic comparison operators (<, >, =<, >=, =:=, =\=) evaluate both sides as expressions, unlike = and == which compare terms structurally without evaluation — notably =< (not <=) is the correct Prolog syntax for 'less than or equal', a common typo for newcomers from C-family languages. String-like data appears as either atoms (like 'hello'), character-code lists, or a dedicated string type in SWI-Prolog specifically, and which one a given program uses depends heavily on the Prolog implementation, so checking your system's flags (e.g., double_quotes) matters before assuming behavior.

🏏

Cricket analogy: The [H|T] list decomposition is like separating the current striker (head) from the rest of the batting order still to come (tail), a natural way to reason about who's up next versus everyone still waiting.

Common gotcha: =:= compares evaluated arithmetic values, so 3 =:= 3.0 succeeds, while = performs structural unification and 3 = 3.0 fails since an integer and a float are structurally different terms.

  • A fact is head. with no body; a rule is head :- body. where comma means conjunction and semicolon means disjunction.
  • Queries return bindings on success; typing ; requests the next solution via backtracking.
  • member/2, append/3, and length/2 all work in multiple directions depending on which arguments are bound — a hallmark of idiomatic Prolog.
  • findall/3 collects all solutions including duplicates; setof/3 additionally sorts and removes duplicates but fails on no solutions.
  • Lists use [H|T] notation for head/tail decomposition; [] is the empty list.
  • Use =< (not <=) for 'less than or equal', and remember =:= evaluates arithmetic while = does structural unification without evaluation.
  • String-like data (atoms, code lists, or SWI-Prolog's string type) varies by implementation — check your system's double_quotes flag before assuming behavior.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#PrologStudyNotes#PrologQuickReference#Prolog#Quick#Reference#Core#StudyNotes#SkillVeris#ExamPrep

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse