Core Builtin Predicate Set

In the examples below, assume the database contains

?- dynamic(test/1).
?- public(test/2).

test(1).
test(1).	% Note that this is asserted twice
test(2) :- atom(a).
test(3).

test(a, b).
test(a, c).

Also, assume that the standard input stream will yield the following when read (where <space> stands for a single space).

<space>a(b, C).
/* This is a comment */ abc.

 

abolish / 1
Prototype: abolish(PredicateIndicator)
Totally remove the specified predicate from the database.
Example: abolish(test/1) - totally removes the predicate test with arity 1 (and hence all clauses for it).
 
arg / 3
Prototype: arg(Number, Compound, Term)
Unifies Term with the argument of Compound specified by Number.
Example: arg(2, a(b, c, d), X) - instantiates X to b.
 
=:= / 2
Prototype: Exp1 =:= Exp2
Evaluate arithmetic expressions Exp1 and Exp2, then succeed if values are equal.
Example: 2 + 2 =:= 1 + 3 - succeeds.
Example: 1 + 1 =:= 2 + 2 - fails.
Example: 2 + 2 =:= 1 + 1 - fails.
 
=\= / 2
Prototype: Exp1 =\= Exp2
Evaluate arithmetic expressions Exp1 and Exp2, then succeed if values differ.
Example: 2 + 2 =\= 1 + 3 - fails.
Example: 1 + 1 =\= 2 + 2 - succeeds.
Example: 2 + 2 =\= 1 + 1 - succeeds.
 
> / 2
Prototype: Exp1 > Exp2
Evaluate arithmetic expressions Exp1 and Exp2, then succeed if value of the first is greater.
Example: 2 + 2 > 1 + 3 - fails.
Example: 1 + 1 > 2 + 2 - fails.
Example: 2 + 2 > 1 + 1 - succeeds.
 
>= / 2
Prototype: Exp1 >= Exp2
Evaluate arithmetic expressions Exp1 and Exp2, then succeed if the value of the first is greater than or equal to the second.
Example: 2 + 2 >= 1 + 3 - succeeds.
Example: 1 + 1 >= 2 + 2 - fails.
Example: 2 + 2 >= 1 + 1 - succeeds.
 
< / 2
Prototype: Exp1 < Exp2
Evaluate arithmetic expressions Exp1 and Exp2, then succeed if value of the first is smaller.
Example: 2 + 2 < 1 + 3 - fails.
Example: 1 + 1 < 2 + 2 - succeeds.
Example: 2 + 2 < 1 + 1 - fails.
 
=< / 2
Prototype: Exp1 =< Exp2
Evaluate arithmetic expressions Exp1 and Exp2, then succeed if the value of the first is less than or equal to the second.
Example: 2 + 2 =< 1 + 3 - succeeds.
Example: 1 + 1 =< 2 + 2 - succeeds.
Example: 2 + 2 =< 1 + 1 - fails.
 
asserta / 1
Prototype: asserta(FactOrRule)
Add a fact or rule to the database, before any existing facts or rules for the same functor and arity.
Example: asserta(test(0)) - adds the fact test(0) as the first clause for test/1.
Example: asserta(test(X) :- X < 0) - adds the rule test(X) :- X < 0 as the first clause for test/1.
 
assertz / 1
Prototype: assertz(FactOrRule)
Add a fact or rule to the database, after any existing facts or rules for the same functor and arity.
Example: assertz(test(4)) - adds the fact test(4) as the last clause for test/1.
Example: assertz(test(X) :- X > 3) - adds the rule test(X) :- X > 3 as the last clause for test/1.
 
atom / 1
Prototype: atom(Term)
Succeeds if Term is an atom.
Example: atom(a) - succeeds.
Example: atom(1) - fails.
Example: atom(A) - fails.
 
atomic / 1
Prototype: atomic(Term)
Succeeds if Term is atomic.
Example: atomic(a) - succeeds.
Example: atomic(1) - succeeds.
Example: atomic(a(b)) - fails.
Example: atomic[a, b] - fails.
Example: atomic(A) - fails.
 
call / 1
Prototype: call(Goal)
Calls Goal, and succeeds if Goal succeeds. During backtracking, Goal can be redone. Opaque to cuts in the subgoal.
Example: call(test(X)) - instantiates X to 1 intially, and to 1, 2, and 3 on backtracking.
 
clause / 2
Prototype: clause(Head, Body)
Finds the first clause in the database whose head unifies with Head and whose body unifies with Body. On backtracking, finds the next such clauses. (A fact is considered to be a clause whose body is true.)
Example: clause(test(X), B) - instantiates X to 1 and B to true. On backtracking, instantiates them to 1 and true again, then to 2 and atom(a) and then to 3 and true.
 
, / 2
Prototype: GoalA, GoalB
Calls GoalA and, if it succeeds, then calls GoalB, succeeding only if both succeed. On backtracking, tries to redo GoalB and, if this fails, tries to redo GoalA. Transparent to cuts occurring in either subgoal.
Example: test(X), write(X) - writes 1. On backtracking, writes (in turn) 1, 2, 3.
 
! / 0
Prototype: !
Cuts off backtracking alternatives - through the clause chosen for the the current Prolog predicate unless part of a subgoal of an opaque predicate.
Example: ! - performs a cut operation.
 
; / 2
Prototype: GoalA ; GoalB
Calls GoalA and, if it fails, then calls GoalB, succeeding if either succeeds. On backtracking, tries to redo the goal that succeeded; if this was GoalA and GoalA cannot be redone, then tries GoalB. Transparent to cuts occurring in either subgoal (but a cut in GoalA will preclude trying GoalB.)
Example: atom(1) ; write('Failed') - writes Failed but succeeds.
 
fail / 0
Prototype: fail
Simply fails.
Example: fail - fails.
 
functor / 3
Prototype: functor(Term, Functor, Arity)
If Term is a compound, unifies Functor with its functor and Arity with its arity; if Term is atomic, unifies Functor with Term and Arity with 0; if Term is uninstantiated, unifies it with a compound term whose functor is Functor and which has Arity fresh uninstantiated arguments.
Example: functor(a(b, c), F, A) - instantiates F to a and A to 2.
Example: functor(T, a, 2) - instantiates T to a(_0, _1) where _0 and _1 are distinct fresh variables.
 
halt / 0
Prototype: halt
Exits PrologJ with system status code 0.
Example: halt - exits PrologJ with status 0.
 
halt / 1
Prototype: halt(Status)
Exits PrologJ with the specified status.
Example: halt(1) - exits PrologJ with status 1.
 
integer / 1
Prototype: integer(Term)
Succeeds if Term is an integer.
Example: integer(1) - succeeds.
Example: integer(1.0) - fails.
Example: integer(a(b)) - fails.
Example: integer(A) - fails.
 
is / 2
Prototype: Term is Expression
Evaluates arithmetic expression Expression and unifies the result with Term.
Example: X is 2 + 2 - instantiates X to 4.
 
nl / 0
Prototype: nl
Writes a newline to the current output stream.
Example: nl - writes a newline to the current output stream.
 
nonvar / 1
Prototype: nonvar(Term)
Succeeds if Term is not an uninstantiated variable.
Example: nonvar(1) - succeeds.
Example: nonvar(a(b)) - succeeds.
Example: nonvar(A) - fails.
 
\= / 2
Prototype: Term1 \= Term2
Fails if Term1 and Term2 can be unified; succeeds if they cannot be.
Example: a(X, c) \= a(b, Y) - fails.
Example: a \= 1 - succeeds.
 
op / 3
Prototype: op(Priority, Associativity, Symbol)
Defines a new operator (if Priority > 0) or removes an operator (if Priority = 0). Priority must be >= 0 and <= 1200. Possible associativities are fx (prefix non-associative), fy (prefix right associative), xfx (infix non-associative), yfx (infix left associative), xfy (infix right associative), yfy (typically not used), xf (posfix non-associative), yf (postfix left associative).
Example: op(1000, xfy, foo) - makes foo an infix operator with priority 1000 and left associativity.
Example: op(0, xfy, +) - causes + to no longer be considered an infix operator.
 
put / 1
Prototype: put(Code)
(Same as ISO put_code/1) Writes the character whose ASCII code is Code to the current output stream.
Example: put(65) - writes A to the current output stream.
 
read / 1
Prototype: read(Term)
Reads a term (terminated by a period) from the current input stream, and then unifies it with Term.
Example: read(T) - instantiates T to a(b, _0).
Example: read(T) - (after the above) instantiates T to abc.
 
repeat / 0
Prototype: repeat
Succeeds initially, and again every time reached during backtracking, unless cut by a subsequent !.
Example: repeat, test(X), write(X), X > 2 - writes 112.
 
retract / 1
Prototype: retract(FactOrRule)
Removes from the database the first fact or rule that unifies with FactOrRule. (The forms Fact and Fact :- true are equivalent.) On backtracking, removes the next such clauses.
Example: retract(test(X)) - instantiates X to 1. On backtracking, instantiates X to 1 again, then 3, in each case removing the corresponding clause. [test(2) :- atom(a) is not affected.]
Example: retract(test(X) :- B) - instantiates X to 2 and B to atom(a), and removes the corresponding clause. Succeeds just once.
 
retractall / 1
Prototype: retractall(FactOrRule)
Removes from the database all facts or rules that unify with FactOrRule. (The forms Fact and Fact :- true are equivalent.) Not redoable. Always succeeds, even if no clauses match.
Example: retractall(test(X)) - removes the clauses test(1) (both) and test(3) from the database, but leaves test(2) :- atom(a).
Example: retractall(test(X) :- B) - removes the clause test(2) :- atom(a) from the database, but leaves the other test/1 clauses alone.
Example: retractall(nonexistent) - succeeds without changing the database.
 
== / 2
Prototype: Term1 == Term2
Succeeds if Term1 and Term2 are identical (without any unifications).
Example: a(b, c) == a(b, c) - succeeds
Example: a(b, X) == a(b, c) - fails.
Example: a(b, c) == a(b, X) - fails.
 
\== / 2
Prototype: Term1 \== Term2
Succeeds if Term1 and Term2 are not identical.
Example: a(b, c) \== a(b, c) - fails.
Example: a(b, X) \== a(b, c) - succeeds.
Example: a(b, c) \== a(b, X) - succeeds.
 
true / 0
Prototype: true
Simply succeeds.
Example: true - succeeds.
 
= / 2
Prototype: Term1 = Term2
Unifies Term1 with Term2.
Example: a(X, c) = a(b, Y) - instantiates X to b and Y to c.
Example: a = 1 - fails.
 
=.. / 2
Prototype: Term =.. List
If Term is instantiated, unifies List with Term represented as a list. If Term is uninstantiated, unifies it with a term constructed from List. At least one of Term and List must be instantiated.
Example: a(b, c) =.. L - instantiates L to [ a, b, c ].
Example: 1=.. L - instantiates L to [ 1 ].
Example: T =..[ a, b c ] - instantiates T to a(b, c).
Example: T =..[ 1 ] - instantiates T to 1.
 
var / 1
Prototype: var(Term)
Succeeds if Term is an uninstantiated variable.
Example: var(A) - succeeds.
Example: var(1) - fails.
 
write / 1
Prototype: write(Term)
Writes a printed representation of Term to the current output stream, using operator and list notation as appropriate, but not quotes.
Example: write(1) - writes 1 to the current output stream.
Example: write([ 2 + 2, a(b) ] - writes [ 2 + 2, a(b) ] to the current output stream.
Example: write('Hello, world') - writes Hello, World (with no quotes) to the current output stream.
 
writeq / 1
Prototype: writeq(Term)
Writes a printed representation of Term to the current output stream, but atoms that would need to be quoted to be accepted by read are quoted
Example: writeq('Hello, world') - writes 'Hello, World' (with quotes) to the current output stream.
Example: writeq((a, b)) - writes a ',' b to the current output stream.
Example: writeq([ 2 + 2, a(b) ] - writes [ 2 + 2, a(b) ] to the current output stream.