Welcome to the study of UnifyWeaver! This document series will guide you through the theory, architecture, and practical application of this unique and powerful tool.
At its heart, UnifyWeaver is a Prolog-to-Bash compiler.
That statement, while accurate, requires some unpacking. UnifyWeaver uses the logic programming language Prolog as a high-level, declarative language to define data relationships, rules, and queries. It then compiles these definitions into highly efficient, stream-based Bash scripts, where possible and otherwise uses specialized recursion patterns.
Think of it as a bridge between two very different worlds:
UnifyWeaver’s specialty is compiling complex data relationships, especially recursive ones (like finding all ancestors in a family tree or all reachable nodes in a network), into Bash code that is both correct and performant.
In any large software project, complexity is a major challenge. This complexity often manifests as:
UnifyWeaver addresses this by providing a single source of truth. The Prolog code becomes the master blueprint for your data logic. The Bash scripts are the generated, disposable artifacts. If you need to change the logic, you change it in one place—the Prolog source—and regenerate the scripts.
To understand UnifyWeaver, we must first grasp a few key ideas.
Instead of writing step-by-step instructions (imperative programming), you describe the desired result and the rules that apply.
Prolog is a declarative language, which makes it excellent for defining rules and relationships without getting bogged down in implementation details.
Prolog is the most well-known logic programming language. It is based on a few simple but powerful ideas:
parent(alice, bob).ancestor(X, Y) :- parent(X, Y).?- ancestor(alice, X).The Prolog engine uses these facts and rules to automatically deduce the answers to your queries.
Code generation is the process of using a program to create other programs. UnifyWeaver is a code generator that takes Prolog as input and produces Bash as output. This is the mechanism it uses to translate the declarative logic into executable scripts.
The name “UnifyWeaver” is a good metaphor for what it does. Imagine your project is a complex tapestry. You have different threads: data files, configuration, business logic, and infrastructure code.
UnifyWeaver acts as a smart loom.
If you want to change the design, you don’t re-weave it by hand. You adjust the pattern (the Prolog code), and the loom re-weaves it for you, ensuring the entire tapestry remains consistent.
Over the next chapters, we will explore:
Let’s begin our journey by diving into the fundamentals of Prolog.
| 📖 Book 1: Foundations | Next: Chapter 2: Prolog Fundamentals for UnifyWeaver → |