Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Тур

    Модули и стандартная библиотека

    Move a greeting into another source file, import it, and print through the standard library.

    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.tpz exports greet; main.tpz selects it and imports std.io as io. Keep the output call in main.tpz.

    2. Check the entry file

    Ссылка

    Check both source files

    Ссылка
    main.tpzCheck both source filesОткрыть песочницу →
    1. import greeting { greet }
    2. import std.io
    3. io.writeLine(greet("Topaz"))
    Зафиксированный выводКод завершения 0
    main.tpz: types-ok (3 modules)
    main.tpz: resolve-ok (3 modules)
    
    $ topaz check main.tpz --compiler self · Зафиксировано с Топазом 5.21.3
    greeting.tpzCheck both source filesОткрыть песочницу →
    1. export function greet(name: string) -> string {
    2. return "Hello, {name}!"
    3. }
    Ожидаемый результат

    Ожидаемый результат

    Проверка принимает программу. Код завершения 0.

    Наблюдаемые утверждения · Пройдено · 5.21.3

    Код завершения 0.

    Наблюдаемый стандартный вывод
    1. main.tpz: types-ok (3 modules)
    2. 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

    Ссылка
    main.tpzRun the entry fileОткрыть песочницу →
    1. import greeting { greet }
    2. import std.io
    3. io.writeLine(greet("Topaz"))
    Зафиксированный выводКод завершения 0
    Hello, Topaz!
    
    $ topaz run main.tpz --compiler self · Зафиксировано с Топазом 5.21.3
    greeting.tpzRun the entry fileОткрыть песочницу →
    1. export function greet(name: string) -> string {
    2. return "Hello, {name}!"
    3. }
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. Hello, Topaz!
    Наблюдаемые утверждения · Пройдено · 5.21.3

    Код завершения 0.

    Наблюдаемый стандартный вывод
    1. 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.io.writeLine 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.toml. 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.

    Next steps

    Ссылка

    Functions and generics →

    std.io.writeLine →

    check →

    First checked and executed program →

    Меню

    Загрузка →