Reference
How syntax works
Syntax is the small stuff that holds a program together — brackets, keywords, one symbol versus another. Most first mistakes are syntax, not ideas. The lab lets you take the training wheels off one at a time: tap tiles into the blanks, then type with a palette, then write it all yourself. Here are the syntax rules it drills. Open the syntax lab →
- print( … ) uses round brackets
A function call puts its value inside round ( ) brackets — never square [ ] or curly { }.
print(6 + 4)prints
10 - One = stores · two == asks
A single = puts a new value into a box. Two == only ASKS "are these equal?" and stores nothing.
var n = 3 n = n + 5 print(n)prints
8 - if uses curly braces { }
The body that runs "if it is true" goes inside curly braces. Swift has no "then" and no "end".
if 7 > 5 { print("big") }prints
big - ..< stops before · ... includes
0 ..< 3 is 0, 1, 2 (not 3). 0 ... 3 would add the 3. Pick the one that gives the count you want.
for i in 0..<3 { print(i) }prints
0 ⏎ 1 ⏎ 2 - return hands a value back
Inside a function, return sends the answer back to whoever called it. print would only show it.
func double(n: Int) -> Int { return n * 2 } print(double(5))prints
10 - .append and .count are the list words
A Swift list grows with .append(x) and is measured with .count — not add / push / length / size.
var xs = [1] xs.append(2) print(xs.count)prints
2 - && needs both · || needs one
&& (AND) is true only when BOTH sides are true; || (OR) is true when either is. Swift uses the symbols.
if true && false { print("both") } else { print("not both") }prints
not both - Whole numbers divide with /, but // is a comment
17 / 5 is 3 (the remainder is dropped). Watch out: // does not divide — it starts a comment!
print(17 / 5)prints
3
Where this idea comes from
Marks that tell you how to read
For centuries, Latin was copied with no spaces between words: a reader had to find where each word ended. Scribes in Ireland and England began putting spaces between words in the 600s and 700s.
One thing to hold: Pietro Bembo’s little book De Aetna, printed by Aldus Manutius in Venice in 1496. It has the first printed semicolon: a comma with a dot on top, for a pause longer than a comma and shorter than a full stop.
Why it matters: A space, a semicolon or a quotation mark changes how a sentence is read, and in code it changes what the computer does. The typewriter gave quotation marks one straight key for both ends, and the computer code letters of 1963 (ASCII) kept only straight quotes. That is why code still uses typewriter quotes, and why a phone’s curly “smart” quotes have to be turned straight.
What we don’t know: Historians still argue how much word spacing changed reading itself, for example whether it made silent reading common. Who first wrote a semicolon by hand is not known.
Dates:
- 600s Scribes in Ireland and England begin putting spaces between words.
- 1496 The first printed semicolon, in a book from Aldus Manutius’s press in Venice.
- 1963 ASCII, the code computers use for letters, keeps only straight quotes.
Every program in SyntaxForge is written in a teaching subset of the Swift language — the same rules real programmers use, kept small so you can build it by hand. Build one →
After this: TraceForge (run it in your head, one line at a time). The twelve Syntax Bridge programs are the same in all three: built here, read in TraceForge, and handed to the compiler in KindForge, often with the tempting wrong tile.