Files
scryer-prolog/README.md
2017-05-09 16:26:17 -06:00

107 lines
2.1 KiB
Markdown

# rusty-wam
An implementation of the Warren Abstract Machine in Rust, done
according to the progression of languages in [Warren's Abstract
Machine: A Tutorial
Reconstruction](http://wambook.sourceforge.net/wambook.pdf), ending in
pure Prolog.
## Progress
Prolog is implemented as a simple REPL. It is without meta- or
extra-logical operators, or side effects of any kind, with the lone
exception of cut. In terms of the tutorial pacing, the work covers in
some form all of the WAM book, including lists, cuts, Debray
allocation, indexing, and conjunctive queries.
## Tutorial
To enter a multi-clause predicate, the brackets ":{" and "}:" are used
as delimiters. They must be contained entirely within their own lines.
For example,
```
prolog> :{
p(f(f(X)), h(W), Y) :- g(W), h(W), f(X).
p(X, Y, Z) :- h(Y), z(Z).
}:
prolog> :{
h(x).
h(y).
h(z).
}:
```
Single clause predicates can be entered without brackets, as in
```
prolog> p(X) :- q(X).
prolog> f(s).
prolog> z(Z).
```
Queries are issued as
```
prolog> ?- p(X, Y, Z).
```
Given the above work, the result of the query will be
```
prolog> ?- p(X, Y, Z).
true
Y = x
X = _0
Z = _2
```
Pressing ; will backtrack through other possible answers, if any exist.
Pressing . will abort the search and return to the prompt.
Wildcards work as well:
```
prolog> :{
member(X, [X|_]).
member(X, [_|Xs]) :- member(X, Xs).
}:
prolog> ?- member(X, [a, b, c]).
true
X = a ;
X = b ;
X = c ;
false.
```
and so do conjunctive queries:
```
prolog> ?- member([X,X],[a,b,c,[d,d],[e,d]]), member(X, [a,b,c,d,e,f,g]), member(Y, [X, a, b, c, d]).
true
Y = d
X = d ;
Y = a
X = d ;
Y = b
X = d ;
Y = c
X = d ;
Y = d
X = d ;
false.
prolog>
```
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` is an example in the
above).
## Occurs check
There's no occurs check, but there soon will be. Currently, attempting
unification on a cyclic term succeeds, and the attempt to write the
term to a string results in an infinite loop, ie.
```
prolog> p(W, W).
prolog> ?- p(f(f(W)), W).
true
*loops to infinity*
```