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.

    Tour

    First checked and executed program

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

    Prerequisite

    Link

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

    1. Write a function

    Link

    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

    Link

    Check the first program

    Link
    first-program.tpzCheck 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
    first-program.tpz: types-ok (2 modules)
    first-program.tpz: resolve-ok (2 modules)
    
    $ topaz check first-program.tpz --compiler self · recorded with topaz 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Observed assertions · passed · 5.21.3

    Exit code 0.

    Observed stdout
    1. first-program.tpz: types-ok (2 modules)
    2. first-program.tpz: resolve-ok (2 modules)

    No stderr.

    • Passed · expected 0; observed 0
    Observed assertions · passed · 5.21.3

    Exit code 0.

    Observed stdout
    1. first-program.tpz: types-ok (2 modules)
    2. first-program.tpz: resolve-ok (2 modules)

    No stderr.

    • Passed · expected 0; observed 0
    Source evidence

    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

    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

    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

    Link

    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

    Link

    Functions and generics

    std.io.writeLine

    check

    TPZ5523: Duplicate protocol bound

    Menu

    Download