chapter four

4 Climbing the stack

 

This chapter covers

  • Compile-time parsing and processing
  • Patterns for debugging comptime code
  • Using errors to separate code concerns
  • Practical TCP and HTTP, and how to leverage them with the standard library
  • Ziggy patterns including iterators and generic interfaces

Word games are one of my favorite ways to relax, although I think I take them too seriously to do much relaxing. They are also a fun programming challenge. Words are messy. It feels like there are more exceptions to the rules than there are words that fit the rules. There is no truly clean definition of word being properly part of a language.

A word ladder is a series of words of the same length that each differ in one letter to the last. We’ll now write a word ladder game that will first provide a randomized starting word and then ask you to create the longest ladder you possibly can!

4.1 Climbing the ladder

To make this game work, we’ll use a dictionary to sample starting words and determine whether a player’s words are valid. We’ll make use of comptime to bake our dictionary into the program. Finally, we’ll use the file skills we developed from our journey with cat to read words in and print out feedback. See how it fits together in figure 4.1.

Figure 4.1 The word ladder game
CH04 F01 hinsonhasty

4.1.1 Thinking in comptime

4.1.2 Executing our plan

4.1.3 Talk to me

4.1.4 Core logic

4.1.5 Check it

4.2 Wilda’s want for words

4.2.1 Connecting the web

4.2.2 A poor conversationalist

4.2.3 How do I HTTP?

4.2.4 The HTTP cherry on top

4.2.5 Modularity makes it easy

4.3 Next steps

4.4 Summary