esolang

INTERCAL

The first esolang: a parody of 1970s languages where you must say PLEASE, but not too often, and nothing works the way you expect.

Don Woods and James M. Lyon, 1972 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: Hello, World!

The idea

Two Princeton students, Don Woods and James M. Lyon, wrote INTERCAL in 1972 as a joke. The goal was a language that shared nothing with any other. The full name is "Compiler Language With No Pronounceable Acronym", which does not abbreviate to INTERCAL.

Read the story

The joke is aimed at the culture of programming, not at computation. There is no plain assignment of a large number, no ordinary arithmetic, no GOTO. Instead there are bit operators with odd names, a politeness check, and statements that switch other statements off.

It lay dormant until 1990, when Eric S. Raymond wrote C-INTERCAL. That version added the most famous feature, COME FROM, taken from a 1973 spoof article about GOTO-less programming. INTERCAL is still maintained today, which is perhaps the best joke of all.

The machine

Variables come in four kinds: .1 (16-bit, "spot"), :1 (32-bit, "two-spot"), and arrays of each (,1 and ;1). Constants are written #3. Every statement starts with DO, PLEASE or PLEASE DO.

FeatureDoes
.1 <- #3Assignment ("gets")
a $ bMingle: interleave the bits of two 16-bit values into one 32-bit value
a ~ bSelect: keep the bits of a where b has a 1, packed to the right
& V ?Unary AND, OR, XOR: each bit with the next higher bit; the top bit pairs with bit 0
(10) NEXTCall line label 10, pushing a return point (RESUME and FORGET pop them)
COME FROM (10)After label 10 runs, jump here. The jump is written at the destination
ABSTAIN FROM (10)Switch a line (or all statements of a kind) off; REINSTATE switches it back on
READ OUT / WRITE INOutput in Roman numerals; input as spelled-out digits (ONE TWO). Arrays move bytes instead
GIVE UPStop

The politeness rule: if too few statements say PLEASE, C-INTERCAL rejects the program as insufficiently polite. If too many do, it is rejected as overly polite. Roughly a fifth to a third is safe. Statements can also carry %50, a chance of running at all.

A statement that does not parse is not an error until it runs. Then it stops the program with error E000 and prints itself. So PLEASE NOTE THAT ... is a comment: it reads as PLEASE NOT followed by nonsense, and a NOT statement never runs. Every error ends the program with a message like ICL079I PROGRAMMER IS INSUFFICIENTLY POLITE, then CORRECT SOURCE AND RESUBNIT.

Example

The original manual's joke: the simplest way to store 65536 in a 32-bit variable is DO :1 <- #0$#256.

The original manual's joke: the simplest way to store 65536 in a 32-bit variable is DO :1 <- #0$#256. Mingle puts the right operand's bits in the even positions and the left's in the odd positions, so bit 8 of 256 lands at bit 16.

A small program that mingles 3 and 5, then takes them apart again:

DO .1 <- #3
DO .2 <- #5
DO :1 <- .1 $ .2
PLEASE DO .3 <- :1 ~ #42
DO .4 <- :1 ~ #21
PLEASE READ OUT :1
DO READ OUT .3
DO READ OUT .4
DO GIVE UP

Traced by hand:

  • 3 $ 5: 3 is 011, 5 is 101. Interleaved (left bit, right bit, from the top) gives 011011 = 27.
  • 27 ~ 42: 42 is 101010, so select keeps bits 1, 3 and 5 of 27: 1, 1, 0, packed into 011 = 3.
  • 27 ~ 21: 21 is 010101, so it keeps bits 0, 2 and 4: 1, 0, 1, packed into 101 = 5.

So it prints XXVII, III and V. Each numeral comes with an extra line above it for overbars (a bar means "times 1000"), blank for small numbers. Select with an alternating mask is the inverse of mingle. Two of the nine statements say PLEASE, which is polite enough.

Run it

Hello world, the way TIO tests it.

Hello world, the way TIO tests it. Reading out an array prints bytes, in the "Turing Text Model": each number is subtracted from the previous character's code, and the 8 bits of the result are reversed. H is 01001000, reversed 00010010 = 18, and 0 − 238 is 18 modulo 256.

Expected: XXVII III V

The example above.

Expected: XXXII XVI VIII IV II I

A loop with no IF and no GOTO. .1 ~ #65534 halves .1 (it keeps every bit but the lowest). The long line at (2) makes .5 1 when .1 is zero and 2 otherwise. RESUME .5 then pops one or two NEXT returns. Popping two lands back after (11), where COME FROM (11) grabs control and loops. Popping one lands after (1), which FORGETs the other return and gives up.

Expected: ICL079I PROGRAMMER IS INSUFFICIENTLY POLITE ON THE WAY TO 4 CORRECT SOURCE AND RESUBNIT

Three statements and no PLEASE: rejected before it runs. WRITE IN .1 reads a number as words, so the input ONE TWO THREE gives 123.

Patterns it teaches

  • Hostile design: the template for every "make it unpleasant" language since, including Malbolge. INTERCAL is hostile by bureaucracy, not by cryptography.
  • Turing completeness: despite everything it is universal; it can simulate P′′. Being awful and being weak are different things.
  • Nondeterminism: %50 makes a statement run half the time.

Try this

  1. Work out #1 $ #1 and #65535 $ #0 by hand.
  2. Write a line that swaps the two halves of a 32-bit value using only $ and ~.
  3. Hard: change the loop above so it stops at 4 instead of 1, and add one PLEASE too many to see E099.

Further

Also in Hostile

Write your own in Run Convert a program from INTERCAL

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run intercal -e 'DO WRITE IN .1
DO WRITE IN :1
DO READ OUT .1 + :1
PLEASE GIVE UP' --input 'ONE TWO THREE
FOUR OH OH OH OH
'
shib manual intercal

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/intercal.js

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

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