XU XUv0.16.0

Functions

fn add(a int, b int) int {
    << a + b
}

fn (c $&Counter) inc() {
    c.n += 1
}

Variadic is trailing name <-> T, seen as []T in the body. Errors are not extra return values; they use >> + >>> (err).

In expressions << / >> remain shifts; as statements they return/throw; >>> propagates & handles errors. Boolean or is ||. Division by zero and out-of-bounds index fail loud.

Generic Type Parameters

Declare type parameters after # in the function name; calls are monomorphized from their arguments. 0.9.4 removes the four-type-parameter limit on generic declarations:

fn fifth#A,B,C,D,E(a A, b B, c C, d D, e E) E {
    << e
}

// fifth(1, true, 3.0, "four", 5) returns 5

See the generics tutorial for method-set constraints and dynamic boxes.

Migration der Fehlersyntax (0.15.0)

Xu 0.15.0 hat veraltete or-Fehlerhandler (or (err) { } und or >>) entfernt. Sie lösen nun einen harten Parser-Fehler aus, der auf >>> (err) { } und >>> verweist (während >> expr Fehler wirft). or ist nun ein normaler Bezeichner (logisches ODER verwendet ||), und xu-lsp bietet eine Quick-Fix-Code-Aktion zur Migration der alten Syntax; siehe VS Code / Cursor LSP-Code-Aktionen.