-
Notifications
You must be signed in to change notification settings - Fork 33
Home
Yutaka Ichibangase edited this page Feb 11, 2023
·
1 revision
Welcome to the prolog wiki!
-
:- dynamic(PI)
Specifies the predicates indicated byPI
are dynamic. ISO -
:- multifile(PI)
Specified the predicates indicated byPI
may be in multiple files. ISO -
:- discontiguous(PI)
Specifies the predicates indicated byPI
may be defined by clauses which are not consecutive read-terms. ISO -
:- op(Priority, Specifier, Op)
Alters the operator table. ISO -
:- char_conversion(In, Out)
Alters the character conversion mapping. ISO -
:- initialization(T)
Registers a goal for execution right before exitingExec()
orExecContext()
. ISO -
:- include(F)
Loads the content of the fileF
as if it were there instead of this directive. ISO -
:- ensure_loaded(P)
Loads the content of the fileP
if not loaded. ISO -
:- set_prolog_flag(Flag, Value)
Alters the value for the Prolog flag. ISO
-
true
Always succeeds. ISO -
fail
Always fails. ISO -
call(Goal)
CallsGoal
. ISO -
!
Cut. ISO -
P, Q
Conjunction. ISO -
P; Q
Disjunction. ISO -
If -> Then
If-then. ISO -
If -> Then; Else
If-then-else. ISO -
catch(Goal, Catcher, Recovery)
CallsGoal
. If an exception is raised and unifies withCatcher
, callsRecovery
. ISO -
throw(Ball)
Raises an exceptionBall
. ISO
-
X = Y
UnifiesX
withY
. ISO -
unify_with_occurs_check(X, Y)
UnifiesX
withY
with occurs check. ISO -
X \= Y
Succeeds iffX
andY
are not unifiable. ISO -
subsumes_term(General, Specific)
Succeeds iff there's a substitutionθ
such thatGeneralθ = Specificθ
andSpecificθ = Specific
. ISO
-
var(X)
Succeeds iffX
is a variable. ISO -
atom(X)
Succeeds iffX
is an atom. ISO -
integer(X)
Succeeds iffX
is an integer. ISO -
float(X)
Succeeds iffX
is a float. ISO -
atomic(X)
Succeeds iffX
is neither a variable nor a compound. ISO -
compound(X)
Succeeds iffX
is a compound. ISO -
nonvar(X)
Succeeds iffX
is not a variable. ISO -
number(X)
Succeeds iffX
is either an integer or a float. ISO -
callable(X)
Succeeds iffX
is either an atom or a compound. ISO -
ground(X)
Succeeds iffX
is a ground term. ISO -
acyclic_term(X)
Succeeds iffX
is acyclic. ISO
-
X @=< Y
EitherX == Y
orX @< Y
. ISO -
X == Y
Equivalent tocompare(=, X, Y)
. ISO -
X \== Y
Equivalent to\+compare(=, X, Y)
. ISO -
X @< Y
Equivalent tocompare(<, X, Y)
. ISO -
X @> Y
Equivalent tocompare(>, X, Y)
. ISO -
X @>= Y
EitherX == Y
orX @> Y
. ISO -
compare(Order, X, Y)
ComparesX
andY
and unifiesOrder
with either<
,=
, or>
. ISO -
sort(List, Sorted)
Succeeds iffSorted
unifies with a sorted list ofList
. ISO -
keysort(Pairs, Sorted)
Succeeds iffPairs
is a list ofKey-Value
pairs andSorted
unifies with a permutation ofPairs
sorted byKey
. ISO
-
functor(Term, Name, Arity)
Succeeds iffTerm
ia either a compound term ofName
andArity
or an atom ofName
andArity = 0
. ISO -
arg(N, Term, Arg)
Succeeds iffArg
is theN
-th argument ofTerm
. ISO -
Term =.. List
Succeeds iffList
is a list of the functor and arguments ofTerm
. ISO -
copy_term(Term1, Term2)
Creates a copy ofTerm1
and unifies it withTerm2
. ISO -
term_variables(Term, Vars)
Succeeds iffVars
is a list of variables appear inTerm
. ISO
-
Result is Expression
EvaluatesExpression
and unifies it withResult
. ISO-
Expression
is either:-
integer,
-
float, or
-
evaluable functors
X + Y
X - Y
X * Y
X // Y
X / Y
X rem Y
X mod Y
-X
abs(X)
sign(X)
float_integer_part(X)
float_fractional_part(X)
float(X)
floor(X)
truncate(X)
round(X)
ceiling(X)
+(X)
X div Y
X ** Y
sin(X)
cos(X)
atan(X)
exp(X)
log(X)
sqrt(X)
max(X, Y)
min(X, Y)
X ^ Y
asin(X)
acos(X)
atan2(X, Y)
tan(X)
pi
X >> Y
X << Y
X /\ Y
X \/ Y
\X
xor(X, Y)
-
-
-
succ(X, S)
Succeeds iffS
is the successor of the non-negative integerX
. prologue
-
E1 =:= E2
Succeeds iffE1
andE2
are evaluated toEV1
andEV2
respectively andEV1
equals toEV2
. ISO -
E1 =\= E2
Succeeds iffE1
andE2
are evaluated toEV1
andEV2
respectively andEV1
does not equal toEV2
. ISO -
E1 < E2
Succeeds iffE1
andE2
are evaluated toEV1
andEV2
respectively andEV1
is greater thanEV2
. ISO -
E1 =< E2
Succeeds iffE1
andE2
are evaluated toEV1
andEV2
respectively andEV1
is greater than or equal toEV2
. ISO -
E1 > E2
Succeeds iffE1
andE2
are evaluated toEV1
andEV2
respectively andEV1
is less thanEV2
. ISO -
E1 >= E2
Succeeds iffE1
andE2
are evaluated toEV1
andEV2
respectively andEV1
is less than or equal toEV2
. ISO
-
clause(Head, Body)
Succeeds iffHead :- Body
unifies with a clause in the DB. ISO -
current_predicate(PI)
Succeeds iff the predicate indicated byPI
is in the DB. ISO
-
asserta(Clause)
PrependsClause
to the DB. ISO -
assertz(Clause)
AppendsClause
to the DB. ISO -
retract(Clause)
Removes a clause that unifies withClause
from the DB. ISO -
abolish(PI)
Removes the predicate indicated byPI
from the DB. ISO -
retractall(Head)
Removes all the clauses which head unifies withHead
from the DB. ISO
-
findall(Template, Goal, Instances)
Succeeds iffInstances
unifies with a list ofTemplate
for each solution ofGoal
. ISO -
bagof(Template, Goal, Instances)
Succeeds iffInstances
unifies with a bag (multiset) ofTemplate
for each solution ofGoal
. ISO -
setof(Template, Goal, Instances)
Succeeds iffInstances
unifies with a set ofTemplate
for each solution ofGoal
. ISO
-
current_input(Stream)
Succeeds iffStream
unifies with the current input stream. ISO -
current_output(Stream)
Succeeds iffStream
unifies with the current output stream. ISO -
set_input(S_or_a)
Sets the current input stream to the stream indicated byS_or_a
which is either the stream itself or its alias. ISO -
set_output(S_or_a)
Sets the current output stream to the stream indicated byS_or_a
which is either the stream itself or its alias. ISO -
open(File, Mode, Stream, Options)
Opens the fileFile
inMode
withOptions
and unifies the stream withStream
. ISO-
Mode
is either:read
,write
, orappend
. -
Options
is a list of stream options listed below:-
type(T)
Specifies the type of the stream.T
is eithertext
(default) orbinary
. -
reposition(Bool)
Specifies if the stream can be repositions.Bool
is eithertrue
orfalse
. -
alias(A)
Specifies the alias for the stream.A
is an atom. -
eof_action(Action)
Specifies the action that will be taken when the input stream reached to the end.Action
is either:-
error
which throws an exception, -
eof_code
which returns a value indicating the end of stream (default), or -
reset
which resets the stream.
-
-
-
-
open(File, Mode, Stream)
Equivalent toopen(File, Mode, Stream, [])
. ISO -
close(S_or_a, Options)
Closes the stream indicated byS_or_a
which is the stream itself or its alias. ISO-
Options
is a list of:-
force(Bool)
Specifies if an exception will be raised when it failed to close the stream.Bool
is eitherfalse
(default) ortrue
.
-
-
-
close(S_or_a)
Equivalent toclose(S_or_a, [])
. ISO -
flush_output(S_or_a)
Sends any buffered output to the stream indicated byS_or_a
which is either the stream itself or its alias. ISO -
flush_output
Equivalent tocurrent_output(S), flush_output(S)
. ISO -
stream_property(Stream, Property)
Succeeds iff the streamStream
has the propertyProperty
. ISO-
Property
is either:file_name(F)
mode(M)
input
output
alias(A)
position(P)
end_of_stream(E)
eof_action(A)
reposition(Bool)
type(T)
-
-
at_end_of_stream
Equivalent tocurrent_input(S), at_end_of_stream(S)
. ISO -
at_end_of_stream(S_or_a)
Succeeds iff the stream indicated byS_or_a
which is either a stream or an alias has the property eitherend_of_stream(at)
orend_of_stream(past)
. ISO -
set_stream_position(S_or_a, Position)
Sets the position of the stream indicated byS_or_a
which is either a stream or an alias to the positionPosition
. ISO
-
get_char(S_or_a, Char)
Succeeds iffChar
unifies with the next character from the stream indicated byS_or_a
which is either a stream or an alias. ISO -
get_char(Char)
Equivalent tocurrent_input(S), get_char(S, Char)
. ISO -
get_code(S_or_a, Code)
Succeeds iffChar
unifies with the next code from the stream indicated byS_or_a
which is either a stream or an alias. ISO -
get_code(Code)
Equivalent tocurrent_input(S), get_code(S, Code)
. ISO -
peek_char(S_or_a, Char)
Similar toget_char(S_or_a, Char)
but doesn't consume the character. ISO -
peek_char(Char)
Equivalent tocurrent_input(S), peek_char(S, Char)
. ISO -
peek_code(S_or_a, Code)
Similar toget_code(S_or_a, Code)
but doesn't consume the code. ISO -
peek_code(Code)
Equivalent tocurrent_input(S), peek_code(S, Code)
. ISO -
put_char(S_or_a, Char)
Outputs the characterChar
to the stream indicated byS_or_a
which is either a stream or an alias. ISO -
put_char(Char)
Equivalent tocurrent_output(S), put_char(S, Char)
. ISO -
put_code(S_or_a, Code)
Outputs the codeCode
to the stream indicated byS_or_a
which is either a stream or an alias. ISO -
put_code(Code)
Equivalent tocurrent_output(S), put_code(S, Code)
. ISO -
nl(S_or_a)
Outputs a newline to the stream indicated byS_or_a
which is either a stream or an alias. ISO -
nl
Equivalent tocurrent_output(S), nl(S)
. ISO
-
get_byte(S_or_a, Byte)
Succeeds iffByte
unifies with the next byte from the stream indicated byS_or_a
which is a stream or an alias. ISO -
get_byte(Byte)
Equivalent tocurrent_input(S), get_byte(S, Byte)
. ISO -
peek_byte(S_or_a, Byte)
Similar toget_byte(S_or_a, Byte)
but doesn't consume the byte. ISO -
peek_byte(Byte)
Equivalent tocurrent_input(S), peek_byte(S, Byte)
. ISO -
put_byte(S_or_a, Byte)
Outputs the byteByte
to the stream indicated byS_or_a
which is either a stream or an alias. ISO -
put_byte(Byte)
Equivalent tocurrent_output(S), put_byte(S, Byte)
. ISO
-
read_term(S_or_a, Term, Options)
Succeeds iffTerm
unifies with the next term from the stream indicated byS_or_a
which is a stream or an alias. ISO-
Options
is a list of read options listed below:-
variables(Vars)
the list of variables appeared inTerm
-
variable_names(VN_list)
the list ofA = V
whereA
is an atom which name is the string representation ofV
andV
is a variable appeared inTerm
-
singletons(VN_list)
similar tovariable_names(VN_list)
but those of variables that appeared once.
-
-
-
read_term(Term, Options)
Equivalent tocurrent_input(S), read_term(S, Term, Options)
. ISO -
read(S_or_a, Term)
Equivalent toread_term(S_or_a, Term, [])
. ISO -
read(Term)
Equivalent tocurrent_input(S), read(S, Term)
. ISO -
write_term(S_or_a, Term, Options)
OutputsTerm
to the stream indicated byS_or_a
which is either a stream or an alias. ISO-
Options
is a list of write options listed below:-
quoted(Bool)
Bool
is eithertrue
orfalse
. Iftrue
, atoms and functors will be quoted as needed. -
ignore_ops(Bool)
Bool
is eithertrue
orfalse
. Iftrue
, operators will be written in functional notation. -
variable_names(VN_list)
VN_list
is a proper list which element is a form ofA = V
whereA
is an atom andV
is a variable. Each occurrence ofV
will be replaced by the leftmost and unquotedA
. -
numbervars(Bool)
Bool
is eithertrue
orfalse
. Iftrue
, terms'$VAR'(0)
,'$VAR'(1)
, ... will be written asA
,B
, ...
-
-
-
write_term(Term, Options)
Equivalent tocurrent_output(S), write_term(S, Term, Options)
. ISO -
write(S_or_a, Term)
Equivalent towrite_term(S_or_a, Term, [numbervars(true)])
. ISO -
write(Term)
Equivalent tocurrent_output(S), write(S, Term)
. ISO -
writeq(S_or_a, Term)
Equivalent towrite_temr(S_or_a, Term, [quoted(true), numbervars(true)])
. ISO -
writeq(Term)
Equivalent tocurrent_output(S), writeq(S, Term)
. ISO -
write_canonical(S_or_a, Term)
Equivalent towrite_term(S_or_a, Term, [quoted(true), ignore_ops(true)])
. ISO -
write_canonical(Term)
Equivalent tocurrent_output(S), write_canonical(S, Term)
. ISO -
op(Priority, Specifier, Operator)
Alters the operator table. ISO -
current_op(Priority, Specifier, Operator)
Succeeds iff the operator indicated byPriority
,Specifier
,Operator
is in the operator table. ISO -
char_conversion(In, Out)
Alters the character conversion mapping. ISO -
current_char_conversion(In, Out)
Succeeds iff the character conversion fromIn
toOut
is in the conversion mapping. ISO
-
\+Goal
Succeeds iffcall(Goal)
fails. ISO -
once(Goal)
CallsGoal
but never redoes. ISO -
repeat
Repeats the following code until it succeeds. ISO -
call(Closure, Arg1, ..., ArgN)
N = 1..7
. Succeeds iffcall(Goal)
whereGoal
isClosure
with additional argumentsArg1, ..., ArgN
. ISO -
false
Equivalent tofail
. ISO -
between(Lower, Upper, X)
Succeeds iffLower <= X <= Upper
. prologue
-
atom_length(Atom, Length)
Succeeds iffLength
is the number of runes inAtom
. ISO -
atom_concat(Atom1, Atom2, Atom3)
Succeeds iffAtom3
is a concatenation ofAtom1
andAtom2
. ISO -
sub_atom(Atom, Before, Length, After, SubAtom)
Succeeds iffSubAtom
is a sub atom ofAtom
whereBefore
is the number of runes beforeSubAtom
,Length
is the length ofSubAtom
, andAfter
is the number of runes afterSubAtom
. ISO -
atom_chars(Atom, List)
Succeeds iffList
is the list of single-rune atoms thatAtom
consists of. ISO -
atom_codes(Atom, List)
Succeeds iffList
is the list of runes thatAtom
consists of. ISO -
char_code(Char, Code)
Succeeds iffChar
is a single-rune atom which rune isCode
. ISO -
number_chars(Number, List)
Succeeds iffList
is the list of single-rune atoms that representsNumber
. ISO -
number_codes(Number, List)
Succeeds iffList
is the list of runes that representsNumber
. ISO
-
set_prolog_flag(Flag, Value)
Sets the Prolog flagFlag
toValue
. ISO-
Flag
is either:-
char_conversion
Value
is eitheron
oroff
(default). -
debug
Value
is eitheron
oroff
(default). -
unknown
Value
is eithererror
(default),fail
, orwarning
. -
double_quotes
Value
is eitherchars
(default),codes
, oratom
.
-
-
-
current_prolog_flag(Flag, Value)
Succeeds iffValue
is the current value for the Prolog flagFlag
. ISO-
Flag
is either:-
bounded
Value
is alwaystrue
. -
max_integer
Value
is always9223372036854775807
. -
min_integer
Value
is always-9223372036854775808
. -
integer_rounding_function
Value
is alwaystoward_zero
. -
char_conversion
Value
is eitheron
oroff
(default). -
debug
Value
is eitheron
oroff
(default). -
max_arity
Value
is alwaysunbounded
. -
unknown
Value
is eithererror
(default),fail
, orwarning
. -
double_quotes
Value
is eitherchars
(default),codes
, oratom
.
-
-
-
halt(X)
Exits the host program with the status code ofX
. ISO -
halt
Equivalent tohalt(0)
. ISO
-
expand_term(In, Out)
Succeeds iffOut
is an expansion of the termIn
. -
phrase(Phrase, List, Remainder)
Succeeds iff the different listList-Remainder
satisfies the grammar rulePhrase
. -
phrase(Phrase, List)
Equivalent tophrase(Phrase, List, [])
.
-
member(X, L)
Succeeds iffX
is a member of the listL
. prologue -
append(Xs, Ys, Zs)
Succeeds iffZs
is the concatenation ofXs
andYs
. prologue -
length(List, Length)
Succeeds iffLength
is the length ofList
. prologue -
select(X, Xs, Ys)
Succeeds iffX
is an element ofXs
andYs
isXs
with one occurence ofX
removed. prologue -
maplist(Goal, List1, ..., Listn)
n = 1..7
. Succeeds iffList1, ..., Listn
are the list of the same length andcall(Goal, List1_i, ..., Listn_i)
succeeds for all thei
-th elements ofList1, ..., Listn
. prologue -
nth0(N, List, Elem)
Succeeds iffElem
is theN
-th element ofList
counting from 0. -
nth1(N, List, Elem)
Succeeds iffElem
is theN
-th element ofList
counting from 1.
-
consult(File)
Loads Prolog program files indicated byFile
.File
is either an atom or a list of atoms. An atomabc
indicates a Prolog program file./abc
or./abc.pl
. -
[File|Files]
Equivalent toconsult([File|Files])
.