본문으로 건너뛰기
토파즈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 →

    메뉴

    다운로드 →