UnifyWeaver

Book 11: Prolog Target

Prolog-to-Prolog Transpilation and Dialect Support

Part of the UnifyWeaver Education Series

Welcome to the comprehensive guide to UnifyWeaver’s Prolog target system!

Note: Firewall and security content from this book has been extracted to Book 8: Security & Firewall.

Prerequisites

Required:

Recommended:

Technical:

What This Book Covers

This book teaches you how to:

Who Should Read This

Book Structure

Part 1: Fundamentals (Chapters 1-3)

Start here if you’re new to the Prolog target. Learn what it is, how it works, and understand the different Prolog dialects.

Start with: Chapter 1: Introduction

Part 2: Using the Prolog Target (Chapters 4-6)

Practical guides for generating scripts, compiling binaries, and managing dependencies.

Key Chapter: Chapter 5: Compilation vs Interpretation

Part 3: Advanced Features (Chapters 7-9)

Security policies, fallback mechanisms, and validation systems.

Highlights:

Part 4: Implementation Deep Dive (Chapters 10-12)

For developers who want to understand or extend the implementation.

Key Chapter: Chapter 2: Architecture Overview

Part 5: Practical Applications (Chapters 13-15)

Real-world patterns and a complete case study.

Must Read: Chapter 15: Case Study - Factorial Compilation

Quick Start

5-Minute Introduction

% 1. Load the Prolog target
:- use_module('src/unifyweaver/targets/prolog_target').

% 2. Define your predicate
factorial(0, 1) :- !.
factorial(N, R) :- N > 0, N1 is N-1, factorial(N1, R1), R is N*R1.

% 3. Generate a script
?- generate_prolog_script([factorial/2],
                         [dialect(gnu), compile(true)],
                         Code),
   write_prolog_script(Code, 'factorial', [dialect(gnu), compile(true)]).

% 4. Run your binary!
$ ./factorial

Next: Read Chapter 1 for details.

30-Minute Tutorial

Work through these chapters in order:

  1. Chapter 1: Introduction - 10 minutes
  2. Chapter 3: Dialects - 10 minutes
  3. Chapter 15: Case Study - 10 minutes

You’ll understand the basics and have working code.

Complete Guide

Read the book in order from 00_index.md. Budget 3-4 hours for a complete reading.

Hands-On Learning

Each chapter includes examples you can run. To follow along:

Prerequisites

# Install SWI-Prolog
sudo apt-get install swi-prolog  # Ubuntu/Debian
brew install swi-prolog          # macOS

# Install GNU Prolog (for compilation)
sudo apt-get install gprolog     # Ubuntu/Debian
brew install gnu-prolog          # macOS

# Clone UnifyWeaver
git clone https://github.com/yourorg/UnifyWeaver.git
cd UnifyWeaver

Running Examples

# Navigate to UnifyWeaver directory
cd /path/to/UnifyWeaver

# Start SWI-Prolog
swipl

# Load the chapter examples
?- [examples/book_examples/chapter_04_basic_usage].

Current Status

This book documents UnifyWeaver v0.1 which includes:

✅ Complete Prolog target implementation ✅ SWI-Prolog and GNU Prolog dialects ✅ Compilation support with error checking ✅ Firewall integration ✅ Basic fallback mechanisms ✅ Validation system

Recent Improvements (v0.1)

The following critical fixes were implemented:

  1. Initialization Directives: Correct initialization/1 for GNU Prolog compiled binaries
  2. Error Checking: Compilation failures now properly detected and reported
  3. Graceful Fallback: Failed compilation falls back to interpreted scripts

These fixes are covered in detail in Chapter 15: Case Study.

What’s Coming

Planned for v0.2

See Chapter 8: Fallback Mechanisms for roadmap details.

Chapter Status

Chapter Status Last Updated
00 - Index ✅ Complete 2025-11-17
01 - Introduction ✅ Complete 2025-11-17
02 - Architecture ✅ Complete 2025-11-17
03 - Dialects ✅ Complete 2025-11-17
04 - Basic Usage 📝 Planned -
05 - Compilation Modes 📝 Planned -
06 - Dependencies 📝 Planned -
07 - Firewall Integration ✅ Complete 2025-11-17
08 - Fallback Mechanisms ✅ Complete 2025-11-17
09 - Validation 📝 Planned -
10 - Code Generation 📝 Planned -
11 - Dialect Specifics 📝 Planned -
12 - Compilation 📝 Planned -
13 - Patterns 📝 Planned -
14 - Troubleshooting 📝 Planned -
15 - Case Study ✅ Complete 2025-11-17
Appendix A - API Reference 📝 Planned -
Appendix B - Dialect Comparison 📝 Planned -
Appendix C - Firewall Examples 📝 Planned -

Contributing

Found an error or want to add content?

  1. File an issue describing the problem or suggestion
  2. Submit a pull request with corrections
  3. Propose new chapters or topics

All contributions welcome!

This is part of the UnifyWeaver Educational Series:

  1. Book 1: Core Bash - Using UnifyWeaver with Bash targets
  2. Book 2: Advanced Features - Partitioning, parallelism, data sources
  3. Book 3: Prolog Target (This Book) - Generating Prolog code
  4. Book 4: C# Target - .NET integration and compilation

License

Same license as UnifyWeaver (check main repository).

Getting Help


Version: 0.1.0 Last Updated: 2025-11-17 Maintainers: UnifyWeaver Team

Happy learning! 🎓