Nexus Language

A pragmatic, multi-language orchestration language

Nexus is designed to seamlessly connect code across JavaScript, Python, Rust, Go, PHP, Java, C, and WebAssembly through a clean FFI (Foreign Function Interface).

Nexus provides a clean, expression-based syntax with strong typing and familiar control flow.

Core Syntax

Variables & Types

Variables are declared with `let` (immutable) or `var` (mutable):

nexus
func main(): void {
    let name: string = "Nexus";
    let version: int = 1;
    var counter: int = 0;
    
    print(name + " v" + version);
    
    counter = counter + 1;  // OK: var is mutable
    // name = "Other";      // Error: let is immutable
}

Type inference (optional):

nexus
let name = "Nexus";     // inferred: string
let version = 1;        // inferred: int
let active = true;      // inferred: bool

Functions

Functions are defined with `func` keyword and explicit return types:

nexus
// Function with return value
func add(a: int, b: int): int {
    return a + b;
}

// Void function (no return)
func greet(name: string): void {
    print("Hello " + name);
}

// Usage
func main(): void {
    let result = add(10, 32);
    greet("Nico");
    print("Sum: " + result);
}

Control Flow

If/Else

nexus
func main(): void {
    let x = 42;
    
    if x > 40 {
        print("Large");
    } else if x > 20 {
        print("Medium");
    } else {
        print("Small");
    }
}

While Loop

nexus
func main(): void {
    var i = 0;
    
    while i < 5 {
        print(i);
        i = i + 1;
    }
}

For Loop

nexus
func main(): void {
    var total = 0;
    
    for var i = 0; i < 5; i = i + 1 {
        total = total + i;
    }
    
    print(total);  // 10
}

Match Statement

Pattern matching for cleaner branching:

nexus
func main(): void {
    let status = "running";
    
    match status {
        "pending" => print("Waiting..."),
        "running" => print("In progress"),
        "done" => print("Complete"),
        _ => print("Unknown")
    }
}

Multi-Language FFI

Nexus's killer feature: seamlessly call functions from 8 different languages.

FFI Declarations

Declare foreign functions with `ffi` keyword:

nexus
// JavaScript (browser/Node.js)
ffi js dom_alert(msg: string): void;
ffi js fetch(url: string): string;

// Python (AI/ML)
ffi py ml_predict(x: int): int;
ffi py process_data(input: string): string;

// Rust (performance/crypto)
ffi rs crypto_hash(data: string): string;
ffi rs compress(data: string): string;

// Go (networking/services)
ffi go start_server(port: int): void;
ffi go http_get(url: string): string;

// PHP (backend/APIs)
ffi php user_get(id: int): string;
ffi php db_query(sql: string): string;

// Java (enterprise/legacy)
ffi java get_customer(id: int): string;

// C (system/audio)
ffi c audio_beep(freq: int, duration: int): void;

// WebAssembly (portable modules)
ffi wasm math_add(a: int, b: int): int;

Using FFI Functions

Once declared, FFI functions are called like regular Nexus functions:

nexus
func main(): void {
    // Browser alert
    dom_alert("Hello from Nexus!");
    
    // Python AI prediction
    let score = ml_predict(42);
    print("Prediction: " + score);
    
    // Rust crypto
    let hash = crypto_hash("sensitive_data");
    print("Hash: " + hash);
    
    // Go server
    start_server(8080);
    
    // PHP database
    let user = user_get(123);
    print("User: " + user);
    
    // C audio
    audio_beep(440, 1000);  // A4 note for 1 second
    
    // WASM math
    let sum = math_add(10, 32);
    print("Sum: " + sum);
}

Real-World Example

Orchestrating multiple languages in one program:

nexus
ffi js fetch(url: string): string;
ffi py analyze(text: string): int;
ffi rs encrypt(data: string): string;
ffi php save(data: string): void;

func process_api_data(url: string): void {
    // 1. Fetch data with JavaScript
    let raw_data = fetch(url);
    print("Fetched: " + raw_data);
    
    // 2. Analyze with Python ML
    let sentiment = analyze(raw_data);
    print("Sentiment score: " + sentiment);
    
    // 3. Encrypt with Rust
    let encrypted = encrypt(raw_data);
    
    // 4. Save with PHP backend
    save(encrypted);
    
    print("Pipeline complete!");
}

func main(): void {
    process_api_data("https://api.example.com/data");
}

Arrays & Collections

nexus
func main(): void {
    // Arrays
    let nums: [int] = [1, 2, 3, 4, 5];
    print(nums[0]);  // 1
    
    // Iteration
    for var i = 0; i < 5; i = i + 1 {
        print(nums[i]);
    }
}

Comments

nexus
// Single-line comment

/*
   Multi-line comment
   Spans multiple lines
*/

func main(): void {
    print("Hello!");  // Inline comment
}

Error Handling

nexus
func divide(a: int, b: int): Result<int, string> {
    if b == 0 {
        return Err("Division by zero");
    }
    return Ok(a / b);
}

func main(): void {
    let result = divide(10, 0);
    
    match result {
        Ok(val) => print("Result: " + val),
        Err(msg) => print("Error: " + msg)
    }
}

Compilation Targets

Nexus compiles to multiple targets:

bash
# Standalone Nexus bytecode
nexus build app.nx --target standalone --out app.nxb
nexus run app.nxb

# VM.ZERO bytecode
nexus build app.nx --target vmzero --out app.vmz
vmzero run app.vmz

# WebAssembly
nexus build app.nx --target wasm --out app.wasm

Getting Started

Installation

bash
# Install Nexus compiler
curl -sSL https://nexus-lang.org/install.sh | sh

# Verify installation
nexus --version

Your First Program

Create hello.nx:

nexus
func main(): void {
    print("Hello, Nexus!");
}

Compile and run:

bash
nexus build hello.nx --target standalone --out hello.nxb
nexus run hello.nxb

Philosophy

Nexus is built on three core principles:

  • Orchestration First - Connect languages, don't replace them
  • Pragmatic Simplicity - Clean syntax, no academic complexity
  • Multi-Target - Compile to bytecode, WASM, or native

Use Case: When you need Python's ML libraries, Rust's performance, JavaScript's DOM access, and PHP's backend—all in one program.