Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

scryer-prolog

> 编程语言
Open source

A modern Prolog implementation written mostly in Rust.

2.4K stars0 likes0 views
WebsiteGitHub

About

A modern Prolog implementation written mostly in Rust.

Scryer Prolog

Scryer Prolog aims to become to ISO Prolog what GHC is to Haskell: an open source industrial strength production environment that is also a testbed for bleeding edge research in logic and constraint programming, which is itself written in a high-level language.

Scryer Prolog passes all tests of syntactic conformity, variable_names/1 and dif/2.

The homepage of the project is: https://www.scryer.pl

Phase 1

Produce an implementation of the Warren Abstract Machine in Rust, done according to the progression of languages in Warren's Abstract Machine: A Tutorial Reconstruction.

Phase 1 has been completed in that Scryer Prolog implements in some form all of the WAM book, including lists, cuts, Debray allocation, first argument indexing, last call optimization and conjunctive queries.

Phase 2

Extend Scryer Prolog to include the following, among other features:

  • call/N as a built-in meta-predicate.
  • ISO Prolog compliant throw/catch.
  • Built-in and user-defined operators of all fixities, with custom associativity and precedence.
  • Bignum, rational number and floating point arithmetic.
  • Built-in control operators (,, ;, ->, etc.).
  • A revised, not-terrible module system.
  • Built-in predicates for list processing and top-level declarative control (setup_call_cleanup/3, call_with_inference_limit/3, etc.)
  • Default representation of strings as lists of characters, using a packed internal representation.
  • term_expansion/2 and goal_expansion/2.
  • Definite Clause Grammars.
  • Attributed variables using the SICStus Prolog interface and semantics. Adding coroutines like dif/2, freeze/2, etc. is straightforward with attributed variables.
    • Support for verify_attributes/3
    • Support for attribute_goals/2 and project_attributes/2
    • call_residue_vars/2
  • if_/3 and related predicates, following the developments of the paper "Indexing dif/2".
  • All-solutions predicates (findall/{3,4}, bagof/3, setof/3, forall/2).
  • Clause creation and destruction (asserta/1, assertz/1, retract/1, abolish/1) with logical update semantics.
  • Backtrackable and non-backtrackable global variables via bb_get/2 bb_put/2 (non-backtrackable) and bb_b_put/2 (backtrackable).
  • Delimited continuations based on reset/3, shift/1 (documented in "Delimited Continuations for Prolog").
  • Tabling library based on delimited continuations (documented in "Tabling as a Library with Delimited Control").
  • A redone representation of strings as difference lists of characters, using a packed internal representation.
  • clp(B) and clp(ℤ) as builtin libraries.
  • Streams and predicates for stream control.
    • A simple sockets library representing TCP connections as streams.
  • Incremental compilation and loading process, newly written, primarily in Prolog.
  • Improvements to the WAM compiler and heap representation:
    • Replacing choice points pivoting on inlined semi-deterministic predicates (atom, var, etc) with if/else ladders. (in progress)
    • Inlining all built-ins and system call instructions.
    • Greatly reducing the number of instructions used to compile disjunctives.
    • Storing short atoms to heap cells without writing them to the atom table.
  • Configurable JIT/on-demand indexing over all arguments (documented in "Demand-Driven Indexing of Prolog Clauses"). (in progress)
  • A compacting garbage collector satisfying the five properties of "Precise Garbage Collection in Prolog." (in progress)

Phase 3

Use the WAM code produced by the completed code generator to get JIT-compiled and -executed Prolog programs. The question of how to get assembly from WAM code is something I'm still considering.

It's my hope to use Scryer Prolog as the logic engine of a low level (and ideally, very fast) Shen implementation.

Nice to have features

There are no current plans to implement any of these, but they might be nice to have in the future. They'd make a good project for anyone wanting to contribute code to Scryer Prolog.

  1. Implement the global analysis techniques described in Peter van Roy's thesis, "Can Logic Programming Execute as Fast as Imperative Programming?"

  2. Add unum representation and arithmetic, using either an existing unum implementation or an ad hoc one. Unums are described in Gustafson's book "The End of Error."

  3. Add concurrent tables to manage shared references to atoms and strings.

Installing Scryer Prolog

Binaries

Precompiled binaries for several platforms are available for download at:

https://github.com/mthom/scryer-prolog/releases/latest

Native Compilation

First, install the latest stable version of Rust using your preferred method. Scryer tends to use features from newer Rust releases, whereas Rust packages in Linux distributions, Macports, etc. tend to lag behind. rustup will keep your Rust updated to the latest stable release; any existing Rust distribution should be uninstalled from your system before rustup is used.

[!NOTE] The minimum rust toolchain version required can be found in the Cargo.toml under the package.rust-version key. The accuracy of this value is validated in CI

From a local git checkout

$> git clone https://github.com/mthom/scryer-prolog
$> cd scryer-prolog
$> cargo build --release

The --release flag performs various optimizations, producing a faster executable.

After compilation, the executable scryer-prolog is available in the directory target/release and can be invoked to run the system.

Via cargo install

From git

cargo install --locked --git https://github.com/mthom/scryer-prolog.git

Afterwards the scryer-prolog binary will be in the $HOME/.cargo/bin directory which is usually added to your PATH during the installation of the rust toolchain.

From Crates.io

[!NOTE] The latest crates.io release can be significantly behind the version available in the git repository The crates.io badge in this sections title is a link to the crates.io page. The msrv badge in the section title references the minimum rust toolchain version required to compile the latest crates.io release

scryer-prolog is also release on crates.io and can be installed with

cargo install --locked scryer-prolog

Caveats for Windows

On Windows, Scryer Prolog is easier to build inside a MSYS2 environment as some crates may require native C compilation. However, the resulting binary does not need MSYS2 to run. When executing Scryer in a shell, it is recommended to use a more advanced shell than mintty (the default MSYS2 shell). The Windows Terminal works correctly.

To build a Windows Installer, you'll need first Scryer Prolog compiled in release mode, then, with WiX Toolset installed, execute:

candle.exe scryer-prolog.wxs
light.exe scryer-prolog.wixobj

It will generate a very basic MSI file which installs the main executable and a shortcut in the Start Menu. It can be installed with a double-click. To uninstall, go to the Control Panel and uninstall as usual.

Building WebAssembly

Scryer Prolog has basic WebAssembly support. You can follow wasm-pack's official instructions to install wasm-pack and build it in any way you like.

However, none of the default features are currently supported. The preferred way of disabling them is passing extra options to wasm-pack.

For example, if you want a minimal working package without using any bundler like webpack, you can do this:

wasm-pack build --target web -- --no-default-features

Then a pkg directory will be created, containing everything you need for a webapp. You can test whether the package is successfully built by creating an html file, adapted from wasm-bindgen's official example like this:

…

Then you can serve it with your favorite http server like python -m http.server or npx serve, and access the page with your browser.

Docker Install

Pre-built Docker images are available on Docker Hub. The latest tag reflects the state on master, which might be unstable. There are also tags for Scryer releases 0.9.2 and up. Note though, that the base images are not kept up to date at the moment, so be wary of security vulnerabilities (see #2646).

First, install Docker on Linux, Windows, or Mac.

Once Docker is installed, you can download and run Scryer Prolog with a single command:

$> docker run -it mjt128/scryer-prolog

To consult your Prolog files, bind mount your programs folder as a Docker volume:

$> docker run -v /home/user/prolog:/mnt -it mjt128/scryer-prolog
?- consult('/mnt/program.pl').
true.

This works on Windows too:

$> docker run -v C:\Users\\user\Documents\prolog:/mnt -it mjt128/scryer-prolog
?- consult('/mnt/program.pl').
true.

Tutorial

Prolog files are loaded by specifying them as arguments on the command line. For example, to load program.pl, use:

$> scryer-prolog program.pl

Loading a Prolog file is also called “consulting” it. The built-in predicate consult/1 can be used to consult a file from within Prolog:

?- consult('program.pl').

As an abbreviation for consult/1, you can specify a list of program files, given as atoms:

?- ['program.pl'].

The special notation [user] is used to read Prolog text from standard input. For example,

?- [user].
hello(declarative_world).
hello(pure_world).

Pressing RETURN followed by Ctrl-d stops reading from standard input and consults the entered Prolog text.

After a program is consulted, you can ask queries about the predicates it defines. For example, with the program shown above:

?- hello(What).
   What = declarative_world
;  What = pure_world.

Press SPACE to show further answers, if any exist. Press RETURN or . to abort the search and return to the toplevel prompt. Press f to see up to the next multiple of 5 answers, and a to see all answers. Press h to show a help message.

Use TAB to complete atoms and predicate names in queries. For instance, after consulting the program above, typing decl followed by TAB yields declarative_world. Press TAB repeatedly to cycle through alternative com

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustiso-prolog-standardprologprolog-implementationprolog-interpreter

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言