# ⚗️ Catalyx

**A reactive streaming runtime built on RayforceDB, inspired by join calculus and chemical reaction models.**

Catalyx brings the elegance of chemical metaphors to reactive programming. Define molecules, reactions, and watch your data flow through a reactive substrate powered by RayforceDB's ultra-fast columnar engine.

## 🧬 Concepts

| Chemical Metaphor | Programming Concept |
|-------------------|---------------------|
| **Molecule** | Message/Event with typed payload |
| **Reaction** | Join pattern matching multiple molecules |
| **Solution** | Reactive context/namespace |
| **Catalyst** | Persistent trigger that isn't consumed |
| **Substrate** | Underlying RayforceDB storage |

## 🚀 Quick Start

```bash
# Build and run the REPL
cargo run

# Or install globally
cargo install --path .
```

## ⚡ REPL Features

- **Syntax Highlighting** - Molecules, reactions, and keywords beautifully colored
- **Auto-completion** - Tab completion for all Catalyx constructs
- **Persistent History** - Command history saved across sessions
- **Multi-line Editing** - Continue expressions across lines
- **Inline Hints** - Ghost text suggestions as you type

## 🧪 Example Session

```
❯ mol ping(x: int)
⊛ Molecule `ping` defined

❯ mol pong(y: int)  
⊛ Molecule `pong` defined

❯ react ping(a) & pong(b) => show (+ a b)
⊛ Reaction defined: ping ⊗ pong → λ

❯ emit ping(21) pong(21)
42
```

## 📖 Commands

| Command | Description |
|---------|-------------|
| `:?` | Show help |
| `:q` | Quit REPL |
| `:m` | List molecules |
| `:r` | List reactions |
| `:s` | Show solution state |
| `:c` | Clear screen |
| `:t` | Toggle timing |

## 🔬 Language

### Molecules

```catalyx
# Define a molecule type
mol request(id: guid, payload: string)

# Emit molecules into the solution
emit request(guid(), "hello world")
```

### Reactions

```catalyx
# Simple reaction consuming two molecules
react request(id, p) & response(id, r) => 
    show "Got response" r "for request" id

# Reaction with guard
react tick(t) & buffer(data) where (> (count data) 100) =>
    flush data
```

### Catalysts

```catalyx
# Catalysts persist and trigger reactions without being consumed
catalyst config(settings: dict)

react request(r) & config(c) =>
    process r (get c `timeout)
```

## 📄 License

MIT License - see [LICENSE](LICENSE)

## 🔗 Links

- [RayforceDB](https://rayforcedb.com) - The underlying columnar database
- [Join Calculus](https://en.wikipedia.org/wiki/Join-calculus) - Theoretical foundation

