A practical introduction to relational programming in Turmeric using a small, runnable example project in examples/minikanren.
Note: This guide uses a miniKanren-style approach (relations + bidirectional queries) implemented directly in Turmeric while full stdlib miniKanren support is still being built.
The example models a tiny family-graph relation and demonstrates:
parento relation (parent, child)grandparento relation composed from parentoCode location:
examples/minikanren/src/main.turFrom the repository root:
cmake -S . -B build
cmake --build build -j --target minikanren
./build/examples/minikanren/minikanren
The example encodes people as integer IDs and converts IDs to names with person-name.
parento acts like a relation predicate:
1 when a (parent, child) pair is true0 otherwiseThis mirrors the "goal succeeds/fails" shape used in miniKanren.
grandparento is defined in terms of parento:
mid)parento(grand, mid) and parento(mid, child) both holdThis demonstrates relational composition (building larger relations from smaller ones).
The example includes:
query-parents-of childquery-children-of parentquery-grandparents-of childprint-all-parent-facts (enumerates all matching pairs)Although the implementation is explicit loops, the usage pattern matches miniKanren thinking: ask the same relation in different directions.
miniKanren-style relational example
----------------------------------
Parents of:
bart
homer
marge
Children of:
homer
bart
lisa
Grandparents of:
bart
abe
mona
After this tutorial, extend the example toward core miniKanren operators:
LVAR, SYM, PAIR, NIL)=, ==)fresh, conde, and run combinatorsFor the full roadmap, see:
docs/minikanren-plan.md