HQ9+

Cliff L. Biffle

The Research

Over winter break of 2000-2001, I ran across Brainf*ck and other extraordinarily esoteric languages. As most students of programming do, I began searching for examples of these languages to help me learn. A great many examples were available, from a great many different authors, but I soon began to notice a pattern: these examples fell neatly into a few categories.

Hello, World!

The quintessential example in any programming language was invented by K&R; in their C tutorial. It's called the Hello World. When a Hello World program is run, it--can you guess?--prints "Hello, world!" to the screen (or teletype or laser-projecting-on-clouds or whatever). This is generally a simple one-line easily-readable statement, which is why it makes for a good first example. (One of the most common exercises for esoteric languages, however, is to make the Hello World as obtuse and and mind-bendingly complex as possible. Take a look at the program that prints "Hi" in Beatnik. The full Hello World would be about twelve times as long.)

99 Bottles of Beer on the Wall

The next set of examples I ran across originated on Usenet many years ago: programs that attempt to print the entire canonical lyrics to "99 Bottles of Beer on the Wall" in the smallest (or craziest) code possible. This is an excellent exercise in recursive, iterative programming, and I knew I had to take it into account.

Quines

The next (particularly cool) set of examples were called "quines." A quine reproduces its source code to the screen. This is more difficult than it sounds, because very few languages have methods for accessing their own source code. Take this pseudocode example:

print "print "print "print .....

As you can see, to simply print the source code of a program as a literal string (like I tried to do there), your program quickly becomes infinitely long. Thus, quines require the programmer to use all sorts of crazy tricks, making them a wonderful exercise.

The Result

As a result of this research, I created a language called HQ9+. HQ9+ is a very simple language consisting of four operations: H, Q, 9, and +. These operations can be used to create any of the types of example programs described above. They work as follows:

H Prints "Hello, world!"
Q Prints the entire text of the source code file.
9 Prints the complete canonical lyrics to "99 Bottles of Beer on the Wall"
+ Increments the accumulator.

HQ9+ is very simple, but allows you to do some things that are very difficult in other languages. For example, here is a program that creates four -- count 'em, four -- copies of itself on the screen:

qqqq

This produces:

qqqq
qqqq
qqqq
qqqq

Wow! Wasn't that straightforward?

Interpreters

HQ9+ was well-accepted by the esoteric languages community, and a flurry of interpreters for it, written in every language available, were released. Most of those have been lost to the winds of time (or rather, the winds of my delete key), but I'm working on re-collecting them for distribution here. Those that I've managed to find are listed below.