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
Ссылкаimport std.iofunction greet(name: string) -> string {return "Hello, {name}!"}io.writeLine(greet("Topaz"))
first-program.tpz: types-ok (2 modules)
first-program.tpz: resolve-ok (2 modules)
Ожидаемый результат
Ожидаемый результат
Проверка принимает программу. Код завершения 0.
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
first-program.tpz: types-ok (2 modules)first-program.tpz: resolve-ok (2 modules)
Нет вывода ошибок.
- Пройдено · expected 0; observed 0
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
first-program.tpz: types-ok (2 modules)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
Ссылкаimport std.iofunction greet(name: string) -> string {return "Hello, {name}!"}io.writeLine(greet("Topaz"))
Hello, Topaz!
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
Hello, Topaz!
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
Hello, Topaz!
Нет вывода ошибок.
- Пройдено · expected 0; observed 0
- Пройдено · stdout matches the authored expectation
- Пройдено · stderr matches the authored expectation
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
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.