diff --git a/README.md b/README.md index 6a34c89..a6106ac 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ cargo run -- repl cargo run -- gui # 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: diff --git a/examples/scripts/README.md b/examples/scripts/README.md new file mode 100644 index 0000000..580863e --- /dev/null +++ b/examples/scripts/README.md @@ -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 diff --git a/examples/scripts/ancestor.chase b/examples/scripts/ancestor.chase new file mode 100644 index 0000000..79237c2 --- /dev/null +++ b/examples/scripts/ancestor.chase @@ -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)? diff --git a/examples/scripts/employee_departments.chase b/examples/scripts/employee_departments.chase new file mode 100644 index 0000000..16a85be --- /dev/null +++ b/examples/scripts/employee_departments.chase @@ -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)? diff --git a/examples/scripts/same_team.chase b/examples/scripts/same_team.chase new file mode 100644 index 0000000..b8e4606 --- /dev/null +++ b/examples/scripts/same_team.chase @@ -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)?