Hash :
d0286b85
Author :
Thomas de Grivel
Date :
2022-11-18T18:33:51
1.1 The world is the totality of facts, not of things.
– Ludwig Wittgenstein, Tractatus Logico Philosophicus
cl-facts is a small in-memory graph database for Common Lisp. It features :
You will need :
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 (?movie :actor "Harison Ford"))
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))
The current facts database.
Clears the database from every facts.
Dump the database facts into filespec INTO.
Load the facts from SRC into *db*.
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.
cl-facts
Copyright 2011-2022 Thomas de Grivel thodg@kmx.io
Permission is hereby granted to use this software granted the above copyright notice and this permission paragraph are included in all copies and substantial portions of this software.
THIS SOFTWARE IS PROVIDED “AS-IS” WITHOUT ANY GUARANTEE OF PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF THIS SOFTWARE.