esolang

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

Expected: O HAI WORLD

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.

CodeMeans
HAI 1.2 … KTHXBYEStart and end of the program
BTW ..., OBTW ... TLDRComments
I HAS A X ITZ 3Declare X, set to 3
X R 4Assign
VISIBLE "HAI " XPrint (the arguments are joined)
GIMMEH XRead a line into X
SUM OF X AN Y, DIFF OF, PRODUKT OF, QUOSHUNT OFArithmetic, written prefix
BOTH SAEM X AN Y, DIFFRINT X AN YEqual, not equal
O RLY? YA RLY … NO WAI … OICIf IT is true … else … end
IM IN YR LOOP … IM OUTTA YR LOOPA loop; GTFO breaks out
HOW IZ I NAME YR X … IF U SAY SODefine 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:

Expected: O HAI Basement Cat

A loop. The loop variable i starts at 0, UPPIN adds one after each pass, and ! stops VISIBLE from ending the line:

Expected: 12345

Two thirds as a NUMBAR: lci prints 0.666666 and cuts it to two decimals.

Expected: 0.66

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

  1. Write FizzBuzz up to 15 in LOLCODE.
  2. Write a function HOW IZ I DUBBL YR X that returns twice its argument with FOUND YR.
  3. Hard: write a tiny LOLCODE interpreter for VISIBLE, I HAS A and SUM OF in 50 lines of Node.

Further

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 lolcode

Source

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