SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


The Prolog Console

The Prolog Console View lets you

  • Control Prolog processes
  • Query Prolog predicates
  • Generate load files
  • Run the debugger, profiler and other SWI-Prolog tools
  • Use some special editing features
  • Jump to error lines in editors

Prolog Console

Processes

The Prolog Console offers a unified entry point for interacting with different Prolog processes. The name of the current Prolog process is always displayed in the top left corner of the Console. If no current Prolog Process is selected, the process selector (first button in the Prolog Console's toolbar) displays a yellow warning triangle:

Console with current Prolog Process Console without current Prolog Process
Console with current Prolog Process Console without current Prolog Process

With the Process Control Buttons buttons in the toolbar of the Prolog Console you can:

  • Switch process Select the current Prolog process.
  • New process Start a new Prolog process and name it as you like. If you open the drop down menu you will see a list of all defined configurations for Prolog processes.

    Selecting a configuration in this list will start a new process using the selected configuration. The default configuration is emphasized with an icon. If you use the button and not the drop down menu to start a process, this process will use the default configuration.
  • Restart process Restart the current process, reconsulting all currently consulted files after the restart. All active breakpoints will be preserved. WARNING: All non-persistent information (in particular, dynamically modified clauses) will be lost after restart :!: The automatical reconsult can be disabled in the preferences.
  • Stop process Stop and Remove (kill) the current process. WARNING: The whole information of this process (breakpoints, dynamic facts, etc) will be lost after this action :!: If there is a “Default Console” the Console View will switch to this.

Restarting a process

If you want to restart a process there are three possible ways to handle the reconsulting of files.

  • no reconsult: no additional files will be consulted, you have to consult everything manually
  • reconsult entry points: of all the currently consulted files, only those which are marked as entry points will be reconsulted. This is the default behaviour.
  • reconsult all files: all files which are currentyl consulted will be reconsulted

Queries and Results

A query is typed at the Console's prompt and terminated with a full-stop ('.'). Hitting <enter> after the full stop issues the query to the Prolog system and displays the results (if any). If there are multiple resultes, the Console background will turn yellow to indicate that the Console is waiting for user directives as whether to continue or terminate the query. Typing semicolon(';') or simply hitting the space bar displays the next result or 'false', if there are no more results. Hitting <enter> or typing 'a' aborts the query.

Backtracking in the console

Tracing or Aborting Long Running Queries

If you started a query that does not seem to stop you can try one of the following:

  • Pause the query and continue it under the control of the GUI tracer to see what is happening behind the scenes.
  • Abort the query

To trace a query from the very start, just prepend “trace, ” to your query (e.g. type “trace, p(X,Y).”). This will open by default the GUI tracer.

On Windows windows opened from the console sometimes start in iconified mode. So if your tracer, profiler, process monitor, etc. do not appear, check the bar at the bottom of the screen for new Prolog Process icons.

Auto-Completion

The Prolog Console supports code completion using the key binding <Ctrl><Space> or <TAB>. The following elements are shown in the completion:

  • Predicates (, ): all matching predicates that are visible in ::user::.
    • if the prefix is qualified with a module, all matching predicates visible in the qualifying module are listed.
    • if a documentation of a predicate is availabe, it is shown in the right window.
    • the icon shows the visibility of the predicate.
    • the text inserted as completion depends on the key mask when accepting a proposal:
      • no key mask: a predicate head is inserted. if a documentation is available, the argument names defined in the documentation will be used as variables for the inserted head.
      • ctrl: a predicate indicator (::functor:: : ::arity::) is inserted.
      • shift: a predicate name is inserted.
  • modules (): all matching modules.
  • atoms (): all matching atoms currently known in the prolog system.

the following table shows some examples for the completion (click on the images to enlarge).

predicates modules and atoms
Code completion in the Prolog Console Code completion in the Prolog Console

Console History

The Prolog Console View supports a history mechanism (see keyboard shortcuts).

Loadfile Creation

If you manually consulted multiple files into a Prolog process you can click the button on the right-hand-side of the Console's toolbar to create a file that will load all manually consulted files. Of course, you can edit it manually afterwards. Load file creation is handy if you want to consult the same set of files in a different process or after restarting Eclipse. It avoids errors otherwise caused by forgetting to (re)load certain recently created files.

Generate load file

By default, the created load file will be marked as an entry point.

SWI-Prolog Tools

If you click the arrow on the right side of the toolbar you can use some of the graphical tools of SWI-Prolog:

Menu for starting graphical tools of SWI-Prolog

  • Activates and deactivates the SWI-Prolog GUI tracer (activated by default): If active, show graphical trace information at source level. If deactivated, sue console tracing.
  • SWI-Prolog thread monitor: Open a graphical window showing Prolog threads and their status.
  • SWI-Prolog debug message monitor: Open a graphical overview of current 'debug topics' and shows accumulated debug messages for each topic.

Context Menu

In addition to the usual editing operations (Select All, Copy, Cut, Paste) the context menu of the Prolog Console lets you paste the complete path of the file that is open in the currently active Prolog Editor. This is very helpful if you want to set breakpoints manually, for example.

Open Search Dialog from Console

Sometimes you find a predicate name in the console and you want to use it in a search query. This happens for example if you have some undefined predicate and you want to find all references to it. For this you can mark the predicate name in the console and select “Open Search Dialog” from the context menu. The Prolog Search dialog will be opened and it will get the current selection of the console as input.

Open Search Dialog from Console Search Dialog
The highlighted text… …is the input for the search dialog.

Go to error location

SWI-Prolog reports warnings and errors while consulting a file. If the location is given, the prolog console links the message to the location, where the problem occurs.

A click on the linked error message … … opens an editor at the blamed line

Colored Output

  • Colored output is triggered by special keywords at the beginnig of each line: "***", “INFO:” , “WARNING:” , “ERROR:”, “DEBUG:”. The keywords are case-insensitive.
  • Each line indented with tabs or (at least) two spaces is colored like the preceeding line.
  • By default, "***" is treated like “INFO:”. Defaults can be overridden and output color can be (de)activated in the PDT preferences.
Colored console output Related predicate definition

Console Preferences

The Prolog Console appearance can be configured in the PDT Preferences:

research/pdt/docs/console.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024