Scene 1 By the shelf
MomoAs promised. Go and find out with Tinker.
LineyTinker, what shows up on the screen?
TinkerLet's leave Momo's cards on the shelf.I'll take the main.tpz file you're written in.
The Life of Code 05
When does the actual calculating happen?
Momo's cards are still on the shelf.
Now it's Tinker's turn to run a program.
What shows up on the screen, and when?
So that's your guess.
Let's read the records with Tinker.
MomoAs promised. Go and find out with Tinker.
LineyTinker, what shows up on the screen?
TinkerLet's leave Momo's cards on the shelf.I'll take the main.tpz file you're written in.
TinkerAt my bench, checking comes first.Running comes after.
TamiThis file passed its checks!
LineyHuh? No 3!
TinkerThe window's blank.What do the note tray and the finish light tell us?
TinkerLet's put the same addition in a new program.This one has a line to announce the start and a line to print the result.
LineyFinally, 3!
TinkerYou get only what you asked to have written, in the order you asked.
TwinI'm almost the same as Liney. I just have "apple" where the 2 was.I'll at least get to print start, right?
TinkerHmm. Let's read the record together.
What did the three files really leave behind?
Let's read it on Tinker's Run Board.
Experiment
How far did each program get?
Tinker tried topaz run on each of the three files and kept the records.
Read the window, the note tray and the finish light of the three slips to see how far each program got.
A 0 on the finish light usually means the command finished successfully.
The window and note tray show the text saved from that command.
Topaz 5.21.1 run records
Byte for byte the same file Momo copied onto cards.
1 + 2Command topaz run main.tpz
Empty
Empty
0
Tinker used topaz run main.tpz. The file passed its checks and finished running. Nothing in it asks for output, so the window is blank. The note tray is empty too, and the finish light shows 0.
The window is empty. So what's in the note tray, and what does the finish light say?
topaz check aloneCommand topaz check main.tpz
main.tpz: types-ok (1 module)
main.tpz: resolve-ok (1 module)
Empty
0
The check alone finished with 0 too. Its window held two lines of check results instead of the program's text.
"Empty" is a label on the board. The original file contains zero bytes.
cb898749d76e51fdaf6c6636920ccdb4f415fc1cffd1e2497636b38cc24698078dbc4723d2c243bfde6f13f4e23ccbd33f409d24173d6b99a71d957581183cefWe followed the same steps twice with the same version. Both runs gave us identical bytes in standard output and standard error, and the exit codes matched.
We also tried the same command on this input with versions 5.21.0 and 5.21.1. The bytes in each output stream matched across versions, as did the exit code.
The top line brings in io, the tool that writes to the screen. Inside "{result}", the value stored in result goes in as text.
import std.ioio.writeLine("start")let result = 1 + 2io.writeLine("{result}")Command topaz run main.tpz
start
3
Empty
0
The window shows start and then 3. The program wrote them while it ran.
The window shows start and 3. If the program never ran, who wrote them?
topaz check aloneCommand topaz check main.tpz
main.tpz: types-ok (2 modules)
main.tpz: resolve-ok (2 modules)
Empty
0
The check alone finished with 0 too. Its window held two lines of check results instead of the program's text.
"Empty" is a label on the board. The original file contains zero bytes.
5f4c63f0f43f717035c441ab5c99388451a7660d7be07d32441a3cece60bf7138dbc4723d2c243bfde6f13f4e23ccbd33f409d24173d6b99a71d957581183cefWe followed the same steps twice with the same version. Both runs gave us identical bytes in standard output and standard error, and the exit codes matched.
We also tried the same command on this input with versions 5.21.0 and 5.21.1. The bytes in each output stream matched across versions, as did the exit code.
Only line 4 differs from B. Where the 2 was, it says "apple".
import std.ioio.writeLine("start")let result = 1 + "apple"io.writeLine("{result}")Command topaz run main.tpz
Empty
error[TPZ5001]: `+` needs matching int, float, string, BigInt, or Decimal operands, found `int` and `string`
--> main.tpz:4:14
|
4 | let result = 1 + "apple"
| ^^^^^^^^^^^
main.tpz: 1 type diagnostic
The diagnostic points to the whole expression 1 + "apple" on line 4. The eleven carets start under the 1.
1
The last line of the note says type diagnostic, a diagnostic from the type check. That is why even the start on line 3 never appeared.
An empty window alone can't tell you. Try reading the first and last lines of the note.
topaz check aloneCommand topaz check main.tpz
Empty
error[TPZ5001]: `+` needs matching int, float, string, BigInt, or Decimal operands, found `int` and `string`
--> main.tpz:4:14
|
4 | let result = 1 + "apple"
| ^^^^^^^^^^^
main.tpz: 1 type diagnostic
1
Checking the same file with topaz check alone put the same note in the tray.
"Empty" is a label on the board. The original file contains zero bytes.
2b65f5c87a2d4a89eea4901f8962567a44b9f614dcbe7e4ec3f37521fd0ecd468dbc4723d2c243bfde6f13f4e23ccbd33f409d24173d6b99a71d957581183cefWe followed the same steps twice with the same version. Both runs gave us identical bytes in standard output and standard error, and the exit codes matched.
We also tried the same command on this input with versions 5.21.0 and 5.21.1. The bytes in each output stream matched across versions, as did the exit code.
Tag all three slips to open the discovery card.
Two blank windows, two reasons
A and C both left the window empty.
A ran to the end but had no line asking for output. C was stopped at the check and never started running.
Read the note tray and the finish light along with the window.
The bench, the lever and the lights are part of the story. The text in the window and the note tray comes from real records made in advance.
The real story
The text in the window is standard output. The text in the note tray is standard error.
Standard output and standard error are two streams that programs and tools can write to. Results usually go to standard output, and diagnostics or notices to standard error. The two streams can be collected separately.
The number on the finish light is the exit code of the topaz run command. Usually 0 reports success, and a nonzero number reports failure. In these records, A and B finished with 0. C stopped at the check and finished with 1.
An interpreter reads a program's instructions and carries out the operations they describe. It may use another form of the program internally.
In Topaz 5.21.1, topaz run checks the source and runs the checked program with an interpreter. When the command finished, the working folder held just main.tpz.
In this version, topaz run checks the source first. When it finds a type error like the one on slip C, it reports the error and stops. The program never reaches the line that prints start.
The program wrote 3 to the screen when it ran.
The addition gives result its value. The last line puts that value into a string and writes 3 to standard output.
We can tell which line printed 3. Some compilers can work out a value like this before the program runs. This run record doesn't tell us exactly when the addition was first worked out.
We also observed the program on slip B. Here are three operations from its 44-line record. The addition points first to 1, then to 2. Here the addition sits inside the let statement that gives its value the name result.
| What it does | The record's words | Representation | Sits inside |
|---|---|---|---|
| Two-value calculation | binaryadd | i64 | The statement that names a value |
| Integer | integer1 | i64 | Two-value calculation |
| Integer | integer2 | i64 | Two-value calculation |
Open all 44 lines of slip B's operation record, opens in a new tab
We gave topaz run the same source file. Its record shows what the command wrote and how it finished. It doesn't show the internal forms used along the way.
No. In the Language Tour, the Python program printed 시작 ("start") on its first line. It stopped with a TypeError when it reached "3" + 4 on the next line.
When a tool checks and when it runs differs from tool to tool.
In one line
The text a program writes on the screen appears when that program runs.
topaz run checks the whole program first and starts running it only if the check passes.
Does a blank window mean the program never ran? Find one clue on slip A and one on slip C.
Not necessarily.
On slip A, the note tray is empty and the finish light shows 0. The file passed its checks and finished running, but no line asked for output.
On slip C, the note tray ends with type diagnostic and the finish light shows 1. The check stopped it before it started running.
Now you know what else to read when the window stays blank.
Field GuideRevisit these wordsInterpreterStandard Output and Standard Error
Next story
LineySo who made the tool that checked me?
At the end of the path, a tiny sprout pokes up out of a flowerpot.
Is a compiler a program someone wrote, too?
Next time, let's follow where the compiler came from.