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 / 1abolish(PredicateIndicator)abolish(test/1) - totally removes the predicate test with arity 1 (and hence all clauses for it).arg / 3arg(Number, Compound, Term)Term with the argument of Compound specified by Number.arg(2, a(b, c, d), X) - instantiates X to b.=:= / 2Exp1 =:= Exp2Exp1 and Exp2, then succeed if values are equal.2 + 2 =:= 1 + 3 - succeeds.1 + 1 =:= 2 + 2 - fails.2 + 2 =:= 1 + 1 - fails.=\= / 2Exp1 =\= Exp2Exp1 and Exp2, then succeed if values differ.2 + 2 =\= 1 + 3 - fails.1 + 1 =\= 2 + 2 - succeeds.2 + 2 =\= 1 + 1 - succeeds.> / 2Exp1 > Exp2Exp1 and Exp2, then succeed if value of the first is greater.2 + 2 > 1 + 3 - fails.1 + 1 > 2 + 2 - fails.2 + 2 > 1 + 1 - succeeds.>= / 2Exp1 >= Exp2Exp1 and Exp2, then succeed if the value of the first is greater than or equal to the second.2 + 2 >= 1 + 3 - succeeds.1 + 1 >= 2 + 2 - fails.2 + 2 >= 1 + 1 - succeeds.< / 2Exp1 < Exp2Exp1 and Exp2, then succeed if value of the first is smaller.2 + 2 < 1 + 3 - fails.1 + 1 < 2 + 2 - succeeds.2 + 2 < 1 + 1 - fails.=< / 2Exp1 =< Exp2Exp1 and Exp2, then succeed if the value of the first is less than or equal to the second.2 + 2 =< 1 + 3 - succeeds.1 + 1 =< 2 + 2 - succeeds.2 + 2 =< 1 + 1 - fails.asserta / 1asserta(FactOrRule)asserta(test(0)) - adds the fact test(0) as the first clause for test/1.asserta(test(X) :- X < 0) - adds the rule test(X) :- X < 0 as the first clause for test/1.assertz / 1assertz(FactOrRule)assertz(test(4)) - adds the fact test(4) as the last clause for test/1.assertz(test(X) :- X > 3) - adds the rule test(X) :- X > 3 as the last clause for test/1.atom / 1atom(Term)Term is an atom.atom(a) - succeeds.atom(1) - fails.atom(A) - fails.atomic / 1atomic(Term)Term is atomic.atomic(a) - succeeds.atomic(1) - succeeds.atomic(a(b)) - fails.atomic[a, b] - fails.atomic(A) - fails.call / 1call(Goal)Goal, and succeeds if Goal succeeds. During backtracking, Goal can be redone. Opaque to cuts in the subgoal.call(test(X)) - instantiates X to 1 intially, and to 1, 2, and 3 on backtracking.clause / 2clause(Head, Body)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.)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., / 2GoalA, GoalBGoalA 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.test(X), write(X) - writes 1. On backtracking, writes (in turn) 1, 2, 3.! / 0!! - performs a cut operation.; / 2GoalA ; GoalBGoalA 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.)atom(1) ; write('Failed') - writes Failed but succeeds.fail / 0failfail - fails.functor / 3functor(Term, Functor, Arity)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.functor(a(b, c), F, A) - instantiates F to a and A to 2.functor(T, a, 2) - instantiates T to a(_0, _1) where _0 and _1 are distinct fresh variables.halt / 0halthalt - exits PrologJ with status 0.halt / 1halt(Status)halt(1) - exits PrologJ with status 1.integer / 1integer(Term)Term is an integer.integer(1) - succeeds.integer(1.0) - fails.integer(a(b)) - fails.integer(A) - fails.is / 2Term is ExpressionExpression and unifies the result with Term.X is 2 + 2 - instantiates X to 4.nl / 0nlnl - writes a newline to the current output stream.nonvar / 1nonvar(Term)Term is not an uninstantiated variable.nonvar(1) - succeeds.nonvar(a(b)) - succeeds.nonvar(A) - fails.\= / 2Term1 \= Term2Term1 and Term2 can be unified; succeeds if they cannot be. a(X, c) \= a(b, Y) - fails.a \= 1 - succeeds.op / 3op(Priority, Associativity, Symbol)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).op(1000, xfy, foo) - makes foo an infix operator with priority 1000 and left associativity.op(0, xfy, +) - causes + to no longer be considered an infix operator.put / 1put(Code)put_code/1) Writes the character whose ASCII code is Code to the current output stream.put(65) - writes A to the current output stream.read / 1read(Term)Term.read(T) - instantiates T to a(b, _0).read(T) - (after the above) instantiates T to abc.repeat / 0repeat!.repeat, test(X), write(X), X > 2 - writes 112.retract / 1retract(FactOrRule)FactOrRule. (The forms Fact and Fact :- true are equivalent.) On backtracking, removes the next such clauses. 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.]retract(test(X) :- B) - instantiates X to 2 and B to atom(a), and removes the corresponding clause. Succeeds just once.retractall / 1retractall(FactOrRule)FactOrRule. (The forms Fact and Fact :- true are equivalent.) Not redoable. Always succeeds, even if no clauses match.retractall(test(X)) - removes the clauses test(1) (both) and test(3) from the database, but leaves test(2) :- atom(a).retractall(test(X) :- B) - removes the clause test(2) :- atom(a) from the database, but leaves the other test/1 clauses alone.retractall(nonexistent) - succeeds without changing the database.== / 2Term1 == Term2Term1 and Term2 are identical (without any unifications).a(b, c) == a(b, c) - succeedsa(b, X) == a(b, c) - fails.a(b, c) == a(b, X) - fails.\== / 2Term1 \== Term2Term1 and Term2 are not identical.a(b, c) \== a(b, c) - fails.a(b, X) \== a(b, c) - succeeds.a(b, c) \== a(b, X) - succeeds.true / 0truetrue - succeeds.= / 2Term1 = Term2Term1 with Term2.a(X, c) = a(b, Y) - instantiates X to b and Y to c.a = 1 - fails.=.. / 2Term =.. ListTerm 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.a(b, c) =.. L - instantiates L to [ a, b, c ].1=.. L - instantiates L to [ 1 ].T =..[ a, b c ] - instantiates T to a(b, c).T =..[ 1 ] - instantiates T to 1.var / 1var(Term)Term is an uninstantiated variable.var(A) - succeeds.var(1) - fails.write / 1write(Term)Term to the current output stream, using operator and list notation as appropriate, but not quotes.write(1) - writes 1 to the current output stream.write([ 2 + 2, a(b) ] - writes [ 2 + 2, a(b) ] to the current output stream.write('Hello, world') - writes Hello, World (with no quotes) to the current output stream.writeq / 1writeq(Term)Term to the current output stream, but atoms that would need to be quoted to be accepted by read are quotedwriteq('Hello, world') - writes 'Hello, World' (with quotes) to the current output stream.writeq((a, b)) - writes a ',' b to the current output stream.writeq([ 2 + 2, a(b) ] - writes [ 2 + 2, a(b) ] to the current output stream.