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 open/3
.
The possible formats of a stream are:
n
symbol
add_stream_alias/2
. Note that user_input
,
user_output
, and user_error
are by default aliased to the
UNIX stdin
, stdout
, and stderr
streams.
Shell-like expansions of filenames is provided.
None.
read(?Term)
read(+Stream,?Term)
read(Stream, Term)
causes the end
of Stream to be reached, Term is unified with the term
eof
. Further calls to read/2
for the same stream
will then fail, unless the stream is connected to the
terminal.
read_term(?Term,+Vars)
read_term(+Stream,?Term,+Vars)
read/1-2
with 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(?Term)
write(+Stream,?Term)
writeln(?Term)
writeln(+Stream,?Term)
write/1-2
except that a newline is send,
display(?Term)
writeq(?Term)
writeq(+Stream,?Term)
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. get_char(?C)
get_char(+Stream,?C)
user_input
).
put_char(+C)
put_char(+Stream,+C)
user_output
).
open(+FileName,+Mode,-Stream)
fopen
) and the resulting
stream is unified with Stream. Mode is one of:
read
write
append
close(+Stream)
absolute_file_name(+RelativeName,?AbsoluteName)
current_input(?Stream)
SP_curin
.
current_output(?Stream)
SP_curout
.
set_input(+Stream)
set_output(+Stream)
flush_output
flush_output(+Stream)
from_alias_to_stream(+Alias,?Stream)
add_stream_alias(+Stream_or_Alias,+Alias)
None.
The DEC-10 prolog IO predicates are available with the library `dec10':
see(+File)
see/1
or a filename. If it is a
filename, the following action is taken: If there is a stream opened by
see/1
associated 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.
seeing(?FileName)
see/1
, with the current input stream, if it is not
user_input
, otherwise with user
.
seen
user_input
.
tell(+File)
tell/1
or a filename. If it is a
filename, the following action is taken: If there is a stream
opened by tell/1
associated 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.
telling(?FileName)
tell/1
, with the current output stream, if
it is not user_output
, otherwise with user
.
told
user_output
.
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)
-X
X+Y
X-Y
X*Y
X//Y
X mod Y
integer(X)-integer(Y)*(X//Y)
.
X/\Y
X\/Y
X#Y
\(X)
X<<Y
X>>Y
abs(X)
min(X,Y)
max(X,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:
./2
.
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
+Guard -> +Q ; +R
+Guard -> +Q
+Guard -> +Q;fail
true
fail
wait(+Goal)
The library `call' provide the additionnal predicate:
call(Goal)
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).
error(Error)
None.
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.
var(?X)
nonvar(?X)
var/1
.
ground(?X)
atom(?X)
integer(?X)
number(?X)
atomic(?X)
simple(?X)
compound(?X)
functor(+Term,?Name,?Arity)
functor(?Term,+Name,+Arity)
arg(+ArgNo,+Term,?Arg)
+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.
name(+Const,?CharList)
name(?Const,+CharList)
%>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.
atom_chars(+Const,?CharList)
atom_chars(?Const,+CharList)
name(Const,CharList)
, but Const
is constrained to be an atom.
number_chars(+Const,?CharList)
number_chars(?Const,+CharList)
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)
None.
The predicates described in this section store arbitrary terms in the database without interfering with the clauses which make up the program.
record(+Term)
recorded(+Term)
erase(+Term)
The predicates described in this section works on the whole set of solutions that may be computed for a goal.
bestof(X,Generator,Y^Test)
%>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.
group_by(Generator,Grouping,Collector)
New^Current^(Old^Updater,Init)
almagates values Current build by Generator
Note that group_by fails if Generator has no answer.
None
None
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
employed.
phrase(:Phrase,?List,?Remainder)
phrase(:Phrase,?Left,?Right)
?X = ?Y
Z=Z.
; i.e. X and Y are
unified.
length(?List,?Length)
copy_term(?Term,?CopyOfTerm)
argv(?Args)
cd
shell(+Command,-Status)
$SHELL
for execution. Unify Status with the
returned status of Command.
system(+Command,-Status)
sh
process for execution. Unify
Status with the returned status of Command.
mktemp(+Template,-FileName)
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.
access(+Path,+Mode)
access(2)
.
getwd(?Path)
getenv(+Name,?Value)
gensym(-Id)
domain(x?X,+List)
member/2
.
Go to the first, previous, next, last section, table of contents.