Minimal Prolog interpreter.
This is mostly a learning project to know more about F# and Prolog.
- The implementation is rather basic. It does not contain cuts, arithmetic, lists, equality and so on — only basic Horn clauses.
- Besides the interpreter, there's a simple hand-rolled parser combinator library. Zero dependencies, yay!
You pretty much need only .NET SDK 8.0.
Available options:
-f,--fileA file to load before starting a REPL.
Simply run the project:
$ dotnet run --project AttologWith arguments:
$ dotnet run --project Attolog -- -f examples/sw.plREPL can also be used with rlwrap:
$ rlwrap -a -N -t dumb dotnet run --project AttologWith arguments:
$ rlwrap -a -N -t dumb dotnet run --project Attolog -- -f examples/sw.plIf you have just installed, you can use the following recipes:
$ just --list
Available recipes:
default
rl *args='' # Run Attolog with rlwrap for a slightly better experience in REPL.
run *args='' # Run Attolog with the default REPL.Arguments can be passed as well:
$ just run -f examples/sw.plThe language currently consists of:
- Constants:
x,y,constant - Variables:
X,Y,Variable - Clauses:
son(abel, adam),less(X, plus(X, one)) - Assertions:
son(X, Y) :- male(X), child(X, Y). - Queries:
?- child(X, vader).
Sample program:
% Persons.
female(leia).
male(vader).
male(luke).
male(kylo).
% Relations.
child(luke, vader).
child(leia, vader).
child(kylo, leia).
% Assertions.
son(X, Y) :- male(X), child(X, Y).
daughter(X, Y) :- female(X), child(X, Y).
grandchild(X, Z) :- child(X, Y), child(Y, Z).
% Queries (goals) can't be part of a saved program.
% ?- son(X, vader).
% ?- daughter(X, vader).
% ?- grandchild(X, vader).Peano numbers (using terms to represent unary numbers, e.g. 0, s(0), s(s(0)), s(s(s(0))), etc.):
add(0, N, N).
add(s(N), M, s(R)) :- add(N, M, R).
% ?- add(s(0), s(0), X).
% X = s(s(0))
% ?- add(s(0), X, s(s(0))).
% X = s(0)- Get rid of exceptions, embrace errors as values.
- Refactor solver to produce values instead of effects (direct printing, reading input, etc).
MIT.