10



AMZI-Prologi primitiivid


Peale programmikäskude täitmist organiseerivate predikaatide
, - ja
; - või
! (cut, lõige) - katkestab tagurdamise (backtrackingu)
goal1 -> goal2 - if-then-else, s.t. goal2 hakkatakse tõestama ainult siis, kui goal1 on tõene (tagurdamisel ebaõnnestub)
on AMZI-Prologis veel palju sisseehitatud predikaate. Järgnevas loetelus (võetud Help-ist) on argumentide tüübid tähistatud argumendi nime viimase tähega:

A - atom
C - tähtede nimistu (character list)
F - reaalarv (float)
N - täisarv
L - nimistu
T - term
V - muutuja (variable)
S - string

abolish(NameA/ArityN) - abolish all clauses whose head is Name/Arity. abolish(NameA, ArityN) - abolish all clauses whose head is Name/Arity. abort(SeverityN) - depending on Severity, 0 aborts and restarts Prolog, 1 aborts back to DOS normally, 2 aborts back to DOS with abnormal return.
arg(N, TermT, ArgV) - unify Arg with the Nth argument of term Term. assert(TermT) - assert Term to the dynamic database.
asserta(TermT) - assert Term to the dynamic database as first clause with its functor.
assertz(TermT) - assert Term to the dynamic database as last clause with its functor.
atom(X) - succeeds if X is an atom.
atom_codes(AtomAV, CharListCV) - convert back and forth between an atom and a list of characters.
atom_uplow(AtomUpperAV, AtomLowerAV) - creates a new upper case atom from a lower and vice versa.
atomic(X) - succeeds if X is an atom or integer,
atom_length(AtomA, LengthV) - unifies the Length of Atom. atomlist_concat(AtomListL, AtomV) - concatenates all of the atoms in AtomList to create a single atom, Atom.
atom_concat(Atom1AV, Atom2AV, Atom3AV) - concatenates atoms Atom1 and Atom2 and unifies with Atom3, or generates all possible pairs of atoms, Atom1/Atom2, from Atom3.
bagof(Instance, Goal, List) - create a List of unified Instances that satisfy Goal. Backtracking tries again if there are variables in Goal not in Instance.
call(Goal) - tries to prove Goal, equivalent to simply Goal.
catch(Goal, Catcher, Recover) - Tries to prove Goal, catching exception terms matching Catcher and proving Recover.
chdir(DirACS, ErrN) - changes directory to Dir, returns error code in Err. clause(Head, BodyV) - designed to backtrack through all the clauses in the dynamic database.
closelog - close the logging file.
cntr_dec(CounterN, ValueV) - unify Value with current value of Counter, then decrement Counter.
cntr_get(CounterN, ValueV) - unify Value with current value of Counter. cntr_inc(CounterN, ValueV) - unify Value with current value of Counter, then increment Counter.
cntr_set(CounterN, ValueN) - set the value of Counter to Value. command_line(ArgsListofListsV) - unifies the list ArgsListofLists with the command line arguments used to start the program.
compare(OpResultV, Term1, Term2) - compares the Term1 to Term2 and unifies Result with the appropriate one of ==, <, or >
compare_lists(List1, List2, DiffListV) - DiffList is the elements of List1 that are not in List2.
consult(FileA) - consult source, object or load file, adding it onto the dynamic database.
cputime - a built-in atom that is a floating point number of the CPU seconds expired.
current_atom(Atom) - designed for a backtracking tour through all the atoms.
current_prolog_flag(FlagAV, ValueNV) - returns the values of various system limits.
current_streams(InputIdV, OutputIdV, ErrorIdV) - for each bound argument, sets the appropriate current stream, for unbound arguments, unifies the argument with the appropriate current stream.
current_user(InputIdV, OutputIdV, ErrorIdV) - for each bound argument, sets the appropriate user (default) stream, for unbound arguments, unifies the argument with the appropriate user (default) stream.
cut_tag(Term) - fails and cuts back to the last tag(Term) goal, useful for abandoning ship when dealing with error conditions
date(MonthNV, DayNV, YearNV) - returns the current date if unbound, or succeeds if it is today
db_ref(HeadTV, BodyTV, DBrefNV) - either finds the DBref for the clause Head :- Body, or finds the Head and Body at DBref.
delfile(PathACS, ErrIN) - deletes file specified by Path returning the error code.
display(Term) - displays Term without expanding operators.
e - an atom representing the floating point value of e.
erase(DBref) - erase the term at DBref.
eraseall(KeyA) - erase all the terms stored under Key.
err_handle(-ErrorN, TermV, ActionN) - error handler to be called when Error error is raised, and Term is unified with the term causing the error. Action is what occurs after the error is handled.
err_msg(-ErrorN, MessageCV) - get the Message associate with a negative error number.
err_raise(-ErrorN) - raise the error condition for a negagive error number.
err_read(CharListV, IndexV) - after a read error, get the list of character codes, and index into them, that caused the error.
expand_term(DCGtermT, PROLOGtermV) - expands a DCG term into a Prolog term.
fail - fails when called
fclose(ID) - close the file identified by ID.
fflush(ID) - flush the I/O to file identified with ID
file_exists(FileACS) - succeeds if FileA exists.
file_exists(FileACS, TypeV{1=PLM,2=source}) - succeeds if FileA exists, returns Type, 1 = Prolog object file, 2 = ASCII file
findall(Instance, Goal, List) - create a List of unified Instances that satisfy Goal.
findfiles(MaskASC, AttrN, FileInfo(NameV, AttrV, time(HourV, MinV, SecV), date(YearV, MonthV, DayV), SizeV)) - returns file information in structure FileInfo for first file in current directory of type Attr, with name matching Mask. On backtracking returns next file.
float(X) - succeeds if X is a floating point number. flush_in - flushes the input stream.
flush_out - flushes the output stream.
fopen(HandleV, FileACS, ModeA {r,w,a,rb,wb,ab}) - opens file named FileA in read/write mode Mode, unifies Handle with resulting handle. for(IndexN, StartN, EndN, IncrementN) - a for loop in Prolog, designed to increment the index on backtracking, succeeding if End hasn't yet been reached, failing if it has.
fread(ID, ValueV, TypeN {0=one byte, 1=two-byte integer, 2=four-byte float, 3=four-byte integer}) - read direct from file identified by ID a Value of length specified by Type.
fseek(ID, OffsetN, MethodN{0=start,1=current,2-end NewOff}) - reposition file identified by ID according to Offset and Method. Unify NewOff with new position.
functor(TermV, FunctorAV, ArityNV) - split a term into its functor and arity, or build a term from a functor and arity.
fwrite(ID, ValueV, TypeN {0=one byte, 1=two-byte integer, 2=four-byte float, 3=four-byte integer}) - write direct to file identified by ID a Value of length specified by Type.
gc - invoke the garbage collector.
gc(4) - garbage collect the heap.
gensym(RootA, SymbolV) - generate a new atom from Root and unify it with Symbol.
get(CharV) - get next character from current input stream.
get(ID, CharV) - get next character from stream ID.
get0(CharV) - get next character from current input stream, return !EOF if end of file reached.
get0(ID, CharV) - get next character from stream ID, return !EOF if end of file reached.
get1(CharV) - gets the next character from the keyboard followed by [Enter] (for environments not supporting keyb/1)
get_mode(ModeA, OnOffV) - gets the current setting of Mode: on or off. get_preds(PredList) - returns a list of the names/arities of all dynamic predicates.
getdrive(DirAS) - gets the current drive.
halt - stop Prolog execution and return to either operating system or IDE. handle_name(HandleNV, NameAV) - find either a streams Name or Handle from the other
instance(DBref, TermV) - unifies Term with term at DBref. integer(X) - succeeds if X is an integer.
Number is ArithExp - evaluate ArithExp and unify with Number.
keyb(AsciiV) - returns the ASCII code of the next key pressed.
lint - turn on lint checking.
list(X) - succeeds if X is a list.
listing - list all the clauses in the dynamic database.
listing(Predicate) - list all the clause of Predicate in the dynamic database. Predicate can be either of the form Functor, or Functor/Arity.
load(FileA) - load and object or load file, File, into the static database. long(X) - succeeds if X is a long integer.
mkdir(DirACS, ErrN) - make a new directory, Dir, unify return code with Err.
name(Atom, CharList) - convert back and forth between an atom and a list of characters.
nl - write a newline character to the current output stream.
nl(ID) - write a newline character to stream ID.
nllog - write a newline to the log file.
nonblank_string(String) - succeeds if String is not empty.
nonvar(X) - succeeds if X is not an unbound variable
not(Goal) - succeeds if Goal fails.
\+ Goal - synonym for not, succeeds if Goal cannot be proved.
number(X) - succeeds if X is an integer or floating point number. numbervars(Term, StartN, EndV) - unify variables of Term with atoms of the form _n, where n is an integer starting at Start for the first unique variable and ending at End. Called with Start bound and End unbound.
once(Goal) - tries to prove Goal once (without backtracking).
op(PrecN, AssociativityA {xfx, xfy, yfx, yfy, fx, fy, xf, yf OpA) - defines operator Op of precedence Prec and associativity As. Op can be a list of operators of same precedence and associativity
openlog(FileA) - open File as a log file and turn logging on.
pi - an atom representing the floating point value of pi.
pp(Term) - pretty print Term.
pro_control(TopV, PosV) - returns current size, Top, and position, Pos, of the control stack.
pro_db(SizeV) - unify Size with current memory used by dynamic database.
pro_heap(TopV, PosV) - returns current size, Top, and position, Pos, of the heap.
pro_local(TopV, PosV) - returns current size, Top, and position, Pos, of the local stack.
pro_mem(SizeV) - returns the total current memory used by Prolog. pro_trail(TopV, PosV) - returns current size, Top, and position, Pos, of the trail stack.
put(CharN) - write the ASCII Char to the current output stream.
put(ID, CharN) - write the ASCII Char to the stream ID.
random - a built-in atom that is a floating point random number >= 0.0 and < 1.0.
rca(CharV, AttrV) - read the Char and Attr of the screen at the current cursor position.
read(TermV) - read the next Term from the current input stream. Note Term must end in a period.
read(ID, TermV) - read the next Term from the stream ID. Note Term must end in a period.
read_string(StringV) - read characters up to next newline character from current input stream, and unify with String.
read_string(ID, StringV) - read characters up to next newline character from stream ID, and unify with String.
reconsult(FileA) - reconsult, replacing old predicate definitions, the source, object or load file File.
record(KeyA, Term, DBrefV) - record Term as first term under Key, DBref is where it wound up.
recorda(KeyA, Term, DBrefV) - record Term as first term under Key, DBref is where it wound up.
recorded(KeyA, TermV, DBrefV) - finds Terms and their DBrefs stored under Key, backtracking finds them all.
recordz(KeyA, Term, DBrefV) - record Term as the last term under Key, DBref is where it wound up.
rename(OldFileNameACL, NewFileNameACL, ErrN) - renames the old file name to the new file name, returning the error code in ErrN.
remove_dups(List, NoDupsListV) - remove duplicates from List, unify result with NoDupsList.
repeat - succeeds the first time called, succeeds every time it’s backtracked into.
respkey(CharV) - gets a key using keyb/1 if possible, otherwise get1/1.
retract(Term) - retract the first term in the database that unifies with Term. On backtracking retract the next.
retractall(Term) - retract all dynamic database terms that unify with Term.
rmdir(DirACS, ErrN) - remove the directory Dir, unify the return code with Err.
see(NameA) - set the current input stream to the named stream. seed_random(Int) - seeds the random number generator.
seeing(NameA) - unify NameA with the current input stream.
seetell(NameA) - set the current input and output streams to NameA. seen - close the current input stream, set current input stream to user.
seentold - close the current input and output streams, setting both to user.
set_errors(NameA) - sets the current_error stream to NameA. set_mode(ModeA, OnOffA) - sets the Mode ‘on’ or ‘off.’
set_drive(DriveAS) - sets the current drive.
setof(Instance, Goal, List) - create an ordered List of unified Instances that satisfy Goal. Backtracking tries again if there are variables in Goal not in Instance.
short(X) - succeeds if X is a short integer
skip(Char) - continuously read characters from current input stream until one matching Char is read. Fail if !EOF is reached.
skip(ID, Char) - continuously read characters from stream ID until one matching Char is read. Fail if !EOF is reached.
sort(List, SortedListV) - sort List into SortedList.
stack_sizes(HeapV, ControlV, LocalV, TrailV) - return number of cells used on each stack.
strcat(S1, S2, S3) - concatenates strings S1 and S2 to create S3. the first two arguments must be instantiated.
stream_type(ID, TypeN) - returns TypeI of stream, 0 - stdio, 1 - file, 2 - window, 3 - redirected through a function, -1 - not defined.
string(X) - succeeds if X is a string.
string_atom(String, Atom) - convert between String and Atom name. string_integer(String, Int) - converts between integer and string. string_length(String, Length) - returns the length of a string. string_list(String, CharList) - converts between string and list of characters.
string_term(String, Term) - converts between strings and terms. string_termq(String, Term) - converts between strings and terms, but when going from term to string, it quotes atoms if necessary and puts strings in $ $ delimiters for rereading.
stringlist_concat(StringList, String) - concatenates the strings and atoms in StringList to create the single String.
structure(X) - succeeds if X is a structure
sub_atom(Atom, IndexNV, LengthNV, SubatomV) - Subatom of Atom starting at Index of Length.
sub_string(String, IndexNV, LengthNV, SubstringV) - Substring of String starting at Index of Length.
tab(CountN) - write Count spaces to the current output stream.
tab(ID, CountN) - write Count spaces to the stream ID.
tag(Term) - defines a tag point which might be used later by cut-tag to escape from the depths of Prolog invocation
tell(NameA) - set current output to the stream named NameA.
telling(NameA) - unify NameA with the current output stream.
throw(Term) -search for a matching catch Term.
time(HourNV, MinNV, SecNV) - unifies arguments with current time, if any arguments are bound, then succeeds of fails if unification succeeds or fails.
timer(TicksV) - unifies Ticks with floating point seconds since whenever.
told - close the current output stream, resetting it to user.
true - succeeds when called, fails on backtracking
ttyflush - discard any character in keyboard buffer.
ttyrdy - succeeds if there is an unread character in the keyboard buffer.
Term =.. List - convert a term into a list whose head is the functor and tail is a list of the arguments, or take a list and reverse the process to create a term. (called univ)
user_pp(Term) - is called by pp/1 (if it exists) for your own pretty printer. var(X) - succeeds if X is an unbound variable,
varlist(List) - a list of the variable names, each as a character list, when the predicate was called.
varsof(Term, List) - unify List with a list of all uninstantiated variables in Term version(VersionS) - return current Amzi! version.
write(Term) - write Term to the current output stream. write(ID, Term) - write Term to stream ID.
writelog(Term) - write Term to the log file, if logging.
writeq(Term) - write Term to the current output stream, quoting atoms as necessary.
writeq(ID, Term) - write Term to the stream ID, quoting atoms as necessary.


Küsimused, probleemid:

jaak@cc.ttu.ee

Tagasi loengute sisukorra juurde