esolang

HQ9+

Four commands, each solving one classic programming exercise in one character. Hello World is H. A quine is Q. The fourth command does nothing anyone can see.

Cliff L. Biffle, 2001 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 2 examples and 2 known programs · Test method

Run it

Hello World

Expected output

hello, world

Output


The idea

Every new language gets judged on the same few exercises: print Hello World, print its own source (a quine), print the lyrics of "99 Bottles of Beer". Cliff L. Biffle's 2001 joke language makes each of them a single instruction.

Read the story

So HQ9+ wins at exactly the tasks people use to compare languages, and can do nothing else. It has no loops, no input and no way to compute. The + command increments an accumulator that no other command ever reads.

It is a parody of benchmark culture, and of code golf in particular: if your language is allowed to have a built-in for the task, the task stops meaning anything.

The machine

An accumulator nobody can see, and the program's own source.

CharDoes
HPrint "Hello, world!"
QPrint the program's entire source code
9Print the full lyrics of "99 Bottles of Beer"
+Add 1 to the accumulator

Exact output text varies between implementations, and the original example suggests commands are not case-sensitive. The player follows that, and ignores every other character.

Example

qq is no longer a quine: each q prints the whole two-character program, so the output is twice as long as…
Expected: Hello, world! then HQ+
Expected: Q a one-character quine
Expected: qqqq Q prints the whole program each time

qq is no longer a quine: each q prints the whole two-character program, so the output is twice as long as the source.

Checked examples

Example

Expected output

q

Output


Quirks

  • HQ9+ ignores case.
  • A run stops after 3,000,000 steps.

Try this

  1. Predict the first two lines of output of +Q9H, then run it.
  2. Which HQ9+ programs are quines? Describe all of them.
  3. Design one more command for HQ9+ that would make it Turing complete. (Several variants on esolangs.org try exactly this.)

Patterns it teaches

  • Quine: by cheating. A real quine has to build its own text from a "data" half and a "code" half. HQ9+ reads its source, which is exactly what quine rules forbid.
  • Code golf: the reductio. Golf languages like GolfScript and Jelly are serious versions of the same idea: built-ins that make common tasks short.
  • Turing completeness: a clean non-example, and a reminder that "it can print Hello World" says nothing about power.

Further

Accumulator-based

Write your own in Run Convert a program from HQ9+

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: hq9.

Command line

shib run hq9 -e 'H'
shib manual hq9

Source

Module
langs/classic.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org