Prerequisite
СсылкаUse 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
СсылкаSave 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
СсылкаCheck both source files
Ссылкаimport 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}!"}
Ожидаемый результат
Ожидаемый результат
Проверка принимает программу. Код завершения 0.
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
main.tpz: types-ok (3 modules)main.tpz: resolve-ok (3 modules)
Нет вывода ошибок.
- Пройдено · expected 0; observed 0
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
СсылкаRun the entry file
Ссылкаimport greeting { greet }import std.ioio.writeLine(greet("Topaz"))
Hello, Topaz!
export function greet(name: string) -> string {return "Hello, {name}!"}
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
Hello, Topaz!
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
Hello, Topaz!
Нет вывода ошибок.
- Пройдено · expected 0; observed 0
- Пройдено · stdout matches the authored expectation
- Пройдено · stderr matches the authored expectation
The expected program output is Hello, Topaz! followed by a newline. The imported function supplies the greeting; std. writes it.
Imports and package setup
Ссылкаimport 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
СсылкаPublic 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.