Minilog is a very small programming language implementation. It's goal is to capture the essence of logic programming.
For the implementation write up see: the write up.
It is very much a subset of Prolog, at least in terms of the syntax.
The biggest (intended) difference in terms of a runtime behaviour is the strict
occurs
checking.
Unlike Prolog, Minilog does not accept infinite terms.
This means that the following snippet will succeed in Prolog but not in Minilog:
X = foo(X).
As stated above, Minilog's syntax is a subset of the syntax of Prolog. In Minilog you have:
-
Atoms
foo
,z
-
Variables
X
,Y
-
Wildcards
_
-
Structs
foo(X, thing)
-
Facts
plus(z, N, N).
-
Rules
plus(s(N), M, s(R)) :- plus(N, M, R).
-
Conjunctions
times(N, M, R), plus(R, M, A).
-
Unification Operator
X = something
Here is an example of a valid Minilog knowledge base definition:
plus(z, N, N).
plus(s(N), M, s(R)) :- plus(N, M, R).
times(z, _, z).
times(s(N), M, A) :- times(N, M, R), plus(R, M, A).
fact(z, s(z)).
fact(s(N), R) :- fact(N, PR), times(s(N), PR, R).
And here is an example of a valid query:
?- fact(A, B) , plus(A,B, s(s(z))) .
- numbers
- arithmetics (obviously)
- strings
- explicit or (
;
) - cuts (
!
)
The implementation is just a complement of the write up. The goal of this project is to offer an introductory level almost tutorial-like description of an implementation of a simple abstract machine for a logic language.
The design of the implementation is not aming to represent a practical implementation of a logic programming language. It should not be considered more than an initial exposition to the ideas behind concepts like unification, proof search that happens during the evaluation and a backtracking in such a proof search.
You could also say that the design of the implementation was chosen to be observable by default. Indeed, as the runtime is implemented as a simple "stepping" interpreter, we can very much see "inside" the process. The write up goes into more detail on that topic.
The goal of the project is not to be a rigorous introduction into the matter! At best it should serve as a toy-like demonstration; similar to when a math or physics teacher reaches for a vast (but still valid) simplification to make some complicated sounding concept more approachable.
-
You run
cabal build
and if that succeededcabal run
. -
You can use the knowledge base in the repository, modify it, or use your own. It is loaded into the repl using a command
:load <path to the file>
like:load factorial.pl
. -
You write Prolog-like query and hit enter.
-
When presented with a result, you either write
:next
and hit enter (to backtrack) or you write:done
and hit enter to conclude the computation. -
When you want to quit the REPL, you submit
:q
or:Q
.