build-a-spell-checker / lesson-04.md
Lesson 04 · Words and the dictionary

Tokenizing text into words

Real input is not a tidy list of words - it is prose with punctuation and spaces. Today you build the tokenizer that splits a run of text into the words a checker can actually look up.

The goal

Split a string of text into its words, discarding punctuation and whitespace.

Start here - the target
TO DO
Scenario: Breaking punctuated text into words
Giventhe text "Hello, world! Nice day."
Whenit is tokenized
Thenthe words are exactly ["Hello", "world", "Nice", "day"]
Andtokenizing "" returns an empty list
Background

A checker never sees clean words - it sees sentences. Before you can ask “is this a word?”, you have to find the words inside Hello, world!. That job is tokenization: scan the text and cut it into tokens, where a word is a maximal run of letters and every other character - space, comma, period - is a boundary that ends the current word.

Keep the rule crisp: a token is a run of letters, nothing else. Punctuation is dropped, not attached, so world! yields world and the trailing ! simply ends the token. An empty string yields no words at all. This is the plainest useful tokenizer; the next lessons refine it to remember where each word was and to keep apostrophes inside contractions.

Make it work
// a "word" is a maximal run of letters; everything else
// (spaces, commas, periods, digits) is a separator
func Tokenize(text string) []string {
// walk the runes, collect runs of letters, flush on a non-letter
}
CheckpointDONE
You can turn a line of prose into its list of words. Commit and stop here.