Skip to content
Xen / docs

Search documentation

English · v0.1.0-demo.2

Type to search the documentation.

    한국어
    Xen / examples v0.1.0-demo.2

    Connected values

    Connected values

    Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.

    Terminal window
    xen check examples/recursive_data.xen
    xen run examples/recursive_data.xen
    30
    recursive_data.xen
    // SPDX-License-Identifier: MIT OR Apache-2.0
    struct Node { value: Int, next: Option<Box<Node>> }
    fn sum(node: Node) -> Int {
    let rest = match node.next {
    Option.Some(next) => sum(next.into_inner()),
    Option.None => 0,
    };
    return node.value + rest;
    }
    fn main() {
    let last = Node { value: 20, next: Option<Box<Node>>.None };
    let first = Node { value: 10, next: Option.Some(box(last)) };
    println(sum(first));
    }

    Download file

    Terminal window
    xen build examples/recursive_data.xen -o app

    Run the generated executable on a compatible Linux machine.