Add example scripts

This commit is contained in:
Hassan Abedi 2026-03-10 12:48:25 +01:00
parent 8f8e63b2f7
commit e24876b8f5
5 changed files with 47 additions and 1 deletions

View File

@ -89,7 +89,7 @@ cargo run -- repl
cargo run -- gui cargo run -- gui
# Run a script file # Run a script file
cargo run -- script examples/session.chase cargo run -- script examples/scripts/ancestor.chase
``` ```
The REPL and GUI share a minimal command language: The REPL and GUI share a minimal command language:

View File

@ -0,0 +1,13 @@
# Example Scripts
These scripts can be executed with:
```bash
make script SCRIPT=examples/scripts/ancestor.chase
```
Available examples:
- `ancestor.chase`: transitive closure over `Parent/2`
- `employee_departments.chase`: existential rule that creates labeled nulls
- `same_team.chase`: conjunctive query with a self-join

View File

@ -0,0 +1,11 @@
# Derive ancestors from parent relationships.
fact Parent(alice, bob).
fact Parent(bob, carol).
fact Parent(carol, dave).
rule Parent(?X, ?Y) -> Ancestor(?X, ?Y).
rule Ancestor(?X, ?Y), Parent(?Y, ?Z) -> Ancestor(?X, ?Z).
run.
query Ancestor(?X, ?Y)?

View File

@ -0,0 +1,11 @@
# Existential rule example: each employee works in some department.
fact Employee(alice).
fact Employee(bob).
fact Employee(carol).
rule Employee(?X) -> WorksIn(?X, ?Dept).
run.
show facts
query WorksIn(?X, ?Dept)?

View File

@ -0,0 +1,11 @@
# Query people who share a manager.
fact ManagedBy(alice, eve).
fact ManagedBy(bob, eve).
fact ManagedBy(carol, frank).
rule ManagedBy(?X, ?M), ManagedBy(?Y, ?M) -> SameTeam(?X, ?Y).
run.
query SameTeam(?X, ?Y)?
query SameTeam(alice, bob)?