minikanren is a more modern streamlined kanren. The traditional implementation is interesting, but we implement the semantic differently using guile-log internals in stead. The basic implementation in minikanren is to construct a special trampolines that enables code to search the space of solutions in a breth first way. Also there is a logaritmic addition of clauses meaning that the first clauses in an or have higher rate of trying then the last one so that by ordering the most likely clauses first you get a higher hit ratio. Also in minikanren one maintains multiple stack datastructures and does a great degree of groveling in them in order to implement the needed features. Here we take anothre approach and use attributes instead. In all we reproduce the sematics of minikanren but with a completely different appoach that mix well with the rest of guile-log. The minikanren primitives is also used to enable those in guile-prolog and a few operators is defined that enable the minikanren features in prolog programs.
To use this library reference
(logic guile-log minikanren).
The method of the api is to combine functions and finally evaluate the result yielding the logic program. A minikanren goal
mk-goal can be executed in guile log as
(mk-goal) and you can construct a minikanren goal directly by wrapping it in
(<lambda> () ...).
mk-goal (conde (mk-goal ....) ...), This will produce a minkanren goal from ’or’-ing a sequence ao ’and’-ing. This construct will do breath first like search and is safe from producing unwanted infinite searches.
mk-goal (conda (mk-goal ....) ...), This will produce a minkanren goal from ’or’-ing a sequence of ’and’-ing. The first value will produce only one value.
mk-goal (condu (mk-goal ....) ...), This will produce a minkanren goal from ’or’-ing a sequence of ’and’-ing. As
conda, but the whole ideom will produce only one solution.
mk-goal (once mk-goal), Makes a goal that take only one solution from the goal
mk-goal (fresh (v1 ...) mk-goal ...), this will bind a set of variables
v1 ... and then execute the minikanren goals according to an
and in a safe way regarding unwanted infinities in the search
mk-goal (== a b), will unify scheme object
a with scheme object
mk-goal (=/= a b), will put a non equal constraint on the scheme objects
mk-goal (symbolo a), Constrain
a to be a scheme symbol.
mk-goal (numbero a), Constrain
a to be a scheme number.
mk-goal (booleano a), Constrain
a to be a scheme boolean.
mk-goal (absento a b), Constrain
a to not be included in the
b datastructure consisting og atoms and conses.
mk-goal (project (v ...) mk-goal ..., This will walk all
v ... values and then execute the goals
mk-goal ... inside
and. This ideom is safe for infinites in the searching.
scm (run n (v ...) mk-goal ...), execute a list of mk-goals,
mk-goal ... inside an
and in a infinite searching safe way using logical variables
v .... A list of list of variable values of no more than
n solution(s) results.
scm (run* (v ...) mk-goal ..., the same as
run, but with no limit on the number of solutions, my stall.