cl-prolog-kit¶
cl-prolog-kit is a small, dependency-free Prolog engine for Common Lisp, built
around three ideas:
- macro-first rule definition — clauses are data, macros own the syntax
- CPS proof search — the engine emits solutions through continuations; callers choose streaming or collection
- data / logic separation — rulebases are plain structs the engine walks
The public package is cl-prolog-kit. It implements a focused Prolog runtime rather
than mirroring every facility of a standalone ISO Prolog system.
Quick start¶
(require :asdf)
(asdf:load-asd (truename "cl-prolog-kit.asd")) ; run from the repository root
(asdf:load-system :cl-prolog-kit)
(in-package #:cl-prolog-kit)
(define-rulebase *family*
((parent tom bob))
((parent bob alice))
((ancestor ?x ?y) (parent ?x ?y))
((ancestor ?x ?y) (parent ?x ?z) (ancestor ?z ?y)))
(query-prolog *family* '(ancestor tom ?who))
;; => (((?WHO . BOB)) ((?WHO . ALICE)))
Facts are one-element clauses; rules are a head followed by body goals. Logic
variables are ?-prefixed symbols.
New here?
Start with Getting Started, then follow Your First Program to build a knowledge base step by step.
Explore the docs¶
-
Getting Started
Install the library, run your first query, and build a family tree.
-
Guide
Querying, the rule DSL, builtins, arithmetic, DCG grammars, and recipes.
-
Reference
The exported symbol index, proof semantics, conditions, and parser limits.
-
Internals & Project
The CPS engine's architecture, plus the test, benchmark, and release workflow.
Architecture · Call Graph Analysis · Benchmarks · Development
Feature highlights¶
- A macro-first DSL:
prolog,define-rulebase,extend-rulebase,def-rule, and:whenguards compiled to closures. - Streaming or collecting query APIs over one CPS core:
map-prolog-solutions,query-prolog,query-prolog-first,prolog-succeeds-p. - A broad builtin set — control and meta-call, collection and sorting, the
dynamic database, arithmetic, ISO string/atom predicates,
library(lists),library(apply), formatted output, and finite-domain constraints. - An SLG tabling engine with automatic left-recursion handling.
- DCG grammar rules and combinators.
- A transactional source loader for Prolog text with configurable parser resource limits.
- Foreign predicates via
define-foreign-predicateas the supported extension surface. - Call graph analysis (
cl-prolog-kit/callgraph) — Prolog-backed reachability, dead-code and mutual-recursion detection, and FD-constraint graph coloring over any caller/callee edge set. See Call Graph Analysis.
Install¶
cl-prolog-kit is not currently distributed by Quicklisp. Clone the repository and either load its ASDF definition directly or place the checkout in a directory configured in your ASDF source registry.
git clone https://github.com/nerima-lisp/cl-prolog-kit.git
cd cl-prolog-kit
sbcl --non-interactive \
--eval '(require :asdf)' \
--eval '(asdf:load-asd (truename "cl-prolog-kit.asd"))' \
--eval '(asdf:load-system :cl-prolog-kit)'
To run the cl-weave regression suite through the Nix app on x86_64-linux or
Apple Silicon (aarch64-darwin):
See Getting Started for the full matrix of load paths; use its ASDF instructions on other environments.
Project policy¶
Conduct, contribution, security and support policies are org-wide defaults, published once in the nerima-lisp/.github repository rather than copied into each of the 21 packages:
What is specific to this package lives here: Development for the workflow, Compatibility for what the public surface promises, and the releases for the per-entry history.