Prerequisite
LinkUse Topaz 5.21.3 with SELF and language mode 5.21. Work in one directory containing the two files in this chapter.
1. Split the program
LinkSave both files with the shown names. greeting. exports greet; main. selects it and imports std. as io. Keep the output call in main..
2. Check the entry file
LinkCheck both source files
Linkimport greeting { greet }import std.ioio.writeLine(greet("Topaz"))
main.tpz: types-ok (3 modules) main.tpz: resolve-ok (3 modules)
export function greet(name: string) -> string {return "Hello, {name}!"}
Expected result
Expected result
Checking accepts the program. Exit code 0.
Observed assertions · passed · 5.21.3
Exit code 0.
main.tpz: types-ok (3 modules)main.tpz: resolve-ok (3 modules)
No stderr.
- Passed · expected 0; observed 0
Source evidence
- compiler/crates/topaz_self_frontend/topaz/parser/declarations_modules.tpz at
b48527d0a174· 1017-1037 - compiler/crates/topaz_self_frontend/topaz/parser/declarations_modules.tpz at
b48527d0a174· 1155-1184 - compiler/crates/topaz_self_frontend/topaz/parser/declarations_modules.tpz at
b48527d0a174· 1206-1245 - compiler/crates/topaz_self_frontend/topaz/resolver/graph.tpz at
b48527d0a174· 52-76 - compiler/crates/topaz_self_frontend/topaz/resolver/modules_tables.tpz at
b48527d0a174· 158-207 - compiler/crates/topaz_self_frontend/topaz/resolver/graph.tpz at
b48527d0a174· 648-674 - compiler/crates/topaz_cli/src/command/flags.rs at
b48527d0a174· 101-135 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 50-74 - compiler/crates/topaz_resolve/src/std/521/io.tpz at
b48527d0a174· 3-5
Run the command from the directory containing both files. Checking should succeed. If module resolution fails, check the file name and location, then follow the reported diagnostic.
3. Run the program
LinkRun the entry file
Linkimport greeting { greet }import std.ioio.writeLine(greet("Topaz"))
Hello, Topaz!
export function greet(name: string) -> string {return "Hello, {name}!"}
Expected result
Expected result
Execution completes. Exit code 0.
Hello, Topaz!
Observed assertions · passed · 5.21.3
Exit code 0.
Hello, Topaz!
No stderr.
- Passed · expected 0; observed 0
- Passed · stdout matches the authored expectation
- Passed · stderr matches the authored expectation
Source evidence
- compiler/crates/topaz_self_frontend/topaz/parser/declarations_modules.tpz at
b48527d0a174· 1017-1037 - compiler/crates/topaz_self_frontend/topaz/parser/declarations_modules.tpz at
b48527d0a174· 1155-1184 - compiler/crates/topaz_self_frontend/topaz/parser/declarations_modules.tpz at
b48527d0a174· 1206-1245 - compiler/crates/topaz_self_frontend/topaz/resolver/graph.tpz at
b48527d0a174· 52-76 - compiler/crates/topaz_self_frontend/topaz/resolver/modules_tables.tpz at
b48527d0a174· 158-207 - compiler/crates/topaz_self_frontend/topaz/resolver/graph.tpz at
b48527d0a174· 648-674 - compiler/crates/topaz_cli/src/command/flags.rs at
b48527d0a174· 101-135 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 50-74 - compiler/crates/topaz_resolve/src/std/521/io.tpz at
b48527d0a174· 3-5
The expected program output is Hello, Topaz! followed by a newline. The imported function supplies the greeting; std. writes it.
Imports and package setup
Linkimport greeting { greet } selects an exported name; it does not install a dependency. These commands pass a source-file entry. Without an entry operand, package mode loads topaz.. See the check reference.
Verification record
LinkPublic Topaz 5.21.3 checked and ran this two-file program successfully in Docs run 42224592687, attempt 2. The recorded exit codes and output were compared with this page's current product assertions. The fixture files, invocation and expected output were unchanged.
Modules and visibility defines imports and exported declarations. Packages, locks and targets describes package inputs.