next up previous index
Next: More about compilation Up: Getting started with ECLiPSe Previous: The .eclipserc file   Index

Subsections

Interaction with the Toplevel Loop

Entering Goals

The ECLiPSe prompt [eclipse 1]: indicates that ECLiPSe is at the top level and the opened module is eclipse. The top level loop is a Prolog procedure which repetitively prompts the user for a query, executes it and reports its result, i.e. either the answer variable bindings or the failure message. There is always exactly one module opened in the top level and its name is printed in the prompt. From this point it is possible to enter Prolog goals, e.g. to pose queries, to enter a Prolog program from the keyboard or to compile a program from a file. Goals are entered after the prompt and are terminated by fullstop and newline.

Exiting from the Toplevel

The ECLiPSe system may be exited by typing CTRL-D (UNIX) or CTRL-Z + RETURN (Windows) at the top level prompt, or by calling the predicate halt/0 or exit/1.

Entering Programs from the Terminal

To enter Prolog code at the terminal, type [user]. or compile(user). in response to the top level prompt. (The closing bracket must be followed by a ``full stop'' just like any other query.) The system then displays the compiler prompt (which is a blank by default) and waits for a sequence of Prolog clauses. Each of the clauses is terminated by a fullstop. (If the fullstop is omitted the system just sits waiting, because it supposes the clause is not terminated. If you omit the stop by accident simply type it in on the following line, and then proceed to type in the program clauses, each followed by a full stop and carriage return.) To return to the top level prompt, type CTRL-D (UNIX), CTRL-Z + RETURN (Windows) or enter the atom end_of_file followed by fullstop and RETURN.

[eclipse 1]: [user].
 father(abraham, isaac).
 father(isaac, jacob).
 father(jacob, joseph).
 ancestor(X, Y) :- father(X, Y).
 ancestor(X, Y) :- ancestor(X, Z), ancestor(Z, Y).
 ^D
  user       compiled traceable 516 bytes in 0.00 seconds

yes.
[eclipse 2]:
The two predicates father/2 and ancestor/2 are now compiled and can be used.

Querying Programs

Once a set of clauses has been compiled into the database, it may be queried in the usual Prolog manner. If there are no uninstantiated variables in the query, the system replies 'yes' or 'no' and prompts for another query, for example:

[eclipse 1]: father(jacob, joseph).
yes.
[eclipse 2]:
If there are uninstantiated variables in the query, the system will attempt to find an instantiation of them which will satisfy the query, and if successful it will display one such instantiation. It will then wait for a further instruction: either a <CR> (``newline'' or ``return'') or a semi-colon ';'. A return will end the query successfully. A semi-colon will initiate backtracking in an attempt to find another solution to the query. Note that it is not necessary to type a new line after the semicolon -- one keystroke is enough. When the top level loop can detect that there are no further solutions, it does not wait for the semicolon or newline, but it displays directly the next prompt. For example in a query on a family database:
[eclipse 2]: father(X, Y).
X = abraham
Y = isaac   More? (;)   (';' typed)

X = isaac
Y = jacob

yes.
[eclipse 3]:

Queries may be extended over more than one line. When this is done the prompt changes to a tabulation character, ie. the input is indented to indicate that the query is not yet completed. The fullstop marks the end of the input.

Syntax errors

If an error occurs while reading input from the terminal, the system prints an error message after the next newline and waits for input of a correct Prolog term.

[eclipse 3]: a b      <return>
syntax error: postfix/infix operator expected
| a b
|   ^ here
[eclipse 3]:
During compilation, clauses with syntax errors cause an error message and are ignored, but all other clauses are compiled normally.

Interrupting the execution

If a program is executing, it may be interrupted by typing CTRL-C (interrupt in the UNIX environment). This will invoke the corresponding interrupt handler (see section 14.3). By default, the system prints a menu offering some alternatives:

^C
interruption: type a, b, c, e, or h for help : ? help
        a : abort
        b : break level
        c : continue
        e : exit
        h : help

interruption: type a, b, c, e, or h for help : ?
The a option returns to the toplevel, b starts a nested toplevel, c continues the interrupted execution, d switches the debugger to creep mode provided it is running, and e is an emergency exit of the whole ECLiPSe session.

The execution of ECLiPSe may be suspended by typing CTRL-Z (suspend) or by calling pause/0. This will suspend the ECLiPSe process and return the UNIX prompt. Entering the BSD-UNIX C-shell command fg will return to ECLiPSe Note that this feature may not be available on all systems.


History Mechanism

The ECLiPSe toplevel loop provides a simple history mechanism which allows to examine and to repeat previous queries. The history list is printed with command h. A previous query is invoked by typing its absolute number or its relative negative offset from the current query number (i.e. -1 will execute the previous query). The current query number is displayed in the toplevel prompt.

The history is initialized from the file .eclipse_history in the current directory or in the home directory. This file contains the history goals, each ended by a fullstop. The current history can be written using the predicate write_history/0 from the util library.


Getting Help

The contents of the ECLiPSe BIP book, i.e. the detailed descriptions of all built-in predicates, can be accessed with the help-facility. It has two modes of operation. First, when a fragment of a built-in name is specified, a list of short descriptions of all built-ins whose name contains the specified string is printed, .e.g.
:- help(write).
will print one-line descriptions about write/1, writeclause/2 etc. When a unique specification is given, the full description of the specified built-in is displayed, e.g. in
:- help(write/1).


Global Flags and Settings

ECLiPSe has a number of flags to control options and modes of operation. They will be described in detail in the appropriate places. To get an overview of the existing flags, call env/0 which will print a list like
[eclipse 1]: env.
all_dynamic:            off             last_errno:             0              
break_level:            0               macro_expansion:        on             
coroutine:              off             max_global_trail:       134217728      
debug_compile:          on              max_local_control:      134217728      
debugger_model:         eclipse         max_predicate_arity:    255            
debugging:              nodebug         object_suffix:          "so"           
dfid_compile:           off             occur_check:            off            
enable_interrupts:      on              output_mode:            "QPm"          
float_precision:        double          pid:                    21660          
gc:                     on              ppid:                   14029          
gc_interval:            1048576         prefer_rationals:       off            
gc_interval_dict:       960             print_depth:            20             
goal_expansion:         on              toplevel_module:        eclipse        
hostarch:               "sparc_sunos5"  unix_time:              919720465      
hostid:                 "9999999999"    version:                '4.1'          
hostname:               "breeze"        wm_window:              off            
ignore_eof:             off             worker:                 0              

cwd:                    "/homes/john/" 
extension:              development occur_check dfid 
installation_directory: "/usr/local/eclipse" 
library_path:           ["/usr/local/eclipse/lib", ...]
loaded_library:         lists pdb idb tracer_tty environment array
                        development_support tracer setof suspend sorts io 
prolog_suffix:          ["", ".sd", ".ecl", ".pl"] 
variable_names:         on 
workerids:              "breeze" : [0] + [] 
workers:                "breeze" : 1
The values of individual flags can be retrieved using get_flag/2. Some of these flags can be set using set_flag/2. The built-in statistics/0 displays various figures about time and memory usage. Refer to chapter 19 for details.


next up previous index
Next: More about compilation Up: Getting started with ECLiPSe Previous: The .eclipserc file   Index

1999-08-06