esolang

Mornington Crescent

Every instruction is a trip on the London Underground. Stations are memory cells, and the program must end at Mornington Crescent.

Timwi, 2013 · Turing complete: yes · ●●○ moderate · esolangs.org

The idea

Mornington Crescent is a running joke from the BBC radio panel show I'm Sorry I Haven't a Clue. Players take turns naming London Underground stations, pretending to follow elaborate strategic rules, until someone "wins" by saying Mornington Crescent. The joke is that the rules do not exist.

Read the story

In 2013 the esolangs.org user Timwi turned the joke into a real language, with real rules. A program is a list of journeys: Take Northern Line to Euston. Each journey must be possible on the real Tube map. Execution starts at Mornington Crescent, and a valid program must end there.

It is camouflage of a sort, since a program reads like a set of travel directions. But mostly it is a punchline that happens to be Turing complete.

The machine

  • Every station holds a value: a string or an arbitrary-size integer. At the start, each holds its own name: Waterloo holds "Waterloo".
  • There is one accumulator, which starts as the whole of the input.
  • An instruction Take <Line> Line to <Station> is legal only if that line connects the current station to the destination. Then the pointer moves there and the accumulator swaps with the station's value.

Some stations do something else instead of swapping:

StationDoes
UpminsterAdd (if both are integers)
Chalfont & LatimerMultiply
Cannon Street, Preston RoadDivide, remainder
Seven SistersSet the accumulator to 7
Charing CrossCharacter ↔ code point
Parsons GreenParse the first integer out of a string
PaddingtonConcatenate strings
Turnpike LaneReverse a string
Bank / HammersmithStoring at Bank also copies the value to Hammersmith, which keeps it
Temple, Angel, Marble ArchPush a return point; jump back if the accumulator is non-zero; pop
Mornington CrescentPrint the accumulator and stop

So you get numbers by visiting Seven Sisters, and loops by going to Temple and later to Angel. An illegal journey (a line that does not stop there) is a runtime error.

Example

A program that prints a word without ever writing it down:

A program that prints a word without ever writing it down:

Take Northern Line to Euston
Take Northern Line to Mornington Crescent

Traced by hand: both stations are on the Northern line. Arriving at Euston swaps the accumulator (the input) with Euston's value, so the accumulator now holds "Euston". Arriving at Mornington Crescent prints it. Output: Euston. The input is left behind at Euston.

For scale, the shortest Hello World listed on esolangs.org, by Martin Ender, is 110 journeys. Most of them shuttle values between Upminster, Hammersmith and Paddington to build character codes and glue strings.

Patterns it teaches

  • Camouflage: code that looks like travel directions. It only fools someone who has never seen a program.
  • Turing completeness: shown by translating a register machine. Stations are registers, and the Tube network is connected enough that any station can be reached.

Try this

  1. Trace what this prints: Euston (Northern), Seven Sisters (Victoria), Euston (Victoria), Mornington Crescent (Northern). Why is it not 7?
  2. Now write a program that does print 7. Every ordinary station you pass through swaps, so plan where the 7 waits.
  3. Hard: add two numbers read from input, using Parsons Green and Upminster.

Further

Non-interactive IO

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