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:

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.

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:

  • consult - assumes the files are source files (.pro), but if an object file is specified it will load it correctly as well.
  • load - assumes the files are object files (.plm), and will fail if a source file is specified instead.
  • consult_project - consults or loads all the files in a project (.ppj)
  • reconsult_project - reconsults or loads all the files in a project (.ppj)
  • Examples: 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.

    Adding and Removing Clauses

    In addition to consulting files, clauses can be added to the dynamic database in a number of ways.

    assert

    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.

    Consulting user

    add

    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.

    Listing Clauses

    The listing predicates displays a listing of your clauses. It has a few forms.
  • listing - list all of the clauses in the dynamic database
  • listing(Name) - list all of the clauses of predicate Name. Note that this will display clauses of different arities that have the same name.
  • listing(Name/Arity) - list all of the clauses of Name/Arity
  • 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:

    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

    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:

    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:
  • consult_project, reconsult_project - to consult/load all the files in a project.
  • debug - to start the debugger.
  • See the respective sections for more details on each.

    Exiting

    The listener is exited in one of two ways:

    In each case the listener cleans house and then exits.

    Copyright ©1987-2000 Amzi! inc. All Rights Reserved.