|new 0.8.86||Jun 14, 2019|
|0.8.85||May 25, 2019|
|0.8.77||Apr 30, 2019|
|0.8.33||Mar 31, 2019|
853 downloads per month
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.
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.
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 (
- A revised, not-terrible module system.
- Built-in predicates for list processing and top-level declarative
- Default representation of strings as list of chars, using a packed internal representation. - A representation of 'partial strings' as difference lists of characters.
- Definite Clause Grammars.
- Attributed variables using the SICStus Prolog interface and
semantics. Adding coroutines like
freeze/2, etc. is straightforward with attributed variables.
- Support for
- Support for
- Support for
if_and related predicates, following the developments of the paper "Indexing
- All-solutions predicates (
- Clause creation and destruction (
abolish/1) with logical update semantics.
- Backtrackable and non-backtrackable global variables via
- Streams and predicates for stream control (in progress).
- An incremental compacting garbage collector satisfying the five properties of "Precise Garbage Collection in Prolog."
- Mode declarations.
- Extensions for clp(FD).
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.
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.
Implement the global analysis techniques described in Peter van Roy's thesis, "Can Logic Programming Execute as Fast as Imperative Programming?"
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."
Add support for shift/reset delimited continuations, see "Delimited Continuations for Prolog."
Add concurrent tables to manage shared references to atoms and strings.
Add optional SLG resolution for fast memoization of predicates.
Add some form of JIT predicate indexing.
First, install the latest stable version of Rust using your preferred method. Then install the latest Scryer Prolog with cargo, like so:
$> cargo install scryer-prolog
cargo will download and install the libraries Scryer Prolog uses
automatically, save for the C library readline. The
readline_rs_compat crate on which Scryer depends (and which is built
and maintained by myself) will search the following library paths for
/lib /usr/lib /usr/local/lib /lib/x86_64-linux-gnu /opt/local/lib
If you'd like to disable readline (and the need for linking to it), install with the line
cargo install scryer-prolog --no-default-features
You can find the
scryer-prolog executable in
Note on compatibility: Scryer Prolog should work on Linux, Mac OS X, and BSD variants on which Rust runs. Windows support hinges on readline and Termion being fully functional in that environment, which to my knowledge is not currently the case.
The following predicates are built-in to Scryer.
- Arithmetic support:
- Comparison operators:
To enter a multi-clause predicate, the directive "[user]" is used.
?- [user]. (type Enter + Ctrl-D to terminate the stream when finished) p(f(f(X)), h(W), Y) :- g(W), h(W), f(X). p(X, Y, Z) :- h(Y), z(Z). ?- [user]. (type Enter + Ctrl-D to terminate the stream when finished) h(x). h(y). h(z).
In the example,
Enter + Ctrl-D is used to terminate the standard
input stream. The instructive message is always printed.
Queries are issued as
?- p(X, Y, Z).
SPACE will backtrack through other possible answers, if any exist.
. will abort the search and return to the prompt.
Wildcards work as well:
?- [user]. (type Enter + Ctrl-D to terminate the stream when finished) member(X, [X|_]). member(X, [_|Xs]) :- member(X, Xs). ?- member(X, [a, b, c]). true . X = a ; X = b ; X = c ; false.
and so do conjunctive queries:
?- [user]. (type Enter + Ctrl-D to terminate the stream when finished) f(X) :- g(X). g(x). g(y). g(z). h(call(f, X)). ?- h(X), X. true . X = call(f, x) ; X = call(f, y) ; X = call(f, z).
Note that the values of variables belonging to successful queries are
printed out, on one line each. Uninstantiated variables are denoted by
a number preceded by an underscore (
X = _0 in an example above).
To clear the database, type
To quit scryer-prolog, type
Scryper supports dynamic operators. Using the built-in arithmetic operators with the usual precedences,
?- write_canonical(-5 + 3 - (2 * 4) // 8). -(+(-(5), 3), //(*(2, 4), 8)) true.
New operators can be defined using the
Scryer has two specialized, non-ISO builtin predicates for handling so-called "partial strings". Partial strings imitate difference lists of characters, but are much more space efficient. This efficiency comes at the cost of full generality -- you cannot unify the tail variables of two distinct partial strings, because their buffers will always be distinct.
X is a free variable, the query
?- partial_string("abc", X), X = [a, b, c | Y], is_partial_string(X), is_partial_string(Y).
will succeed. Further, if
Y a free variable, unifying
another string, "def" in this case, produces the equations
X = [a, b, c, d, e, f], Y = [d, e, f].
Scryer has a simple predicate-based module system. It provides a
way to separate units of code into distinct namespaces, for both
predicates and operators. See the files
At the time of this writing, several control and list processing operators and predicates are hidden in their own modules that have not been exported to the toplevel. To export them, write
The [user] prompt can also be used to define modules inline at the REPL:
?- [user]. (type Enter + Ctrl-D to terminate the stream when finished) :- module(test, [local_member/2]). :- use_module(library(lists)). local_member(X, Xs) :- member(X, Xs).
use_module directives can be qualified by adding a list of imports:
?- use_module(library(lists), [member/2]).
use_module can be used to remove imports from the
toplevel by calling it with an empty import list.
(:)/2 operator resolves calls to predicates that might not be
imported to the current working namespace:
?- lists:member(X, Xs).