Words and punctuation
A program is made of words and punctuation. This chapter is about telling them apart.
Numbers
Is 42 a program?
It is a number, one kind of value. Type it at the prompt and Koskari shows it back:
>>> 42
42
Are 0 and -3 numbers too?
Yes. So is 2.5.
Text
How do we write text in a program?
Between double quotes:
>>> "Hello, Koskari!"
"Hello, Koskari!"
The quotes are punctuation. They mark where the text starts and stops
and are not part of it. Koskari shows a value back with its quotes so
you can see it is text; print shows the text alone.
Can we use single quotes instead?
No. A single quote means something else, which chapter 9 uses. Text is
always in " quotes.
Names
What is x?
By itself, a name. A name is a word you choose. It means nothing until you give it a value, which chapter 2 does.
Is print a name?
Yes, and one that already has a value: the thing that puts text on the screen.
Can a name contain digits, or a dash?
Both: x2, add-tax, and total-so-far are names. A name can even
start with a digit, as long as the whole word is not a number: 2x is a
name and 2 is a number.
Parentheses
What does ( do?
It starts a group, and the matching ) ends it. Everything between them
belongs together:
(+ 1 2)
The group is a call, which is chapter 2. The parentheses are not decoration; they tell Koskari where the group begins and ends.
Can a group sit inside another group?
Yes, to any depth:
(+ 1 (+ 2 3))
Spacing
Is (+ 1 2) different from (+ 1 2)?
No. Inside a group, one space or several are the same. Use spaces so that a person can see the pieces.
What about (+1 2)?
That is different. A + or - touching what follows it belongs to it:
+1 is the number 1 with a sign, not the name + beside a 1. So
(+1 2) asks the number 1 to do something with 2, and Koskari
reports an error. Put a space after the name you are calling.
The group rule
Every ( has a matching ). Leave one out and Koskari cannot read the
program at all.