Quickstart
Install relic, run a Datalog program, and import a table.
1. Install relic
Homebrew
With Homebrew installed, use the relic formula:
brew install stass/tap/relic
This installs the relic command, librelic, the
relic.h header and manual pages.
Build from source
A release tarball needs a C11 compiler, make and a POSIX shell.
Download and unpack a source tarball from GitHub Releases, then run these commands inside it.
This installs under your home directory without root access.
./configure --prefix="$HOME/.local"
make
make check
make install
export PATH="$HOME/.local/bin:$PATH"
Building from a Git checkout
Install Git, autoconf 2.69+, automake 1.13+ and libtool 2.4.2+ first. These extra build tools are needed only for the checkout.
git clone https://github.com/stass/relic.git
cd relic
./autogen.sh
./configure --prefix="$HOME/.local"
make
make check
make install
export PATH="$HOME/.local/bin:$PATH"
The only optional library is libedit, for REPL line editing.
Use --with-libedit=no to build without it.
2. Save a program
Save the following as impact.dl.
Facts describe direct dependencies; rules derive indirect ones.
depends(web, api).
depends(api, database).
depends(worker, api).
affected(App, Changed) :- depends(App, Changed).
affected(App, Changed) :-
depends(App, Middle), affected(Middle, Changed).
affected(App, database)?
3. Run it
$ relic -s impact.dl
api
web
worker
-s sorts the output. The query prints one column for each named variable.
Use -q to ask a different question instead of the queries in the file:
$ relic -s -q 'affected(App, api)?' impact.dl
web
worker
For interactive exploration, run relic -i impact.dl and enter
queries such as affected(web, What)?. Leave with Ctrl-D.
4. Read a table
Create edge.tsv with two tab-separated columns:
a b
b c
Save these rules as reach.dl:
path(X, Y) :- edge(X, Y).
path(X, Z) :- edge(X, Y), path(Y, Z).
path(a, X)?
-T sets column types; -I imports the table.
The filename supplies the predicate name and the format.
$ relic -s -T edge:symbol,symbol -I edge.tsv reach.dl
b
c
Use -F csv, -F tsv or -F json for
machine-readable answers. -o answers.tsv writes query output to a file;
-O path.tsv exports the whole path relation.
Further documentation
Continue with the language tutorial,
read the C API overview, or run man 1 relic
for the command-line reference.