LinuxCommandLibrary

swipl

Run and interpret Prolog programs

TLDR

Start an interactive session

$ swipl
copy

Execute a command without showing any output
$ swipl --quiet -t "[command]"
copy

Execute a script
$ swipl [path/to/file.pl]
copy

Print all shell configuration variables
$ swipl --dump-runtime-variables
copy

Display version
$ swipl --version
copy

SYNOPSIS

swipl [options] [scriptfile] [argument ...]

PARAMETERS

-s <file>
    Loads the specified Prolog source file into the environment. If no other goal is specified, the system enters the interactive top-level.

-g <goal>
    Executes the specified Prolog goal immediately after loading any specified files. This is often used for non-interactive execution, exiting after the goal succeeds or fails.

-t <goal>
    Sets the top-level goal that is executed when the system is ready to accept user input. The default is prolog, which starts the interactive prompt.

-q
    Runs in quiet mode, suppressing the initial welcome banner and other informational messages during startup.

--non-interactive
    Prevents the system from entering the interactive top-level after execution. The interpreter exits after the specified goal completes or fails, making it ideal for scripting.

--help
    Displays a brief summary of command-line options and usage information.

--version
    Shows the SWI-Prolog version number, copyright information, and build details.

DESCRIPTION

swipl invokes the SWI-Prolog interpreter, a comprehensive and widely used Prolog implementation. Prolog is a general-purpose logic programming language often associated with artificial intelligence, knowledge representation, and computational linguistics. The command provides an interactive top-level environment (REPL) for developing and running Prolog programs. It supports a rich set of built-in predicates, modules, threads, and interfaces to other languages like C and Java. Users can load Prolog source files, query the knowledge base, and debug programs directly from the command line. It also allows for executing scripts in non-interactive mode, making it suitable for scripting and deploying Prolog applications.

CAVEATS

SWI-Prolog, while powerful, can sometimes be resource-intensive for very large knowledge bases or complex computations due to its garbage collection and memory management. Debugging complex Prolog programs can have a steep learning curve, requiring familiarity with the execution model and effective use of the trace debugger. Path handling for modules and files can sometimes be tricky due to Prolog's module search paths.

INTERACTIVE TOP-LEVEL

When invoked without arguments, swipl starts an interactive shell where users can enter queries, load files, and debug programs directly. Queries are terminated with a period ('.') followed by Enter, and results (variable bindings) are displayed immediately.

CREATING EXECUTABLES (SAVED STATES)

SWI-Prolog can create 'saved states' or standalone executables using predicates like qsave_program/1 or qsave_program/2. These executables bundle a Prolog program and its required libraries into a single file, allowing for easy distribution and deployment without requiring a full SWI-Prolog installation.

HISTORY

SWI-Prolog was initially developed in 1987 by Jan Wielemaker at the University of Amsterdam (UvA). Its name originally stood for "Socrates Workbench" Prolog, referencing an early expert system shell. Over decades, it has evolved into a robust, feature-rich, and highly portable Prolog system, widely adopted in both academic and industrial settings due to its comprehensive library, extensibility, and active community support. It continues to be actively developed and maintained.

SEE ALSO

gprolog(1), yap(1), rlwrap(1)

Copied to clipboard