SPECTRALANG_

// DOCS NAVIGATION

QUICK_START

SOURCE: README.md — Quick Start

SOURCE: README.md — Quick Start section (view full README)

Quick Start

Hello, Spectra — a basic program

Create a file hello.spectra:

module hello;

pub fn main() {
    let x = 10;
    let y = 20;
    let sum = x + y;
    return;
}

Run it with the JIT:

spectralang run hello.spectra

Run a bundled example

The repository ships with a small, self-contained starter program:

spectralang run examples/basic.spectra

Build a tiny HTTP service (API platform)

The examples/api/00_hello_http.spectra example exercises the spectra.api server surface (routing, handlers, requests, responses, listen/shutdown):

spectralang run examples/api/00_hello_http.spectra

The first few lines of that file illustrate the API surface — a Router, a registered Handler, and a Server you listen on and serve until shutdown:

module hello_http;

import { Server, new, listen, serve, shutdown } from std.api.server;
import { Router, Route, router, get, route_id } from std.api.routing;
import { HandlerHandle, text, with_header, register_sync, dispatch_sync } from std.api.handler;
import { Request, Response, method_get, request, response_status } from std.api.http;

The full, runnable example (with handler registration, request dispatch, listen, serve, and shutdown) lives at examples/api/00_hello_http.spectra. For a CRUD-style variant, see examples/api/01_rest_crud.spectra.

Run a tensor graph (AI core)

The examples/ai/tensor_graph_elementwise_fusion.spectra example uses the tensor runtime and exercises the graph IR's elementwise fusion path:

spectralang run examples/ai/tensor_graph_elementwise_fusion.spectra

The example:

module ai_tensor_graph_elementwise_fusion;

import std.tensor as tensor;

pub fn main() -> int {
    tensor.free_all();
    tensor.reset_stats();

    let input = tensor.full_f(8, 4.0);
    let activated = tensor.relu(input);
    let normalized = tensor.sqrt_f(activated);
    let projected = tensor.tanh_f(normalized);

    if tensor.len(projected) != 8 { return tensor.len(projected); }
    if tensor.get_f(projected, 0) <= 0.0 { return 1; }
    if tensor.stats_kernel_ops() < 3 { return 2; }

    tensor.free_all();
    return 0;
}

More examples

ls examples/
# basic, control flow, methods, algorithms, math, fibonacci, calculator, ...

ls examples/ai/
# mlp, cnn, transformer, onnx, rag, distributed training, monitoring, ...

ls examples/projects/
# boletim, complex_demo, multi_file, poliedro, spectra_academy, test_corpus