Five lessons.
The whole language
in your head.

Hello world, errors as values, channels, an HTTP server, and a macro. Every example below compiles with glide run.

1 · hello

Hello, world

fn main() -> int is the entry point. println! writes to stdout with a trailing newline; the bang signals it's a macro. The return value is the process exit code.

Save the snippet as hello.glide and run it with glide run hello.glide.

hello.glide
fn main() -> int {
    println!("hello, glide");
    return 0;
}
2 · errors

Errors as values

!T means "either a T or an error". ok(v) and err("msg") build them. The postfix ? propagates: if the result is an error, the function returns immediately; otherwise v is unwrapped into the local binding.

No exceptions, no panic handlers — the failure mode is in the type signature.

errors.glide
fn parse(n: int) -> !int {
    if n < 0 { return err("negative"); }
    return ok(n * 2);
}

fn pipeline(n: int) -> !int {
    let v: int = parse(n)?;
    return ok(v + 1);
}

fn main() -> int {
    let r: !int = pipeline(10);
    if r.ok { println!("got:", r.val); }
    else   { println!("err:", r.err); }
    return 0;
}
3 · channels

Channels and spawn

spawn kicks off an M:N coroutine. chan<T> is a typed channel; make_chan(cap) creates one with a buffer. Channels are first-class values — pass them as arguments, store them in structs, close them with .close().

For OS threads instead of coroutines, use spawn_thread — same syntax, different scheduler.

channels.glide
fn producer(c: chan<int>) {
    for i in 0..3 { c.send(i * i); }
    c.close();
}

fn main() -> int {
    let c: chan<int> = make_chan(2);
    spawn producer(c);
    while let v = c.recv() { println!("got:", v); }
    return 0;
}
4 · http

An HTTP server

Import stdlib::http::*. A handler is fn(*HttpRequest) -> HttpResponse. http_listen(port, handler) binds, accepts, and runs the loop forever.

For TLS, swap to https_listen(port, cert, key, handler) — same shape, plus the PEM files. Routers, middleware, and static-file serving live in stdlib::http::router.

server.glide
import stdlib::http::*;

fn root(req: *HttpRequest) -> HttpResponse {
    if req.path.eq("/health") {
        return HttpResponse::ok().text("ok");
    }
    return HttpResponse::ok().html("<h1>hello from glide</h1>");
}

fn main() -> int {
    http_listen(8080, root);
    return 0;
}
5 · macros

Macros, declarative

macro_rules! matches token patterns — $x:expr, $x:ident, $x:ty — and expands to code at compile time. The variadic form $($x:expr),* matches a comma-separated list and lets you iterate over the captures with $( … )*.

For richer metaprogramming, @derive(Name) and @name!(args) are procedural macros that run inside the compiler.

macros.glide
macro_rules! sum {
    ($($x:expr),*) => { {
        let mut t: int = 0;
        $( t = t + $x; )*
        t
    } };
}

fn main() -> int {
    let total: int = sum!(1, 2, 3, 4);
    println!("sum =", total);   // 10
    return 0;
}

Where to next

Five lessons in; you've seen most of the surface. Pick what you need.

More examples

Larger programs — HTTP routers, JSON, file walkers, WebSockets, inline asm.

Browse examples →

Stdlib reference

Every pub item in the standard library, generated from doc comments.

Open the API →