A deep dive into the examples in the Inform Recipe Book

I am beginning a project in which I am going to spend time manually entering and playing with every one of the examples in the Inform books. There are literally hundreds of examples.

When I was a kid, my step-dad’s mom gave me an Apple //c+ that she got from her work. This was around the time when PCs were starting to assert dominance over the home computer market.

At the same time, a math teacher at my weird alternative school introduced me to Apple Basic (the Apple ][e being pretty much ubiquitous in K-12 institutions, even weird little alternative schools).

Where am I going with this? Well, the //e and //c+ were pretty similar in a lot of ways, but generally speaking, the //e used 5.25 inch-floppy disks whereas the //c+ used 3.5-inch floppy disks. So there wasn’t an easy way for me to play at home any of those Apple Basic games I discovered at school.

There wasn’t an easy way. There was a hard way.

I am not the only person of my generation (that liminal space between Gen X and Millenials) who rode their bikes home from school with printouts of BASIC programs (probably on dot matrix paper) and then spending hours upon hours typing those pages in, line by line.

If I was lucky, I’d end up with a working copy of ELIZA or whatever and maybe, just maybe, I learned a little bit about computer programming in the process.

A few years later when I was teaching myself Turbo Pascal, I did so cuddled up to a book (probably by Greg Perry) and typing in the examples. There was a lot I didn’t understand, sure, but over time, things started to make sense to me in a way I don’t think they would have if I hadn’t had to manually enter them.

The Inform IDE comes with some great (albeit sometimes frustrating) documentation. I’ve seen some valid criticisms of it, but the fact is it’s jam packed with information. It’s dense and overwhelming. It’s verbose in places where perhaps it need not be and it’s often difficult to know what you need to know in order to achieve a particular effect. The knowledge is there, though.

They say a picture is worth a thousand words and I would say many of the examples in Inform’s Recipe Book (which has hundreds of small-to-medium sized examples of varying levels of complexity) are just as valuable. And a lot of them are probably things a lot of people will never think of trying because they don’t seem immediately applicable to whatever problem they are currently trying to solve.

For example…

"Number Study" [example 240]

Abstraction is a room.

Parity relates a number (called N) to a number (called M) when N minus M is even.

Joint magnitude relates a number (called N) to a number (called M) when N plus M is greater than 7.

To chart (R - a relation of numbers):
    repeat with N running from 1 to 5:
        repeat with M running from 1 to 5:
            if R relates N to M, say "[N] <=> [M] by [R][line break]";

When play begins:
    let L be { parity relation, joint magnitude relation };
    repeat with R running through L:
        chart R.

This comes from WI §13.14. Relations as values in their own right. It’s also referenced in chapter 10 (Physics: Substances, Ropes, Energy and Weight) of the Recipe Book in section RB §10.11 Mathematics.

I’ll be honest: I found this purely at random. I wasn’t looking for it, specifically. I’d been hoping to learn more about the concept of relations and did a substring search to find all the examples that mentioned relations at all, the theory being that even an example that wasn’t emphasizing relations could still be useful for learning more about them. As a result, I now understand some things about relations that I didn’t before:

  1. You can reference them like other kinds of values.
  2. You can even put them in lists (and perhaps, tables? I’ll have to research that one more).

tl;dt (too long, didn’t type)

The Inform books have a convenient feature to allow you to copy entire examples into a project simply by clicking on the icon at the top of the example. And while this is a good feature to quickly get an example running, so much is lost by not manually entering the examples and inhabiting the text as it flows through your fingers. Maybe it’s just because of my own neurodivergence, but I really do believe that anybody who spends the time to type these examples in are going to get so much more from them, especially if they are new to the language.

Learning is, in my experience, a heuristic process. You learn things by making mistakes. Any typos made while entering an example create an opportunity to hone your debugging skills. Typing things in one at a time also leads to questions arising and helps you to get a feel for different ways to organize your code, name things, and get an intuitive sense of the language’s grammar.