Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

cl-prolog

cl-prolog 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.

Quick start

(require :asdf)
(asdf:load-asd (truename "cl-prolog.asd")) ; run from the repository root
(asdf:load-system :cl-prolog)

(in-package #:cl-prolog)

(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.

Where to go next

Install

cl-prolog 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/takeokunn/cl-prolog.git
cd cl-prolog
sbcl --non-interactive \
  --eval '(require :asdf)' \
  --eval '(asdf:load-asd (truename "cl-prolog.asd"))' \
  --eval '(asdf:load-system :cl-prolog)'

To run the cl-weave regression suite through the Linux-only Nix app:

nix run github:takeokunn/cl-prolog