Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Builtin & Stdlib Reference

Every predicate the engine provides. The builtins are compiled into the language itself; the standard library is a small set of list predicates compiled into every binary. The descriptions here mirror the engine’s builtin table (plg-shared::BUILTINS) verbatim — a test fails the build if this page and the table disagree.

Evaluable arithmetic functions (+, *, mod, abs, …) are not predicates; see the Language Guide and the Operators reference for those and for operator precedence.

Type checks

PredicateDescription
var/1Type check: succeeds if argument is an unbound variable.
nonvar/1Type check: succeeds if argument is bound.
atom/1Type check: succeeds if argument is an atom.
number/1Type check: succeeds if argument is an integer or float.
integer/1Type check: succeeds if argument is an integer.
float/1Type check: succeeds if argument is a float.
compound/1Type check: succeeds if argument is a compound term.
is_list/1Type check: succeeds if argument is a proper list.

Unification & term comparison

PredicateDescription
=/2Unification: X = Y succeeds if X and Y can be made identical.
\=/2Not-unifiable: succeeds when = would fail.
==/2Term identity: structural equality without unification.
\==/2Term non-identity.
unify_with_occurs_check/2Unification with occurs check: rejects X = f(X)-style cycles.
compare/3compare(Order, T1, T2) — bind Order to <, =, or > per standard term ordering.
@</2Standard term ordering: less.
@>/2Standard term ordering: greater.
@=</2Standard term ordering: less-or-equal.
@>=/2Standard term ordering: greater-or-equal.

Arithmetic

PredicateDescription
is/2Arithmetic evaluation: X is Expr binds X to the value of Expr.
=:=/2Arithmetic equality.
=\=/2Arithmetic inequality.
</2Arithmetic less-than.
>/2Arithmetic greater-than.
=</2Arithmetic less-or-equal (note: =<, not <=).
>=/2Arithmetic greater-or-equal.

Control

PredicateDescription
,/2(A, B) — conjunction: prove A, then B.
;/2(A ; B) — disjunction: prove A, or B on backtracking. (C -> T ; E) reads as if-then-else.
->/2(C -> T) — if-then: if C succeeds (committing to its first solution), prove T; otherwise fail.
\+/1Negation as failure: succeeds when its argument fails.
once/1once(Goal) — succeed at most once for Goal.
call/1Meta-call: execute its argument as a goal. Variadic — extra args are appended.
true/0Always succeeds.
fail/0Always fails.
false/0Always fails (alias for fail).
!/0Cut: commit to current choices; remove choice points back to the parent clause.

Finding solutions & enumeration

PredicateDescription
findall/3findall(Template, Goal, List) — collect all solutions of Goal.
between/3between(Low, High, X) — enumerate or test integers in [Low, High].

Exceptions

PredicateDescription
catch/3catch(Goal, Catcher, Recovery) — run Goal; on thrown error matching Catcher, run Recovery.
throw/1Raise an error term that propagates to the nearest matching catch/3.

Term construction & inspection

PredicateDescription
functor/3functor(Term, Name, Arity) — inspect or construct a term’s functor.
arg/3arg(N, Term, Arg) — extract the N-th argument of Term.
=../2Univ: T =.. L decomposes T into a list of its functor and args.
copy_term/2copy_term(T, C) — bind C to a copy of T with fresh variables.

Atoms & numbers

PredicateDescription
atom_length/2atom_length(A, L) — bind L to the length of atom A.
atom_concat/3atom_concat(A, B, C) — concatenate A and B into C, or, with C bound and A/B unbound, nondeterministically split C into every prefix/suffix pair.
atom_chars/2atom_chars(A, Chars) — convert between an atom and a list of single-char atoms.
number_chars/2number_chars(N, Chars) — convert between a number and a list of single-char atoms.
number_codes/2number_codes(N, Codes) — convert between a number and a list of character codes.

Arithmetic relations

PredicateDescription
succ/2succ(X, S) — Peano successor relation; S = X + 1, both non-negative.
plus/3plus(X, Y, Z) — addition relation; any one argument may be unbound.

Sorting

PredicateDescription
msort/2msort(L, Sorted) — sort without removing duplicates.
sort/2sort(L, Sorted) — sort and remove duplicates.

I/O

PredicateDescription
write/1Write a term to stdout (no newline).
writeq/1Write a term to stdout, quoting atoms so it reads back (no newline).
writeln/1Write a term to stdout followed by a newline.
nl/0Write a newline to stdout.

Standard library (lists)

Defined in Prolog (stdlib.pl) and compiled into every binary.

PredicateDescription
member/2member(X, List) — succeeds once for each element of List.
append/3append(A, B, C) — C is A concatenated with B (relational; works in reverse).
length/2length(List, N) — N is the number of elements in List.
last/2last(List, X) — X is the last element of List.
reverse/2reverse(List, Rev) — Rev is List in reverse order.
nth0/3nth0(N, List, X) — X is the element at zero-based index N.
nth1/3nth1(N, List, X) — X is the element at one-based index N.