Not every standard built-in predicate found in most Prolog evaluators are avaliable in DyALog and will not be because DyALog is mostly devoted to build parsers.
Input / Output in DyALog is done through streams that can associated either to a file, a string or a device.
A stream can be connected to a filename or UNIX file descriptor for
input or output by calling the predicate
The possible formats of a stream are:
add_stream_alias/2. Note that
user_errorare by default aliased to the UNIX
Shell-like expansions of filenames is provided.
read(Stream, Term)causes the end of Stream to be reached, Term is unified with the term
eof. Further calls to
read/2for the same stream will then fail, unless the stream is connected to the terminal.
read/1-2with a third argument +Vars. This argument is unified with a list of Name=Var pairs, where each Name is an atom indicating the name of a non-anonymous variable in the term, and Var is the corresponding variable.
write/1-2except that a newline is send,
write(Stream,Term), but the names of atoms and functors are quoted where necessary to make the result acceptable as input to
read/2, provided the same operator declarations are in effect.
fopen) and the resulting stream is unified with Stream. Mode is one of:
The DEC-10 prolog IO predicates are available with the library `dec10':
see/1or a filename. If it is a filename, the following action is taken: If there is a stream opened by
see/1associated with the same file already, then it becomes the current input stream. Otherwise, the file File is opened for input and made the current input stream.
see/1, with the current input stream, if it is not
user_input, otherwise with
tell/1or a filename. If it is a filename, the following action is taken: If there is a stream opened by
tell/1associated with the same file already, then it becomes the current output stream. Otherwise, the file File is opened for output and made the current output stream.
tell/1, with the current output stream, if it is not
user_output, otherwise with
Arithmetic is performed by built-in predicates which take as arguments arithmetic expressions and evaluate them. An arithmetic expression is a term built from numbers, variables, and functors that represent arithmetic functions. At the time of evaluation, each variable in an arithmetic expression must be bound to a non-variable expression. An expression evaluates to a number, which may be an integer.
Only certain functors are permitted in an arithmetic expression. These are listed below, together with an indication of the functions they represent. X and Y are assumed to be arithmetic expressions. Unless stated otherwise, the arguments of an expression may be any numbers.
X mod Y
Arithmetic expressions, as described above, are just data structures. If you want one evaluated you must pass it as an argument to one of the built-in predicates listed below. Note that it only evaluates one of its arguments, whereas all the comparison predicates evaluate both of theirs. In the following, X and Y stand for arithmetic expressions, and Z for some term.
Z is X
X =:= Y
X =\= Y
X < Y
X > Y
X =< Y
X >= Y
These built-in predicates are meta-logical. They treat uninstantiated variables as objects with values which may be compared, and they never instantiate those variables. They should not be used when what you really want is arithmetic comparison (see section Arithmetic) or unification.
The predicates make reference to a standard total ordering of terms, which is as follows:
These are the basic predicates for comparison of arbitrary terms:
Term1 == Term2
%>dyalog -s "?-X==Y. "fails (answers `no') because X and Y are distinct uninstantiated variables. However, the query
%>dyalog -s "?-X=Y,X==Y. " Answer : Y = Xsucceeds because the first goal unifies the two variables (see section Miscellaneous).
Term1 \== Term2
Term1 @< Term2
Term1 @> Term2
Term1 @=< Term2
Term1 @>= Term2
+P , +Q
+P ; +Q
+Guard -> +Q ; +R
+Guard -> +Q
+Guard -> +Q;fail
The library `call' provide the additionnal predicate:
call(Term)is executed exactly as if that term appeared textually in its place. There are some restrictions on Goal.
DyALog treats very poorly errors. There is only one predicate to raise errors (but no way to catch them).
The predicates in this section are meta-logical and perform operations that require reasoning about the current instantiation of terms or decomposing terms into their constituents. Such operations cannot be expressed using predicate definitions with a finite number of clauses.
+Term =.. ?List
?Term =.. +List
%>dyalog -s "?-product(0, n, n-1) =.. L. " Answer : L = [product,0,n,n - 1] %>dyalog -s "?-n-1 =.. L. " Answer : L = [-,n,1] %>dyalog -s "?-product =.. L. " Answer : L = [product]If Term is uninstantiated, then List must be instantiated either to a list of determinate length whose head is an atom, or to a list of length 1 whose head is a number.
%>dyalog -s "?-name(product,L). " Answer : L = [0'p,0'r,0'o,0'd,0'u,0'c,0't] %>dyalog -s "?-name(1976,L). " Answer : L = [0'1,0'9,0'7,0'6]If Const is uninstantiated, CharList must be instantiated to a list of characters. If CharList can be interpreted as a number, Const is unified with that number, otherwise with the atom whose name is CharList.
name(Const,CharList), but Const is constrained to be an atom.
name(Const,CharList), but Const is constrained to be a number.
term_subsumer(+Term1, +Term2, -General)
%>dyalog -s "?- term_subsumer(f(g(1,h(_))), f(g(_,h(1))), T). " Answer : T = f(g(B__2,h(A__2))) %>dyalog -s "?- term_subsumer(f(1+2,2+1), f(3+4,4+3), T). " Answer : T = f(B__2 + C__2,C__2 + B__2)
The predicates described in this section store arbitrary terms in the database without interfering with the clauses which make up the program.
The predicates described in this section works on the whole set of solutions that may be computed for a goal.
%>dyalog -s "?-bestof(X,domain(X,[1,-2,3]),Y^(X<Y)). " Answer : X = -2
iterate( Iterator, Generator )
New^(Init,X^Old^Updater)computes the iterate value of Init by repeated application of Updater to each value X generated by Generator.
%>dyalog -s "?-iterate(Y^(Y is 0,X^Old^(Y is X+Old)),domain(X,[1,2,3])). " Answer : Y = 6Note that iterate doesn't fail if there is no answer Generator but binds New variables to Init values.
New^Current^(Old^Updater,Init)almagates values Current build by Generator
Note that group_by fails if Generator has no answer.
Definite Clause Grammars are available in DyALog using the standard notations,
Terminals to be recognized may be provided either by a PROLOG list or a
set of tokens. A token has the form
'C'(Left,T,Right) and means that a terminal
L is present between the markers Left and
Right. Anything may be used as markers, may integers are usually
?X = ?Y
Z=Z.; i.e. X and Y are unified.
$SHELLfor execution. Unify Status with the returned status of Command.
shprocess for execution. Unify Status with the returned status of Command.
mktemp(3). A unique file name is created and unified with FileName. Template should contain a file name with six trailing Xs. The file name is that template with the six Xs replaced with a letter and the process id.
Go to the first, previous, next, last section, table of contents.