Results and messages

Running a program produces output, and sometimes an error. Reading both is part of programming.

Results at the prompt

When does Koskari show a result?

At the prompt, whenever a line produces a value worth seeing:

>>> (+ 1 2)
3

What about (var x 99)?

Nothing is shown. Giving a name a value is a quiet job; there is no result to look at. Ask for x afterwards and you see 99.

And (print "hi")?

You see hi, because that is what print does. Its own result is nothing worth showing, so the prompt shows only the printed text.

Can we get the last result back?

Yes. An underscore names the value from the last line:

>>> (+ 3 4)
7
>>> (* _ 2)
14

Errors while reading

What if the punctuation is wrong?

Koskari cannot read the program and says so:

>>> ( 1 2 ]
  File "<stdin>", line 1
    ( 1 2 ]
          ^
koskari.exceptions.ReaderSyntaxError: mismatched open and close characters

The last line is the name of the error and what went wrong. The lines above show where: the line you typed, with a caret under the character that stopped the reader. From a file the first line names the file instead of <stdin>.

What should we do with it?

Read the last line of the message. Look back at what you typed and count the ( and ). Fix one thing and run again.

Errors while running

Can the punctuation be right and the program still fail?

Yes. Koskari can read this, but cannot do it:

>>> (/ 1 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in __main__
ZeroDivisionError: division by zero

The last line names the error. Reading was fine; running was not, and the lines above say where.

So there are two kinds of error?

Two kinds. A syntax error means Koskari could not understand the text. A runtime error means it understood the text and something went wrong doing it. The last line of the message tells you which: a reader error ends in ReaderSyntaxError, a runtime error in the name of what failed.

Lines that continue

What if I press Enter before the group is closed?

Koskari waits for the rest. The prompt changes until the ) arrives:

>>> (+ 1
...    2)
3