Amzi! Prolog User's Guide & Reference
Contents Index
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 Amzi! 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 IDE Quick Start Eclipse IDE Quick Start Beginning Users Open a Source File When you create a new file, it will be opened in the Editor View.Otherwise, in the Navigator View, double-click on the name of the file you want to edit. It will open in the Editor View.Type in your code.Save a Source File Select File | Save When you save a file, a new outline is generated and the source file is checked for syntax errors. Check the Problems View to see the errors:Any errors will be highlighted in your Edit View. You can click on the red boxes in the right margin.Run a Single Source File Open a source file for editing (or click on the file name in the Navigator View ). Select Run | Run As | Interpreted Single File (pro) This start the Prolog Listener in the Listener View:After the?-type the goal you want to execute (in this case main.). You can use the arrow keys to retrieve and edit the goals you entered previously.Type debug.to use the classic box-model debugger.Type quit.to exit.Debug a Single Source File Open a source file for editing (or click on the file name in the Navigator View ). Select Run | Debug As | Interpreted Single File (pro) This opens the Debug Perspective (you were previously in the Prolog Perspective):After the?-type the goal you want to debug (in this case 'main.' followed by the command 'goto(yard).'.) The currently executing line is highlighted with a C for call, R for redo, F for fail, E for exit and I for info. Pausing at each of those debug ports is controlled by the buttons in the Debug View. The use the buttons in the Debug View in the upper left to run, suspend, stop and step your program. This view also displays the Prolog call stack.The Variables View in the upper right shows your variable bindings at each level of the call stack.To set a breakpoint, double-click in the left margin of the source file (see the blue dot).Press or type quit.to exit. Type [Ctrl]-C to break user input. Click on the paw in the left margin of the Eclipse Window to return to the Prolog Perspective. Advanced Users Editor and Outliner Editor and Outliner Editor Functions Using Unicode Outliner Preferences Listener Listener Starting and Stopping the Listener IDE Command Line Entering and Editing Commands Adding and Removing Clauses assert Adding a Rule Consulting user add Removing Clauses Listing Clauses Querying the Logic Base Consulting Prolog Source Files Loading Compiled Prolog Code Listener Commands add debug pp(Term), user_pp(Term) quit replace Debugger Source Code Debugger Box Model Debugging Perspective Running the Debugger Launch Configurations Starting and Exiting Remote Debugging Display Debug Commands Breakpoints Breaking at Debug Ports Example Command-Line 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 and Syntax Checker Cross Referencer and Syntax Checker Running Warnings and Errors 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 Eclipse IDE The Prolog Perspective Prolog Projects and Building Executables Setting Project Properties Creating Projects Opening, Closing and Deleting Projects Starting the Listener and Prolog Programs Starting the Listener Launch Configurations Running Compiled Programs Starting the Source Code Debugger 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 unify_with_occurs_check(X,Y) is_cyclic(Term) 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 string_query(QUERYSTRING, RESULTSTRING) varlist_query(QUERYSTRING, LENGTH, RESULTLIST) 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) is_atom(X) name(Atom, CharList) sub_atom(Atom, Index, Length, SubAtom) List Processing is_member(Term, List) sort(List, SortedList) keysort(KeyedList, KeyedSortedList) String Processing is_string(X) nonblank_string(String) strcat(StringA, StringB, StringAB) stringlist_concat(StringList, String), stringlist_concat(StringList, Separator, String) string_atom(String, Atom) string_float(String, Float) string_icomp(String1, String2) string_integer(String, Integer) string_number(String, Number) string_length(String, Length) string_list(String, List) string_split(String, DelimitersS, List) string_term(String, Term) string_termq(StringQ, Term) is_string_term(String, Term) string_tokens(String, TokenList), string_tokens(String, TokenList, DelimitersS) string_trim(String, TrimmedString) sub_string(String, Index, Length, SubString) tilt_slashes(InAS, OutAS) Character List Processing atom_chars(Number, CharList) char(X) char_code(Atom, CharList) number_chars(Number, CharList) 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 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_fraction(N) is_integer(N) is_odd(N) is_number(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 at_end_of_stream(ID) flush_output, flush_output(ID) nl, nl(ID) skip(CODE), skip(ID, CODE) tab(N), tab(ID, N) respkey(CHAR) Repositioning Streams stream_property(ID, position(Position)) 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 Parsing Files