esolang

Chicken

The only word is "chicken". The number of chickens on a line is the instruction, and the code lives on the same stack as the data.

Torbjörn Söderstedt, 2013 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: chicken

The idea

Torbjörn Söderstedt made Chicken in 2013. It was inspired by a famous joke paper by Doug Zongker, "Chicken Chicken Chicken: Chicken Chicken", a complete scientific paper (and talk) in which every word is "chicken".

Read the story

The disguise is total: a program is lines of chicken chicken chicken. Underneath is a small stack machine. Each line's count of chickens is one opcode. The count is unary: a line of 75 chickens means "push 65".

The deeper trick is where the code goes. The program is loaded onto the same stack it computes on. So the machine can read, overwrite and jump into its own code.

The machine

The stack starts with two registers, then the code, then free space:

CellHolds
0A reference to the stack itself
1The user input (a string)
2, 3, …One cell per line: its chicken count. Then an extra 0 (exit)
after thatThe working stack

Execution starts at cell 2. Values behave like JavaScript values, as in the original implementation.

ChickensNameDoes
0axeExit. An empty line is 0, so blank lines matter
1chickenPush the string "chicken"
2addPop b, a; push a + b (strings concatenate)
3foxSubtract
4roosterMultiply
5comparePush whether a == b
6pickDouble-wide: the next cell picks a source (0 = stack, 1 = input); pop an index and push that item
7peckPop an address, pop a value, store it there
8frPop an offset, pop a condition; if true, jump by the offset
9BBQPop x, push the HTML entity &#x;
10+pushPush the number (count − 10)

When the program exits, the top of the stack is printed, after HTML-unescaping (so A prints A).

Example

The shortest program is one line: chicken.

The shortest program is one line: chicken. It pushes "chicken", exits, and prints chicken. It is a quine by accident of design.

Adding two numbers: a line of 12 chickens (push 2), a line of 13 (push 3), and a line of 2 (add). The result, 5, is on top when the program exits.

Expected: 5 (the three lines above)
Expected: 3, in MiniChicken digits

The last line uses MiniChicken notation, one number per line, from the esolangs page. It reads digit 0 of the input (push 0, pick from source 1), turns "1" into a number by subtracting 0, does the same for digit 2, and adds them. The 60-line Hello World from the esolangs page also prints Hello world in this implementation.

Patterns it teaches

Try this

  1. Write a Chicken program that prints 7 (17 chickens on one line).
  2. Use BBQ to print the letter A. How many chickens is the longest line?
  3. Hard: write a loop with fr that counts down from 3. You will need pick and peck on the stack cells just above the code.

Further

Non-interactive IO

Self-modifying

Write your own in Run Convert a program from Chicken

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run chicken -e 'chicken'
shib manual chicken

Source

Module
langs/museum/ports.js
Interpreter
langs/museum/chicken.js, langs/museum/push.js

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

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