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

    Split a program across files

    Split a program across files

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

    Terminal window
    xen check examples/modules/app.xen
    xen run examples/modules/app.xen
    tea: 3
    modules/app.xen
    // SPDX-License-Identifier: MIT OR Apache-2.0
    module app;
    import shop.model as model;
    import shop.view as view;
    fn main() {
    let item = model.Item { name: "tea", price: 3 };
    view.show(item);
    }

    Download file

    Save all three files with this structure. The shop modules are support files, not standalone programs.

    examples/modules/
    ├── app.xen
    └── shop/
    ├── model.xen
    └── view.xen
    // SPDX-License-Identifier: MIT OR Apache-2.0
    module shop.model;
    struct Item { name: String, price: Int }

    shop/model.xen

    // SPDX-License-Identifier: MIT OR Apache-2.0
    module shop.view;
    import shop.model as model;
    fn show(item: model.Item) {
    println(item.name + ": " + int_to_str(item.price));
    }

    shop/view.xen