UnifyWeaver

Book 3: C# Target Language

Multi-Target Compilation: From Prolog to C# / .NET

Part of the UnifyWeaver Education Series

This book covers UnifyWeaver’s C# code generation targets, enabling you to compile Prolog predicates to idiomatic C# code and .NET assemblies. This is where fixed-point approaches are introduced.

Prerequisites

Before starting Book 3, you should have:

What You’ll Learn

C# Targets Overview

UnifyWeaver provides two C# compilation targets:

1. Stream Target (csharp_stream_target.pl)

2. Query Runtime (csharp_query_target.pl)

Book Structure

Chapter 1: Introduction to Multi-Target Compilation

Chapter 2: C# Stream Target

Chapter 3: C# Query Runtime

Chapter 4: Runtime Libraries and Deployment

Installation Requirements

Required

Optional

Quick Start Example

% Define a simple predicate
parent(alice, bob).
parent(bob, charlie).

% Compile to C#
?- compile_predicate_to_csharp(parent/2, [], CSharpCode).

% Generated C# (simplified):
namespace UnifyWeaver.Generated {
    public static class Parent {
        static readonly (string, string)[] Facts = {
            ("alice", "bob"),
            ("bob", "charlie")
        };

        public static IEnumerable<(string, string)> Stream()
            => Facts;
    }
}

What’s New in v0.1

Comparison: Bash vs C# Targets

Feature Bash Target C# Stream C# Query Runtime
Recursion Full support Limited Full support
Performance Good Excellent Very Good
Deployment Shell scripts .NET apps .NET apps
Memory Streaming In-memory Hybrid
Debugging Shell tools Visual Studio Visual Studio
Dependencies Bash 4.0+ .NET SDK .NET SDK + Runtime lib

When to Use Each Target

Use Bash Target when:

Use C# Stream Target when:

Use C# Query Runtime when:

Learning Path

  1. Start with Chapter 1 - Understand multi-target compilation concepts
  2. Work through Chapter 2 - Build simple C# programs from Prolog
  3. Advance to Chapter 3 - Master query runtime for complex cases
  4. Complete Chapter 4 - Deploy production-ready .NET applications

Example Projects

Throughout Book 2, you’ll build:

Additional Resources

Going Further

After completing Book 3, you’ll be able to:

Continue to Book 4 to learn about:

License

This educational content is licensed under CC BY 4.0. Code examples are dual-licensed under MIT OR Apache-2.0.

Feedback

Found an issue or have suggestions?