LOLCODE PLZ!!!!!11 PDF Print E-mail
User Rating: / 1
PoorBest 
Written by regicide666   
Monday, 18 June 2007
    So I am reading some random things on the web when I stumbled on this very cool and very funny project called lolcode. It is a new computer language that gets its syntax from all those sayings on the lolcat pictures that you see every where lately. I am not a big lolcat fan but after looking at some of the example code I just had to try it out for myself.
    To get started we need to get an interpriter that will parse and run our lolcode. I tried a few and I could only get 1 to work so we will deal with only that one.

 


    In gentoo-

        # emerge -v dev-perl/Parse-RecDescent

    In Ubuntu-

        $ sudo apt-get install libparse-recdescent-perl

    In CPAN-

        $ cpan install Parse::RecDescent

    then just download the perl script

        $ wget http://drago.cc/lol/lol.pl

 

    So now we should all be able to start out with our first bit of lolcode. As usual we will start with the hello world example.


        HAI

        BTW This is hello world in lolcode

        VISIBLE "HAI WORLDZ!!!!11"

        KTHXBYE


    Every lolcode file should start with HAI and end with KTHXBYE. Lolcode is always in caps and comments follow the BTW. The only other part of this code is the VISIBLE and it is the output to the terminal.


    Go ahead and save this file as haiworldz.lol then run it .


        $ ./lol.pl haiworldz.lol


    Now lets talk about variables and concatenation. To declare a variable we use the I HAS A statement. As an example if we wanted a variable named CATZ we would write it as this.

 

        I HAS A CATZ


    To declare the variable and give it a value just add ITZ and the value to the end of the declaration.


        I HAS A CATZ ITZ FREDEE


    With this we gave CATZ the value of FREDEE. Now if we want to use that variable in some output with some other text we will use the N for concatenation so the VISIBLE statement would look something like this.


        VISIBLE "AR CATZ HAVE NAME, IZ " N CATZ N "!!!!!11"


    All the text you want to output should be quoted then use N outside of the quotes with an unquoted variable to put it all together. The program will then look like this.


        HAI

        I HAS A CATZ ITZ FREDEE

        VISIBLE "AR CATZ HAVE NAME, IZ " N CATZ N "!!!!!11"

        KTHXBYE

 

    Save that as concat.lol and go ahead and run it.


        $ ./lol.pl concat.lol


    So that was some basic fun lets now get in to iterating variables. To start a loop we use the IM IN YR statement followed by a label to name the loop. To test the condition we use the IZ statement, think if. Lets get an example out so we can see how it works . Remember BTW is a comment


        HAI

        BTW initialize variable CATZ with a value of 0

        I HAS A CATZ ITZ 0

 

        BTW start the loop named counting

        IM IN YR COUNTING

 

            BTW tell the user how many CATZ there are

            VISIBLE "OWNLY " N CATZ N " CATZ"

 

            BTW compare CATZ value and see if it is bigger than 9

            IZ CATZ BIGGER THAN 9 O RLY?

                BTW if CATZ is bigger than 9 then exit loop

                YA RLY

                    GTFO

                BTW if CATZ is less then 9 than add 1 and start over

                NO WAI

                    UP CATZ!!1

                BTW exit IZ statement

                KTHX

            BTW exit loop counting

            KTHX

        BTW exit program

        KTHXBYE


    Save this as countcat.lol and run it.


        $ ./lol.pl catcount.lol


    As you can see this simply counts from 0 to ten. IZ CATZ BIGGER THAN 9 O RLY? Tests for true so if it is true YA RLY then exit the loop with GTFO. If the test is false NO WAI than add 1 to CATZ with UP CATZ!!1 . You always close the IM IN YR and IZ blocks with KTHX.


    Now just for fun try and rewrite the program to count down. Use SMALR THAN instead of BIGGER THAN and NERFZ instead of UP. For more information check out http://www.lolcode.com. Remember that this is a new language and it is not in anyway complete but it sure is fun.



Last Updated ( Tuesday, 19 June 2007 )
 
Next >
Main Menu
Home
News
Blog
Links
HowTo
Code
Contact Me
Search
News Feeds
Gallery
Google Search
Videos
Gallery
template design by joomlashack