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

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

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

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

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

    Библиотека

    std.io.writeLine

    Writes a string as a line and returns ().

    writeLine(line: string) -> ()
    Модуль
    std.io →
    Получатель
    Неприменимо
    Минимальное число аргументов
    1
    Максимальное число аргументов
    1

    Signature and parameters

    Ссылка

    Доступность

    Включено по умолчанию · Не определено

    Import std.io in language mode 5.21.

    The selected 5.21 module exports writeLine. Installed default-distribution execution is tracked by the shared check/run fixture.

    Получатель

    Ограничения параметров

    std.io.writeLine takes one string argument. On a successful host write, it writes that string followed by a newline to standard output and returns ().

    Результат

    std.io.writeLine takes one string argument. On a successful host write, it writes that string followed by a newline to standard output and returns ().

    Эффекты

    std.io.writeLine takes one string argument. On a successful host write, it writes that string followed by a newline to standard output and returns ().

    Ошибки

    A failed std.io.writeLine call raises a dedicated host-output runtime fault at that call.

    The Topaz 6.0 fault is TPZ4010. Successful writes retain the normal unit result.

    Import std.io and call io.writeLine with one string argument.

    Result and effects

    Ссылка
    Правилоtopaz.rule.std-io.write-line

    writeLine contract

    std.io.writeLine takes one string argument. On a successful host write, it writes that string followed by a newline to standard output and returns ().

    Причина

    One string argument keeps value formatting separate from output. Appending a newline makes each successful call complete a line.

    Правилоtopaz.rule.std-io.write-line.normal-boundaries

    String and newline boundaries

    std.io.writeLine preserves the supplied string and appends one newline on a successful host write. An empty string writes one newline. Unicode characters and embedded newlines are retained. The function returns (); a non-string argument is a type error. A failed host write produces a structured runtime fault.

    Причина

    Preserving input avoids changing Unicode text or embedded line breaks. One appended newline gives empty and nonempty strings the same output rule.

    Failures and boundaries

    Ссылка
    Правилоtopaz.rule.std-io.write-line.host-failure

    Host write failures

    A failed std.io.writeLine call raises a dedicated host-output runtime fault at that call.

    The Topaz 6.0 fault is TPZ4010. Successful writes retain the normal unit result.

    Причина

    Keeping the unit signature preserves the existing call contract. A structured fault makes a host write failure visible to the program runner.

    Host output diagnostic

    Ссылка

    Host output failure

    Семейство
    topaz
    Этап
    run
    Код
    TPZ4010
    Операция
    std.io.writeLine

    Причина и условия

    A failed std.io.writeLine call raises a dedicated host-output runtime fault at that call.

    The Topaz 6.0 fault is TPZ4010. Successful writes retain the normal unit result.

    Действия

    Use a working standard output sink. Keep output recovery in the embedding host until structured fault production is available.

    Example

    Ссылка

    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

    Write empty, Unicode, and multiline strings

    Ссылка
    write-line-boundaries.tpzWrite empty, Unicode, and multiline stringsОткрыть песочницу →
    1. import std.io
    2. io.writeLine("")
    3. io.writeLine("토파즈")
    4. let result: () = io.writeLine("a\nb")
    5. io.writeLine("{result}")
    Ожидаемый выводКод завершения 0
    
    토파즈
    a
    b
    ()
    
    $ topaz run write-line-boundaries.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    Ожидаемый стандартный вывод
    1. 토파즈
    2. a
    3. b
    4. ()

    Reject a non-string argument

    Ссылка
    write-line-bad.tpzReject a non-string argumentОткрыть песочницу →
    1. import std.io
    2. io.writeLine(1)
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check write-line-bad.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

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

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      write-line-string-argument-type at write-line-bad.tpz:2:14

    A successful write has a Unit result

    Ссылка
    write-line-unit-result.tpzA successful write has a Unit resultОткрыть песочницу →
    1. import std.io
    2. let result: () = io.writeLine("hello")
    Ожидаемый выводКод завершения 0
    Нет стандартного вывода.
    $ topaz check write-line-unit-result.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    A write result cannot use Result propagation

    Ссылка
    write-line-not-result.tpzA write result cannot use Result propagationОткрыть песочницу →
    1. import std.io
    2. function greeting() -> Result<(), string> {
    3. io.writeLine("hello")?
    4. Ok(())
    5. }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check write-line-not-result.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

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

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      result-required-for-propagation at write-line-not-result.tpz:4:3

    Related entries

    Ссылка

    First checked and executed program →

    check →

    Functions and generics →

    TPZ5001 →

    Меню

    Загрузка →