Xen / examples v0.1.0-demo.2
Split a program across files
This topic is not available in the selected language or version. Showing the start of this section.
Split a program across files
Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.
xen check examples/modules/app.xenxen run examples/modules/app.xenExpected output
Section titled “Expected output”tea: 3Complete source
Section titled “Complete source”// SPDX-License-Identifier: MIT OR Apache-2.0module app;import shop.model as model;import shop.view as view;
fn main() { let item = model.Item { name: "tea", price: 3 }; view.show(item);}Save all three files with this structure. The shop modules are support files, not standalone programs.
examples/modules/├── app.xen└── shop/ ├── model.xen └── view.xenshop/model.xen
Section titled “shop/model.xen”// SPDX-License-Identifier: MIT OR Apache-2.0module shop.model;
struct Item { name: String, price: Int }shop/view.xen
Section titled “shop/view.xen”// SPDX-License-Identifier: MIT OR Apache-2.0module shop.view;import shop.model as model;
fn show(item: model.Item) { println(item.name + ": " + int_to_str(item.price));}