EvgSkv / logica

Logica is a logic programming language that compiles to SQL. It runs on Google BigQuery, PostgreSQL and SQLite.

Home Page:https://logica.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python eDSL

munro opened this issue Β· comments

It would be really nice if there was a Python eDSL so that I could write queries in Python, which I have much better tooling for. πŸ˜„

perhaps something like this πŸ₯²

import logica as lg
from logica import var, rule

# Define natural numbers from 1 to 29.
N = rule("N", var.x).body(
    var.x.in_(lg.range(30))
)

# Define primes.
Prime = rule("Prime", prime=var.x).body(
    N(var.x),
    var.x > 1,
    lg.not_(
        N(var.y),
        var.y > 1,
        var.y != var.x,
        var.x % var.y == 0
    )
)
# Define natural numbers from 1 to 29.
N(x) :- x in Range(30);
# Define primes.
Prime(prime: x) :-
  N(x),
  x > 1,
  ~(
    N(y),
    y > 1,
    y != x,
    x % y == 0
  );