a silly little programming language inspired by datalog.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
Gil Mizrahi 94017f5113 update to stackage lts 17 8 miesięcy temu
app Adding CSV support 10 miesięcy temu
src/Language adding the if function 10 miesięcy temu
test adding the if function 10 miesięcy temu
.dir-locals.el Adding dante's .dir-locals.el 10 miesięcy temu
.gitignore repl with repline 11 miesięcy temu
.gitlab-ci.yml Adding .gitlab-ci.yml 10 miesięcy temu
LICENSE Add facts to knowledge 1 rok temu
Makefile update to stackage lts 17 8 miesięcy temu
README.org Pass functions as arguments + afold, product 10 miesięcy temu
logi.cabal Adding CSV support 10 miesięcy temu
package.yaml Adding CSV support 10 miesięcy temu
stack.yaml update to stackage lts 17 8 miesięcy temu

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.