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

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

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

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

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

    Тур

    Первая проверенная и запущенная программа

    Write one function, check its types, and run it to print a line.

    Prerequisite

    Ссылка

    Use a Topaz distribution that provides language mode 5.21 and the default SELF compiler.

    1. Write a function

    Ссылка

    Save the source in the check example below as first-program.tpz. The function returns a greeting. The final call sends it to std.io.writeLine. This example uses an explicit output operation; it does not depend on automatic printing of a top-level value.

    2. Check the program

    Ссылка

    Check the first program

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

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

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

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

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

    Наблюдаемый стандартный вывод
    1. first-program.tpz: types-ok (2 modules)
    2. first-program.tpz: resolve-ok (2 modules)

    Нет вывода ошибок.

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

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

    Наблюдаемый стандартный вывод
    1. first-program.tpz: types-ok (2 modules)
    2. first-program.tpz: resolve-ok (2 modules)

    Нет вывода ошибок.

    • Пройдено · expected 0; observed 0

    Expected result: checking succeeds. This step checks the program without running its output operation. If checking fails, follow the reported diagnostic code to Diagnostics. The check reference defines input, options, and output channels.

    3. Run the program

    Ссылка

    Run the first program

    Ссылка
    first-program.tpzRun the first programОткрыть песочницу →
    1. import std.io
    2. function greet(name: string) -> string {
    3. return "Hello, {name}!"
    4. }
    5. io.writeLine(greet("Topaz"))
    Зафиксированный выводКод завершения 0
    Hello, Topaz!
    
    $ topaz run first-program.tpz --compiler self · Зафиксировано с Топазом 5.21.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
    Наблюдаемые утверждения · Пройдено · 5.21.3

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

    Наблюдаемый стандартный вывод
    1. Hello, Topaz!

    Нет вывода ошибок.

    • Пройдено · expected 0; observed 0
    • Пройдено · stdout matches the authored expectation
    • Пройдено · stderr matches the authored expectation

    The run command checks the selected unit before execution. The expected program output is shown above; an observation is displayed after the exact source is executed.

    Verification

    Ссылка

    Public Topaz 5.21.3 checked and ran this program successfully in Docs run 42224592687, attempt 2. Both commands exited with code 0, and run printed the expected greeting. The new receipts preserve the observed output from the unchanged fixture and invocation. The earlier receipts remain available.

    Next steps

    Ссылка

    Functions and generics →

    std.io.writeLine →

    check →

    TPZ5523: Duplicate protocol bound →

    Меню

    Загрузка →