a silly little programming language inspired by datalog.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Gil Mizrahi 94017f5113 update to stackage lts 17 il y a 10 mois
app Adding CSV support il y a 11 mois
src/Language adding the if function il y a 11 mois
test adding the if function il y a 11 mois
.dir-locals.el Adding dante's .dir-locals.el il y a 11 mois
.gitignore repl with repline il y a 1 an
.gitlab-ci.yml Adding .gitlab-ci.yml il y a 11 mois
LICENSE Add facts to knowledge il y a 1 an
Makefile update to stackage lts 17 il y a 10 mois
README.org Pass functions as arguments + afold, product il y a 11 mois
logi.cabal Adding CSV support il y a 11 mois
package.yaml Adding CSV support il y a 11 mois
stack.yaml update to stackage lts 17 il y a 10 mois

README.org

logi

A silly half-baked implementation of a logic programming language heavily inspired by datalog.

Have fun with it but don't use it for anything important please :)

Might go well with simple-file-db

Build

Download Stack

stack build

Run REPL with:

stack run

Simple Examples

Ancestor

> parent({parent='john', child='william'}).
Ok.
> parent({parent='william', child='ruth'}).
Ok.
> ancestor({ancestor=$X, offspring=$Y}) := parent({parent=$X, child=$Y}).
Ok.
> ancestor({ancestor=$X, offspring=$Z}) := parent({parent=$X, child=$Y}), ancestor({ancestor=$Y, offspring=$Z}).
Ok.
> ancestor($x)?
ancestor({ancestor = 'john', offspring = 'ruth'})
ancestor({ancestor = 'john', offspring = 'william'})
ancestor({ancestor = 'william', offspring = 'ruth'})

Negative Join

> a(1).
Ok.
> a(2).
Ok.
> b(1).
Ok.
> b(3).
Ok.
> c({a=$a, b=$b}) := a($a), b($b), @not(@equals($a, $b)).
Ok.
> c($x)?
c({a = 1, b = 3})
c({a = 2, b = 1})
c({a = 2, b = 3})

Iterate

> a(1).
Ok.
> a(@sum($x,1)) := a($x), @lesser($x, 10).
Ok.
> a($x)?
a(1)
a(2)
a(3)
a(4)
a(5)
a(6)
a(7)
a(8)
a(9)
a(10)

Aggregates

(Carrying on with the a from before)

> @asum(!a)
55
> @aavg(!a)
11/2
> @afold(&product, 1, !a)
3628800

Filter by Label

> product({ name = 'book', price = 17 }).
Ok.
> product({ name = 'shirt', price = 700 }).
Ok.
> expensive($x) := product($x), @greater($x.price, 100).
Ok.
> expensive($x)?
expensive({name = 'shirt', price = 700})

User Defined Functions

> function between(low,n,high) = @and(@lesser($low,$n), @greater($high, $n)).
Ok.
> a(1).
Ok.
> a(@sum($x,1)) := a($x), @lesser($x, 10).
Ok.
> b($x) := a($x), @between(3, $x, 7).
Ok.
> b($x)?
b(4)
b(5)
b(6)
> function app(f,n) = @$f($n,1,2).
Ok.
> @app(&sum, 10)
13
> @app(&product, 10)
20

EDSL

Logi can also be used as an EDSL.

Check out the EDSL module for documentation and the EDSL test module for examples.