Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Library

    std.io.writeLine

    Writes a string as a line and returns ().

    writeLine(line: string) -> ()
    Module
    std.io
    Receiver
    Not applicable
    Minimum arity
    1
    Maximum arity
    1

    Signature and parameters

    Link

    Availability

    Included by default: Pending

    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.

    Source evidence

    Receiver

    Parameter constraints

    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 ().

    Result

    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 ().

    Effects

    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 ().

    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.

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

    Result and effects

    Link
    Ruletopaz.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 ().

    Why

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

    Source evidence
    Ruletopaz.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.

    Why

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

    Source evidence

    Failures and boundaries

    Link
    Ruletopaz.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.

    Why

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

    Source evidence

    Host output diagnostic

    Link

    Host output failure

    Family
    topaz
    Phase
    run
    Code
    TPZ4010
    Operation
    std.io.writeLine

    Cause and conditions

    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.

    Response

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

    Source evidence

    Example

    Link

    Run the first program

    Link
    first-program.tpzRun the first programOpen in Playground
    1. import std.io
    2. function greet(name: string) -> string {
    3. return "Hello, {name}!"
    4. }
    5. io.writeLine(greet("Topaz"))
    Recorded outputexit 0
    Hello, Topaz!
    
    $ topaz run first-program.tpz --compiler self · recorded with topaz 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. Hello, Topaz!
    Observed assertions · passed · 5.21.3

    Exit code 0.

    Observed stdout
    1. Hello, Topaz!

    No stderr.

    • Passed · expected 0; observed 0
    • Passed · stdout matches the authored expectation
    • Passed · stderr matches the authored expectation
    Observed assertions · passed · 5.21.3

    Exit code 0.

    Observed stdout
    1. Hello, Topaz!

    No stderr.

    • Passed · expected 0; observed 0
    • Passed · stdout matches the authored expectation
    • Passed · stderr matches the authored expectation
    Source evidence

    Write empty, Unicode, and multiline strings

    Link
    write-line-boundaries.tpzWrite empty, Unicode, and multiline stringsOpen in Playground
    1. import std.io
    2. io.writeLine("")
    3. io.writeLine("토파즈")
    4. let result: () = io.writeLine("a\nb")
    5. io.writeLine("{result}")
    Expected outputexit 0
    
    토파즈
    a
    b
    ()
    
    $ topaz run write-line-boundaries.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 토파즈
    2. a
    3. b
    4. ()
    Source evidence

    Reject a non-string argument

    Link
    write-line-bad.tpzReject a non-string argumentOpen in Playground
    1. import std.io
    2. io.writeLine(1)
    Expected outputNonzero exit
    No stdout.
    $ topaz check write-line-bad.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 write-line-string-argument-type at write-line-bad.tpz:2:14
    Source evidence

    A successful write has a Unit result

    Link
    write-line-unit-result.tpzA successful write has a Unit resultOpen in Playground
    1. import std.io
    2. let result: () = io.writeLine("hello")
    Expected outputexit 0
    No stdout.
    $ topaz check write-line-unit-result.tpz --compiler self --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    A write result cannot use Result propagation

    Link
    write-line-not-result.tpzA write result cannot use Result propagationOpen in Playground
    1. import std.io
    2. function greeting() -> Result<(), string> {
    3. io.writeLine("hello")?
    4. Ok(())
    5. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check write-line-not-result.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 result-required-for-propagation at write-line-not-result.tpz:4:3
    Source evidence

    Related entries

    Link

    First checked and executed program

    check

    Functions and generics

    TPZ5001

    Menu

    Download