Documentation channel: current development main at compiler checkpoint 1d7e15e. The latest tagged release is v0.0.3; pages identify APIs that are not yet released.

Examples

Small examples are kept deliberately ordinary. The point is to show how Strut reads in real code rather than compress every language feature into one demonstration.

Hello world

function main() -> int {
    print("hello, world!");
    return 0;
}

Collections

function main() -> int {
    int[] values := [1, 2, 3, 4];
    squares := values.map((x) => x * x);

    for (value : squares) {
        print(value);
    }

    return 0;
}

JSON configuration

config := {
    "host": "127.0.0.1",
    "port": 8080
};

print(json.pretty(config));

Safe pointers

Raw extraction is explicit and limited to unsafe code. This complete example is compiled and executed by documentation CI:

function main() -> int {
    int* value := new(7);
    unsafe {
        raw_ptr<int> address := ptr(value);
        print(*address);
    }
    return 0;
}

Tuple and collections

include <tuple>;
include <map>;
include <priority_queue>;

tuple<double, int> measurement := (2.0, 1);
map<string, int> counts := ["ready": 2];

priority_queue<int, min> next;
next.push(8);
next.push(3);
print(next.top()); // 3

Filesystem scripting

include <filesystem>;

make_dir("dist/assets");
copy(["css/*.css", "js/*.js"], "dist/assets");
write_file("dist/version.txt", "0.0.3\n");

for (path : walk("dist")) {
    print(path);
}

WebSocket terminal session

P10 composes the public WebSocket and PTY APIs in application code rather than adding a built-in bridge. A route owns the PTY lifetime, uses binary messages for terminal bytes, accepts only validated text controls, and runs a joined bounded output pump:

function terminal_session(http_request request, websocket socket) -> void
        : (NetworkError, WebSocketError, PtyError, ThreadError) {
    socket.accept();
    terminal := pty_spawn("/bin/sh", [], request.cancellation);
    output := thread(() => {
        try {
            while (!terminal.eof()) {
                bytes chunk := terminal.read_bytes(4096);
                if (!chunk.empty()) { socket.write_bytes(chunk); }
            }
        } catch (PtyError caught) {
        } catch (NetworkError caught) {
        } catch (WebSocketError caught) {
        }
    });

    message := socket.read();
    if (message != null && (message?.kind ?? "") == "binary") {
        terminal.write_bytes(message?.data ?? bytes());
    }
    terminal.close();
    output.join();
}

A complete service should loop over messages, implement an explicit control vocabulary, authorize before accept(), and close and join on every error, peer-close, cancellation, and shutdown path. See WebSockets and Pseudo-terminals for the certified lifecycle and backpressure contract.