View on GitHub

Nexus Language

A LLM-friendly language

Semantics

This document describes the execution model of Nexus.

Evaluation Strategy

Nexus is call-by-value. All expressions are fully evaluated before being passed to functions or constructors.

Evaluation Order

Strict left-to-right:

Scoping

Lexical scoping. Bindings are visible in the block where they are defined and in nested blocks.

Shadowing is permitted. An inner let can reuse a name from an outer scope, masking it until the inner block ends.

Sigil Behavioral Semantics

Sigils are not annotations – they impose runtime behavioral constraints.

Mutability (~)

Linearity (%)

Borrowing (&)

Closures and Captures

Exception Propagation

raise immediately terminates the current computation and unwinds the call stack until it reaches a try/catch block. The Exn value is passed to the catch parameter:

try
    raise NotFound(msg: "key")
catch e ->
    // e : Exn
    match e do
        case NotFound(msg: m) -> ()
        case _ -> ()
    end
end

Exceptions are the only builtin effect. There are no unchecked exceptions – any function that may raise must declare effect { Exn }. try/catch discharges Exn from the protected region.

Concurrency Model

Structured Concurrency (conc)

conc do
    task worker1 do
        // ...
    end
    task worker2 do
        // ...
    end
end

Entrypoint

main Function

Every Nexus program must define a main function with these constraints:

let main = fn () -> unit require { PermConsole } do
    inject stdio.system_handler do
        Console.println(val: "Hello")
    end
    return ()
end

The runtime calls main, which performs all side effects via injected handlers. Exit code is 0 on success, non-zero on unhandled error.