Hello World in LOLCODE: A Very Peculiar Programming Language

gaberomualdo

Gabe Romualdo

Posted on January 11, 2020

Hello World in LOLCODE: A Very Peculiar Programming Language
HAI 1.2
    VISIBLE "Hello, World!"
KTHXBYE
Enter fullscreen mode Exit fullscreen mode

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.

HAI and KTHXBYE for starting and ending programs

Every LOLCODE program starts with a HAI declaration, followed by a version number. For example:

HAI 1.2
Enter fullscreen mode Exit fullscreen mode

With the HAI declaration, the end of every program must include a KTHXBYE statement, for example:

HAI 1.2

KTHXBYE
Enter fullscreen mode Exit fullscreen mode

BTW and OBTW for comments

The BTW keyword introduces a single line comment, like this:

BTW this is a single line comment
Enter fullscreen mode Exit fullscreen mode

Whereas the OBTW and TLDR keywords are used to start and end a multiline comment respectively, for example:

OBTW
This is a multiline comment
TLDR
Enter fullscreen mode Exit fullscreen mode

VISIBLE for printing to stdout

To print text in LOLCODE, the VISIBLE keyword is used as follows:

VISIBLE "Hello, World!"
Enter fullscreen mode Exit fullscreen mode

Variables with I HAS A [varname] ITZ [value]

Variables in LOLCODE are written with the syntax I HAS A [var] ITZ [value], for example:

BTW this sets the variable NAME to the value "Gabriel Romualdo"
I HAS A NAME ITZ "Gabriel Romualdo"
Enter fullscreen mode Exit fullscreen mode

Variables can then be referenced later with the same name.

SMOOSH and 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:

name = "Gabriel Romualdo"
website = "gabrielromualdo.com"
favorite_color = "blue"

print("Hi, I am " + name + ", my website is at " + website + " and my favorite color is " + favorite_color + ".")
Enter fullscreen mode Exit fullscreen mode

Which in LOLCODE is:

HAI 1.2
    OBTW
        This program creates several variables, concatenates them, and prints them.
    TLDR

    BTW create variables
    I HAS A NAME ITZ "Gabriel Romualdo"
    I HAS A WEBSITE ITZ "gabrielromualdo.com"
    I HAS A FAVORITECOLOR ITZ "blue"

    BTW concatenate with SMOOSH and AN
    VISIBLE SMOOSH "Hi, I am " AN NAME AN ", my website is at " AN WEBSITE AN " and my favorite color is " AN FAVORITECOLOR AN "."
KTHXBYE
Enter fullscreen mode Exit fullscreen mode

And produces the following output successfully:

Hi, I am Gabriel Romualdo, my website is at gabrielromualdo.com and my favorite color is blue.
Enter fullscreen mode Exit fullscreen mode

Note that some interpreters may require LOLCODE programs to include the STDIO library, which can be included with a CAN HAS [library]? statement.

Conclusion

I hope you enjoyed this post and found LOLCODE to be a funny yet interesting programming language. You can read more about LOLCODE and its syntax on the LOLCODE Esolang Wiki Page, and check out The LOLCODE Website.

Thanks for scrolling.

— Gabriel Romualdo, January 11, 2020

💖 💪 🙅 🚩
gaberomualdo
Gabe Romualdo

Posted on January 11, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related