Xen / examples v0.1.0-demo.2
Connected values
This topic is not available in the selected language or version. Showing the start of this section.
Connected values
Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.
xen check examples/recursive_data.xenxen run examples/recursive_data.xenExpected output
Section titled “Expected output”30Complete source
Section titled “Complete source”// SPDX-License-Identifier: MIT OR Apache-2.0struct 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));}Build an executable
Section titled “Build an executable”xen build examples/recursive_data.xen -o appRun the generated executable on a compatible Linux machine.