본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    투어

    모듈과 표준 라이브러리

    Move a greeting into another source file, import it, and print through the standard library.

    Prerequisite

    링크

    Use Topaz 5.21.3 with SELF and language mode 5.21. Work in one directory containing the two files in this chapter.

    1. Split the program

    링크

    Save both files with the shown names. greeting.tpz exports greet; main.tpz selects it and imports std.io as io. Keep the output call in main.tpz.

    2. Check the entry file

    링크

    Check both source files

    링크
    main.tpzCheck both source files플레이그라운드 열기 →
    1. import greeting { greet }
    2. import std.io
    3. io.writeLine(greet("Topaz"))
    기록된 출력종료 코드 0
    main.tpz: types-ok (3 modules)
    main.tpz: resolve-ok (3 modules)
    
    $ topaz check main.tpz --compiler self · 기록에 사용한 토파즈 5.21.3
    greeting.tpzCheck both source files플레이그라운드 열기 →
    1. export function greet(name: string) -> string {
    2. return "Hello, {name}!"
    3. }
    기대 결과

    기대 결과

    검사가 프로그램을 받아들입니다. 종료 코드 0.

    관측한 단언 · 통과 · 5.21.3

    종료 코드 0.

    관측한 표준 출력
    1. main.tpz: types-ok (3 modules)
    2. main.tpz: resolve-ok (3 modules)

    표준 오류 출력 없음.

    • 통과 · expected 0; observed 0

    Run the command from the directory containing both files. Checking should succeed. If module resolution fails, check the file name and location, then follow the reported diagnostic.

    3. Run the program

    링크

    Run the entry file

    링크
    main.tpzRun the entry file플레이그라운드 열기 →
    1. import greeting { greet }
    2. import std.io
    3. io.writeLine(greet("Topaz"))
    기록된 출력종료 코드 0
    Hello, Topaz!
    
    $ topaz run main.tpz --compiler self · 기록에 사용한 토파즈 5.21.3
    greeting.tpzRun the entry file플레이그라운드 열기 →
    1. export function greet(name: string) -> string {
    2. return "Hello, {name}!"
    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

    The expected program output is Hello, Topaz! followed by a newline. The imported function supplies the greeting; std.io.writeLine writes it.

    Imports and package setup

    링크

    import greeting { greet } selects an exported name; it does not install a dependency. These commands pass a source-file entry. Without an entry operand, package mode loads topaz.toml. See the check reference.

    Verification record

    링크

    Public Topaz 5.21.3 checked and ran this two-file program successfully in Docs run 42224592687, attempt 2. The recorded exit codes and output were compared with this page's current product assertions. The fixture files, invocation and expected output were unchanged.

    Modules and visibility defines imports and exported declarations. Packages, locks and targets describes package inputs.

    Next steps

    링크

    Functions and generics →

    std.io.writeLine →

    check →

    First checked and executed program →

    메뉴

    다운로드 →