Amzi! Prolog User's Guide & Reference
Amzi! Prolog User's Guide and Reference Contents Purpose Quick Overview Quick Overview Components Relationship of Files and Components Listener/Debugger Debugger Intermixing Interpreted and Compiled Code Compiler Linker Interactive Development Environment (IDE) Stand-Alone Runtime Embedded Applications Where to Go Next? Quick Tutorial Quick Tutorial Duck World Starting the Listener Creating a Source File Consulting a Source File Using the Listener Debugging Modules Running a Modular Application Using Projects in the IDE Compiling Linking and Running Distributing an Application Interfacing with Other Tools Listener Listener Starting and Stopping the Listener Command Line IDE Adding and Removing Clauses assert Adding a Rule Consulting user add Removing Clauses Listing Clauses Querying the Logic Base Consulting Prolog Source Files From Within a Listener From the Command Line IDE Options Loading Compiled Prolog Code Listener Commands add consult_project(ProjectFile) debug pp(Term), user_pp(Term) quit reconsult_project(ProjectFile) replace Debugger Debugger Box Model Starting and Exiting Display portray(GOAL) Debug Port Options Spypoints Leashing Debug Ports Logging Example Compiler Compiler Advantages Disadvantages Requirements Directives Running from the IDE Running from the Command-Line Messages Errors Complex Clauses Complex Predicates Main Predicate Linker Linker Running from the IDE Running from the Command-Line Libraries Cross Referencer & amp; Syntax Checker Cross Referencer & Syntax Checker Amzi! Runtime Amzi! Runtime Running arun from the Command-Line Configuration Files Configuration Parameters Default.cfg Values Flags current_prolog_flag(FLAG, VALUE) set_prolog_flag(FLAG, VALUE) Configuration Flags Settable Flags IDE IDE Interface Unicode, Locale, and Multibyte Characters File Menu Edit Menu View Menu Listener Menu Build Menu Window Menu Help Projects Projects Creating a Project Dialog Box Consulting/Loading Building Debugging Your Programs Debugging Your Programs Initial Development for Embedded Modules Tracking Prolog Errors Logging Debugger-Like Output catch and throw Prolog Error File Writing Your Own Embedded Debugging Predicates Tracking LSAPI Errors Tracing LSAPI Calls Checking LSAPI Error Codes Examining Prolog Terms Distributing Your Programs Distributing Your Programs Redistributable Files Preprocessor Preprocessor Directives #define Prolog Directives Prolog Directives Dynamic Clauses in Compiled Code Multifile Directive Discontiguous Directive Include Directive Ensure Loaded Directive Op Directive Set Prolog Flag Latent Expressions Prolog Terms Prolog Terms Internationalization Atoms Symbol Set for Atoms Escape Characters Enabling and Disabling Escape Processing Escape Codes Using Escape Codes Strings Variables Numbers Integers Negative Numbers Decimal Numbers Structures Lists Character Lists Character Constants Comments Operators Precedence Associativity op(Precedence, Associativity, Operator) current_op(Precedence, Associativity, Operator) Predefined Prolog Operators Prolog Execution Prolog Execution Clauses Unification Backtracking Search Complex Goals X, Y X; Y Goal1-Goal2; Goal3 call(Goal) not(Goal) \+ Goal once(Goal) findall(Instance, Goal, List) bagof(Instance, Goal, List) setof(Instance, Goal, List) Flow-of-Control ! Cut repeat fail true for(Index, Start, End, Increment) catch(GOAL, ERROR, HANDLER) throw(TERM) halt Counters cntr_get(Counter, Value) cntr_dec(Counter, Value) cntr_inc(Counter, Value) cntr_set(Counter, Value) Modules Modules Default User Module System Module Defining Modules Adding Predicates to a Module Referring to Modules Exports Imports Metapredicates Manipulating Terms Manipulating Terms Term Typing term_type(TERM, TYPE) atomic(X) atom(X) string(X) number(X) compound(X) structure(X) list(X) is_list(X) var(X) nonvar(X) Equality of Terms X = Y X \= Y X == Y X \== Y not(not(X = Y)) Standard Order of Terms Ordering of Terms X @< Y X @> Y X @=< Y X @>= Y compare(Result, Term1, Term2) Term Creation and Decomposition functor(TERM, FUNCTOR, ARITY) arg(N, Term, Argument) Term =.. List (univ) gensym(Root, Sym) copy_term(T1, T2) Variable Identification numbervars(TERM, START, END) varlist(List) varsof(Term, List) Atoms, Lists and Strings Atoms, Lists and Strings Atom Processing atom_codes(Atom, CharList) atomlist_concat(AtomList, Atom) atom_concat(Atom1, Atom2, AtomVar3) atom_length(Atom, Length) atom_uplow(AtomUpper, AtomLower) name(Atom, CharList) sub_atom(Atom, Index, Length, SubAtom) List Processing is_member(Term, List) sort(List, SortedList) keysort(KeyedList, KeyedSortedList) String Processing nonblank_string(String) strcat(StringA, StringB, StringAB) stringlist_concat(StringList, String), stringlist_concat(StringList, Separator, String) string_atom(String, Atom) string_icomp(String1, String2) string_integer(String, Integer) string_length(String, Length) string_list(String, List) string_split(String, DelimitersS, List) string_term(String, Term) string_termq(StringQ, Term) string_tokens(String, TokenList), string_tokens(String, TokenList, DelimitersS) string_trim(String, TrimmedString) sub_string(String, Index, Length, SubString) tilt_slashes(IN, OUT) Numbers and Math Numbers and Math Evaluating Mathematical Expressions X is Y Mathematical Comparisons X >= Y X =< Y X > Y X < Y X =:= Y X =\= Y Mathematical Operators X + Y X - Y - X X * Y X / Y X ** Y X // Y X divs Y X divu Y max(X,Y) min(X,Y) X mod Y X mods Y X modu Y Bitwise Operators X /\ Y X \/ Y X << Y X >> Y \ X X xor Y Trigonometry Functions sin(X) cos(X) tan(X) asin(X) acos(X) atan(X) Mathematical Functions abs(X) ceiling(X) exp(X) float(X) floor(X) integer(X) ln(X), log(X) log10(X) real(X) round(X) sign(X) sqrt(X) Built-in Atoms seed_random(I) Number Types numeric_type(N,T) integer(N) is_integer(N) float(N) single_float(N) double_float(N) real(N) fixed_real(N) long_real(N) Mixed Mode Expressions Mathematical Games Modulo Arithmetic Notes on Reals and Gigadigits Prime Numbers Rational Numbers Continued Fractions Prolog Logicbase Prolog Logicbase Modules current_module(MODULE) Predicates current_predicate(M:F/A) predicate_property(M:F/A, PROPERTY) Static Predicates load(FileA), load([F1, F2,...]) load(memory, NAME, SIZE, ADDRESS) unload(FileA), unload([F1, F2,...]) Dynamic Predicate Storage Options :-dynamic F/A :-indexed F(I1, I2,...) :-sorted F/A Dynamic Predicates abolish(M:F/A) asserta(TERM) assertz(TERM) assert(TERM) clause(HEAD, BODY) retract(TERM) retractall(TERM) Input and Output Input and Output General Principles Stream IDs Backtracking and I/O End of File Streams Standard Streams Stream Properties stream_property(STREAM, PROPERTY) String I/O Open and Closing Files open(FILE, MODE, ID, OPTIONS) open(FILE, MODE, ID) close(ID) Reading and Writing Prolog Terms read(TERM), read(ID, TERM) write(TERM), write(ID, TERM) writeq(Term), writeq(ID, Term) listing, listing(PRED), listing(ID, PRED) pp(TERM), pp(ID, TERM) consult(FILE), reconsult(FILE) display(Term) Reading and Writing Strings and Characters get(CODE), get(ID, CODE) get0(CODE), get0(ID, CODE) put(CODE), put(ID, CODE) read_string(STRING), read_string(ID, STRING) Special Purpose I/O Predicates flush_output, flush_output(ID) nl, nl(ID) skip(CODE), skip(ID, CODE) tab(N), tab(ID, N) respkey(CHAR) Repositioning Streams set_stream_position(ID, POSITION) Redirecting Streams current_input(ID) current_output(ID) set_input(ID) set_output(ID) see(ID), see(FILENAME), see(user) seen seeing(ID) tell(ID), tell(FILENAME), tell(user) told telling(ID) Binary I/O read_binary(ID, DATA_TYPE, DATA) write_binary(ID, DATA_TYPE, DATA) Logging openlog(Fname) closelog writelog(X) nllog System Predicates System Predicates command_line(ArgsL) date(MONTH, DAY, YEAR) time(HOUR, MIN, SEC) gc highwater(Heap, Local, Control, Trail) loadlsx(FilenameA) pro_heap(Top, Pos) pro_control(Top, Pos) pro_local(Top, Pos) pro_trail(Top, Pos) stack_sizes(Heap, Control, Local, Trail) system(CmdA) timer(Ticks) version(String) O.S. Extended Predicates O.S. Extended Predicates File and Directory Name Parameters chdir(DirL) chdir(DirL, Err) curdir(DirS) delfile(PathL, Err) mkdir(DirL, Err) rename(OldName, NewName, Err) rmdir(DirL, Err) findfiles(Mask, Attr, FileInfo) stat(FileName,Atime,Ctime,Mtime,Size,Mode,NLink,Uid,Gid) getdrive(Drive) setdrive(Drive) get_env_var(VARIABLE, VALUE) w_getfile(FileStr) w_msgbox(Term) w_tfmsgbox(Term) Definite Clause Grammars (DCGs) Definite Clause Grammars (DCGs) Parsing with Difference Lists Generating with Difference Lists DCG Syntax expand_term(DCGclause, PROLOGclause) Applications of DCG and Difference Lists Language Translation Bill of Materials Command Language XML DCG Terminals