sī-Kanren, a microKanren implementation in Common Lisp, with disequality, numbero, symbolo and absento constraints
sī-Kanren is based on the 2013 Scheme Workshop paper by Jason Hemann and Dan Friedman. Other resources are available on the miniKanren website. It's written in "pure" and simple Common Lisp, without external libraries like pmatch, guard or things like that, nor record types or structs. The constraint store in fact, as a whole, has the form:
cs = '(((s) . c) (d) (t) (a))
where s
is the substitution, c
the counter, d
the disequality
store, t
the type store and a
the absento store.
For more information:
- Excellent survey paper on unification: Kevin Knight.
- Disunification papers: Hubert Comon , Pierre Lescanne.
- Combining Unification and Disunification Algorithms: Klaus U. Schulz.
- And, above all, the miniKanren uncourse series, by William Byrd!
sī-Kanren includes:
- core miniKanren (
fresh
,conde
,==
). =/=
constraint, and thus it's the first microKanren written in Common Lisp with this feature (at least, as far as I know).Symbolo
,numbero
andabsento
constraints, the latter in the restricted version, as per the paper A tutorial reconstruction of miniKanren with constraints Bharathi Ramana Joshi, William E. Byrd, where the first argument is required to be a symbol only.- Reification of all the logic queries variables
x x0...
in(run _ (x x0...)...)
. It looks like a trick of magic too beautiful to not include it. 🪄 - Interactive request of a solution/s, with
runi
. - Pretty formatting of the answer/s.
sī-Kanren is a library in Quicklisp. To load it, use:
(ql:quickload "si-kanren")
Usage1
Many examples can be found in the playground file.
-
Inspiration for a simple implementation in Common Lisp, from cl-microkanren.
-
Inspiration for the implementation of the disequality store, from microKanren-sagittarius.
-
The version of the nlet-tail macro (among others things), from Let Over Lambda, by Doug Hoyte (@hoytech).
-
And, of course, last but not least, many thank's to @webyrd for his sensational work!
As for the name, sī is the Chinese unit of measurement for 10 micrometers: since compared to microKanren sī-Kanren also contains the disequality store, plus the types and absento constraints, it seemed to me a fair way to give credit to this system. 😁 And since I think it can be pronounced like a c (more or less...), as in Common Lisp, the circle closes3.
Footnotes
-
Tested on SBCL v. 2.3.0 ↩
-
@alex-hhh Hope it's ok for you! Here's the CC BY-NC-SA 4.0 license link. ↩
-
Cit.: The Stand, Stephen King ↩