In-memory graph database for Common Lisp
Common Lisp
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
.gitignore
README.md
anon.lisp
database.lisp
fact.lisp
facts.asd
index.lisp
meta.lisp
mop.lisp
package.lisp
serialize.lisp
skip-list.lisp
spec.lisp
test.lisp
transaction.lisp
usl.lisp
with.lisp

README.md

Facts

1.1 The world is the totality of facts, not of things.

-- Ludwig Wittgenstein, Tractatus Logico Philosophicus

Facts is a small in-memory graph database for Common Lisp. It features :

  • a triple store based on unlabelled skip lists
  • a very simple query language (facts:with)
  • transactions using rollback functions
  • logging and replay of transactions to/from disk
  • dumping and loading the database to/from disk

Requirements

You will need :

Usage

FACTS:ADD &rest SPECS

Adds facts (triples) to the database. Triples can be grouped by subject.

(facts:add ("Blade Runner" :is-a :movie
                           :director "Ridley Scott"
                           :actor "Harison Ford"
                           :actor "Rutger Hauer")
           ("Snow White" :is-a :movie
	   	  	 :director "William Cottrell"
			 :director "David Hand"))
(facts:add (?movie :is-a :movie
                   :title "Blade Runner"
                   :director "Ridley Scott"
                   :actor "Harrison Ford"
                   :actor "Rutger Hauer"))

(facts:add (?movie :is-a :movie
	   	   :title "Snow White and the Seven Dwarfs"
	   	   :director "William Cottrell"
		   :director "David Hand"))

The second version with ?movie will generate an anonymous symbol prefixed with movie-. It is considered a more clean and efficient way to abstract identifiers.

FACTS:RM &rest SPECS

(facts:rm (?movie :actor "Harison Ford"))

FACTS:WITH SPECS &body BODY

To follow Wittgenstein's view of the world, all queries get turned into testing the presence or absence of triples (facts).

(defun movie-title (movie)
  (facts:with ((?movie :is-a :movie
    	               :title ?title))
    (return ?title)))

is equivalent to

(defun movie-title (movie)
  (facts:with ((?movie :is-a :movie)
  	       (?movie :title ?title))
    (return ?title)))

which is itself equivalent to

(defun movie-title (movie)
  (facts:with ((?movie :is-a :movie))
    (facts:with ((?movie :title ?title))
      (return ?title))))

Multiple queries on the same subject can be grouped together easily :

(facts:with ((?movie :is-a :movie
	    	     :title ?title
	    	     :director ?director))
  (format t "~A directed ~A~%" ?director ?title))

FACTS:*DB*

The current facts database.

FACTS:CLEAR-DB

Clears the database from every facts.

FACTS:SAVE-DB &key INTO (READABLY T)

Dump the database facts into filespec INTO.

FACTS:LOAD-DB SRC

Load the facts from SRC into *db*.

FACTS:WITH-TRANSACTION &body BODY

Enclose BODY database operations into a transaction.

A transaction ensures that all database operations will succeed or be reverted using their respective rollback functions.

Transactions can be nested safely.

Examples