Hello World in LOLCODE: A Very Peculiar Programming Language
1HAI 1.2 2 VISIBLE "Hello, World!" 3KTHXBYE 4
Yes, that was a "Hello, World!" program in the famous LOLCODE programming language.
LOLCODE is an esoteric programming language, a type of programming language which is defined by the Esolang Wiki as follows:
An esoteric programming language is a computer programming language designed to experiment with weird ideas, to be hard to program in, or as a joke, rather than for practical use.
Other esoteric programming languages include the famous Brainf*** programming language, Malbolge, and more.
LOLCODE was written to be programming language to mimic the "lolcats" meme which became popular in the mid-2000s, with basic syntax including words such as
HAI (start program with version number) and
KTHXBYE (end program).
Like many other esoteric programming languages, LOLCODE is actually very featured, and has the capability to be used to write many complex programs.
In fact, Justin Meza, the creator of the most recent LOLCODE interpreter, created httpd.lol, an HTTP server written entirely in LOLCODE.
Let's Write a Basic LOLCODE Program
First, to run actual LOLCODE programs, I'll be using the LOLCODE Repl.it Online Interpreter, although you can download the LOLCODE C Interpreter to run LOLCODE programs locally.
KTHXBYE for starting and ending programs
Every LOLCODE program starts with a
HAI declaration, followed by a version number. For example:
1HAI 1.2 2
HAI declaration, the end of every program must include a
KTHXBYE statement, for example:
1HAI 1.2 2 3KTHXBYE 4
OBTW for comments
BTW keyword introduces a single line comment, like this:
1BTW this is a single line comment 2
TLDR keywords are used to start and end a multiline comment respectively, for example:
1OBTW 2This is a multiline comment 3TLDR 4
VISIBLE for printing to stdout
To print text in LOLCODE, the
VISIBLE keyword is used as follows:
1VISIBLE "Hello, World!" 2
I HAS A [varname] ITZ [value]
Variables in LOLCODE are written with the syntax
I HAS A [var] ITZ [value], for example:
1BTW this sets the variable NAME to the value "Gabriel Romualdo" 2I HAS A NAME ITZ "Gabriel Romualdo" 3
Variables can then be referenced later with the same name.
AN for concatenation
To concatenate strings and variables,
SMOOSH is used. Example is provided in basic program below.
A Basic Program to Concatenate Strings and Variables
Now, we'll combine these basic LOLCODE keywords and syntax to create a very, very basic program which concatenates strings and variables.
The Python equivalent of this would be:
1name = "Gabriel Romualdo" 2website = "xtrp.io" 3favorite_color = "blue" 4 5print("Hi, I am " + name + ", my website is at " + website + " and my favorite color is " + favorite_color + ".") 6
Which in LOLCODE is:
1HAI 1.2 2 OBTW 3 This program creates several variables, concatenates them, and prints them. 4 TLDR 5 6 BTW create variables 7 I HAS A NAME ITZ "Gabriel Romualdo" 8 I HAS A WEBSITE ITZ "xtrp.io" 9 I HAS A FAVORITECOLOR ITZ "blue" 10 11 BTW concatenate with SMOOSH and AN 12 VISIBLE SMOOSH "Hi, I am " AN NAME AN ", my website is at " AN WEBSITE AN " and my favorite color is " AN FAVORITECOLOR AN "." 13KTHXBYE 14
And produces the following output successfully:
Hi, I am Gabriel Romualdo, my website is at xtrp.io and my favorite color is blue.
Note that some interpreters may require LOLCODE programs to include the
STDIO library, which can be included with a
CAN HAS [library]? statement.
Thanks for scrolling.
— Gabriel Romualdo, January 11, 2020