LOLCODE
A programming language written in the voice of an internet cat. HAI to start, KTHXBYE to stop.
Adam Lindsay, 2007 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 5 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
In 2006 the "lolcats" meme filled the internet with cat photos captioned in a broken baby-talk English ("I CAN HAS CHEEZBURGER?"). In 2007 Adam Lindsay, a researcher at Lancaster University, wrote a language in that voice. Interpreters in many host languages appeared within months.
Read the story
Under the jokes, LOLCODE is an ordinary imperative language: variables, conditionals, loops and functions. Only the keywords are strange. The program does not pretend to be a cat caption; it just talks like one.
It is a good example of how an esolang spreads. The idea was funny, the semantics were easy, and so anyone could implement it in an afternoon. A community specification, version 1.2, was finished in July 2007.
The machine
Variables are dynamically typed: NUMBR (integer), NUMBAR (float), YARN (string), TROOF (boolean, WIN or FAIL) and NOOB (nothing). The last expression evaluated is kept in the variable IT.
| Code | Means |
|---|---|
HAI 1.2 … KTHXBYE | Start and end of the program |
BTW ..., OBTW ... TLDR | Comments |
I HAS A X ITZ 3 | Declare X, set to 3 |
X R 4 | Assign |
VISIBLE "HAI " X | Print (the arguments are joined) |
GIMMEH X | Read a line into X |
SUM OF X AN Y, DIFF OF, PRODUKT OF, QUOSHUNT OF | Arithmetic, written prefix |
BOTH SAEM X AN Y, DIFFRINT X AN Y | Equal, not equal |
O RLY? YA RLY … NO WAI … OIC | If IT is true … else … end |
IM IN YR LOOP … IM OUTTA YR LOOP | A loop; GTFO breaks out |
HOW IZ I NAME YR X … IF U SAY SO | Define a function (1.2) |
A comma acts as a line break, so short O RLY? blocks fit on a few lines.
This implementation copies lci, the one TIO runs, quirks included. A NUMBAR prints with two decimals cut off, not rounded. BOTH SAEM "1" AN 1 is FAIL, because a YARN never equals a number. A TROOF cannot be printed at all: VISIBLE WIN is an error in lci, so turn it into words with O RLY? first. Every block (each branch, each loop pass) has its own variables and its own IT.
Example
Greet the boss differently:
Greet the boss differently:
HAI 1.2
I HAS A NAME
GIMMEH NAME
BOTH SAEM NAME AN "CEILING CAT", O RLY?
YA RLY, VISIBLE "O HAI BOSS"
NO WAI, VISIBLE "O HAI " NAME
OIC
KTHXBYE
GIMMEH reads a line. The comparison sets IT to WIN or FAIL. O RLY? branches on IT. With input Basement Cat it prints O HAI Basement Cat.
Run it
Commas are line breaks, so a whole program fits on one line:
Commas are line breaks, so a whole program fits on one line:
A loop. The loop variable i starts at 0, UPPIN adds one after each pass, and ! stops VISIBLE from ending the line:
Two thirds as a NUMBAR: lci prints 0.666666 and cuts it to two decimals.
Patterns it teaches
- Camouflage, the light version: only the keywords are disguised. Compare Shakespeare, where even the numbers are hidden in prose.
- Turing completeness: it is an ordinary language with loops and unbounded variables, so it is universal.
Try this
- Write FizzBuzz up to 15 in LOLCODE.
- Write a function
HOW IZ I DUBBL YR Xthat returns twice its argument withFOUND YR. - Hard: write a tiny LOLCODE interpreter for
VISIBLE,I HAS AandSUM OFin 50 lines of Node.
Further
- esolangs.org/wiki/LOLCODE
- The 1.2 specification: github.com/justinmeza/lolcode-spec
lci, a widely used interpreter in C by Justin Meza: github.com/justinmeza/lci
See also
Pseudonatural
Write your own in Run Convert a program from LOLCODE
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: lolcode.
Command line
shib run lolcode -e 'HAI 1.2
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE'shib manual lolcodeSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/lolcode.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org