Listener
Alis is the Prolog listener, which contains the classic "?-"
Prolog listener used to run interpreted Prolog code, as described in Clocksin
& Mellish. Alis is a superset of the classic listener as it can also load
and run Prolog object modules (.plm files). This allows you to intermix compiled
and interpreted code in the listener, making it easy to work on a piece of an
application at a time.
The listener is available from both command-line and windowing environments.
Running in the
IDE
To invoke the Prolog listener from the Windows-IDE,
press the LIS button or select Listener / Start.
Running from the
Command-Line
To start the listener from the command
line, type:
c> alis
Amzi! Prolog Listener
Copyright (c) 1987-2000 Amzi! inc. All Rights Reserved.
Type 'quit.' to exit
?-
Consulting
Files
You can optionally
specify a list of files on the operating system command line. These files
are consulted as Prolog loads, then the predicate
main/0 is called, if it exists. If the files do NOT contain a main/0
predicate, this is equivalent to having consulted the files at the ?- prompt
(i.e., the code files are loaded, but are not executed).
The files are loaded in the order in which they are listed. The filenames
(which may be arbitrary pathnames complete with drive and sub-directory
specifiers) must be separated from each other by at least one space. If
there is no extension specified for a file, and there is no file with the
non-extended name, then the extension .pro is assumed.
The files specified can be Prolog source files (.pro), compiled Prolog
object files (.plm) or a combination thereof.
c> alis duck1 duck2.plm
c> alis b:\mydir\myapp1.plm
Executing
main/0
If the files consulted on the
command line do contain a main/0, then alis simply calls main/0
and exits if it succeeds. If main/0 fails, then the listener is
started up.
Loading Prolog
Code
Both source and object files can
be loaded into the listener. In the Windows-IDE, Listener / Consult can
be used to load source, object and project files.
In alis and the IDE, four built-in predicates provide this service:
Examples:
?- consult([duck1, duck2]). % consults both .pro Files.
yes
?- load([duck1, duck2]). % loads both .plm files.
yes
?- consult([duck1, 'duck2.plm']).
% consults one, loads the other.
yes
Consult can also be specified by simply giving a list as the goal at the
prompt. In other words, if you specify just a list, the listener assumes
you want to consult those files.
?- ['duck1.plm'].
yes
Adding and
Removing Clauses
In addition to consulting files, clauses can be
added to the dynamic database in a number of ways.
assert
?- assert( likes(ella, crackers) ).
yes
Typing in a Rule
A term with a neck symbol, ":-", is a rule. If the
rule has no body, then use the body true to ensure the clause is added.
?- likes(ella, pizza) :- true.
Term asserted
Consulting user
?- consult(user).
| likes(leona, lettuce).
| likes(leona, pool).
| quit.
yes
add
?- add.
| likes(basil, carrots).
| likes(basil, hay).
| % [Ctrl-Z] key pressed
yes
Clauses can be replaced by using replace, just like add. The only
difference is the old clauses for the predicate are removed first, and
replaced with the new ones.
Removing Clauses
Once in the dynamic database, clauses can be removed
with any of the built-in predicates that provide that service, such as
retract and abolish. See the Prolog Database
section for details.
?- retractall( likes(basil, X) ).
yes
Listing Clauses
The listing
predicates displays a listing of your clauses. It has a few forms.
The listing is displayed using the built-in predicate pp/1,
the "pretty printer." You can define your own pretty printer and call it
user_pp/1. If so, listing and other built-in
predicates will use your pretty printer.
Variable names are not preserved when clauses are asserted to the dynamic
database, so listing generates new names for the variables as it
displays. The names are of the form _n where n is an integer.
Proving Goals
At the listener prompt "?-" You may
enter any Prolog goal, including compound conjunctions of goals, separated
by ",", and disjunctions, separated by ";".
The listener attempts to prove the goal, returning values of any variables.
A ";" requests more solutions. Pressing [Enter] means you've seen enough.
Examples:
?- likes(ella, X).
X = crackers ;
X = pizza ;
no
?- likes(X, Y).
X = ella
Y = crackers ;
X = ella
Y = pizza % [Enter] key pressed
yes
?- likes(X, A), likes(X, B), A \= B.
X = ella
A = crackers
B = pizza ;
X = leona
A = lettuce
B = pool ;
no
If the value of a variable is undefined, then the internal notation for
the variable is displayed. It is of the form Hn, where n is an integer.
For example
?- X = foo(A,B,A).
X = foo(H8,H9,H8)
A = H8
B = H9
Syntax Errors
If you
enter a clause or goal that is unreadable by Prolog then the error handler
is entered.
Note that
the listener ?- prompt does not support a full line editor. You can type
in queries and correct them with the backspace key. In the IDE you can
cut and paste to create a new query, but you can only edit it with the
backspace key.
The error message in this case will indicate some kind of parsing error
(parsing is the act of reading Prolog and checking to see if it
can be understood). For "read" errors, the text of the term just read in
is displayed along with an indication of where Prolog thinks the error
lies.
Note that
in the case of an error in mismatched delimiters, such as quotes or parenthesis,
the error might have occurred many lines before the point the reader failed.
When an error occurs you will get a message similar to the following:
?- name(78, X).
Execution Error 401:
Argument type error: arg1 must be an atom or variable
While executing: name/2
Call Stack (approximate)
...
Other Command-Line
Services
Some goals built into the listener
are designed just to provide useful service to the command-line alis user.
These are:
See the respective sections for more details on each.
Exiting
The listener is exited in one of two ways:
-
quit. typed in response to the ?- prompt.
-
any attempt to prove the halt predicate.
In each case the listener cleans house and then exits.
Copyright ©1987-2000 Amzi! inc. All Rights Reserved.