Skip to content

V0.3.0/refactor - #114

Merged
thanos merged 3 commits into
mainfrom
v0.3.0/refactor
Jun 19, 2026
Merged

V0.3.0/refactor#114
thanos merged 3 commits into
mainfrom
v0.3.0/refactor

Conversation

@thanos

@thanos thanos commented Jun 19, 2026

Copy link
Copy Markdown
Owner

No description provided.

thanos added 3 commits June 19, 2026 19:43
  - closed #109
  - closed #110
  - closed #111

Add ergonomic shorthand notation for constructing Datalog rules, avoiding
the verbose Rule.new/Atom.new/Term.var ceremony. This introduces the
Prolog-inspired convention where uppercase atoms become variables,
:_ becomes a wildcard, and lowercase atoms/other values become constants.

New APIs:

- Program.add_rule/3,4 — accept {relation, [terms]} tuples for heads,
  {:positive/negative, {relation, [terms]}} for body literals, and
  {:op, args...} tuples for constraints
- Term.from/1 — convert shorthand values to Term.t()
- Atom.from_tuple/1 — construct Atom from {"rel", [terms]} tuple
- Constraint.from_tuple/1 — construct Constraint from operator tuples
  ({:neq, :A, :B}, {:add, :X, :Y, :Z}, {:is_integer, :V}, etc.)

Before:
  Program.add_rule(program,
    Rule.new(
      Atom.new("ancestor", [Term.var("X"), Term.var("Y")]),
      [{:positive, Atom.new("parent", [Term.var("X"), Term.var("Y")])}]
    )
  )

After:
  Program.add_rule(program,
    {"ancestor", [:X, :Y]},
    [{:positive, {"parent", [:X, :Y]}}]
  )

Constraint shorthand examples:
  {:neq, :A, :C}          → Constraint.neq(Term.var("A"), Term.var("C"))
  {:gt, :S, 100_000}      → Constraint.gt(Term.var("S"), Term.const(100_000))
  {:add, :Balance, :Limit, :Total}
  {:is_integer, :V}        → Constraint.type_integer(Term.var("V"))
  {:starts_with, :E, "admin."}
  {:member, :Dept, [:engineering, :infra]}

The struct-based Program.add_rule/2 with Rule.new remains available for
full control over term types. Both forms can be mixed in the same program.

Updates across codebase:
- All livebook examples (quickstart.livemd, examples.livemd, examples.exs)
  converted to shorthand notation
- README Quick Start updated to showcase shorthand
- Program moduledoc rewritten with shorthand examples
- CHANGELOG.md updated with [Unreleased] section
- Roadmap updated: v0.3.0 = shorthand, v0.4.0 = Sigil DSL (bumped from v0.3)
- 38 new tests for Term.from/1, Atom.from_tuple/1,
  Constraint.from_tuple/1, and Program.add_rule/3,4 shorthand

All 639 tests pass. Credo --strict clean. Dialyzer clean.
mix docs --warnings-as-errors clean.
- mix.exs: version bumped 0.2.0 → 0.3.0
- mix.exs: livebooks added to extras for Hex docs
- README.md: dependency ~> 0.3.0, livebook links in Documentation section, roadmap updated with rename note
- CHANGELOG.md: [Unreleased] → [0.3.0] - 2025-06-19, added ### Changed section documenting Result → Knowledge, query → materialize, telemetry renames, error passthrough
@thanos
thanos merged commit 4d99958 into main Jun 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant