Objective LOLCODE is a rewritten version of LOLCODE, created in 2012, rather with an objective than being pointless. Objective LOLCODE uses extensions with names like the C/C++ header names, but all extensions introduce support for more code which looks like LOLSPEAK.
Just like the standard LOLCODE, Objective LOLCODE has these basic commands when no "CAN HAZ [LIBRARY]?" is included.
||In all LOLCODE programs, HAI introduces the program.|
||Introduces a comment.|
||Includes the library [LIBRARY].|
||Declares a variable and assigns a value to it.|
||Another way of assigning a value to the variable.|
IZ [VAR] [OPERATOR] [VALUE]? YARLY ...SOMECODE KTHX NOWAI ...SOMECODE KTHX
|An if statement (spec 1.0). OPERATOR can be BIGR DEN (>), SMALLR DEN (<) or LIEK (==).|
IM IN YR LUP ...SOMECODE KTHX IM OUTTA YR LUP
|Runs the same code in the "IM IN YR LUP" code block until it goes to a "KTHX" instruction in the code block. An "IM IN YR LUP" code block which never goes to a "KTHX" instruction causes an infinite loop.|
Like every non-esoteric programming language, basic arithmetic is part of Objective LOLCODE standards. Here is an example which tests all arithmetic functions
HAI CAN HAZ STDIO? I HAZ A TEST ITZ 65 + 48 IZ TEST LIEK 113? YARLY VISIBLE "Addition test passed" KTHX NOWAI COMPLAIN "Addition test failed" KTHX I HAZ A TEST ITZ 65 - 48 IZ TEST LIEK 17? YARLY VISIBLE "Subtraction test passed" KTHX NOWAI COMPLAIN "Subtraction test failed" KTHX I HAZ A TEST ITZ 15 * 5 IZ TEST LIEK 75? YARLY VISIBLE "Multiplication test passed" KTHX NOWAI COMPLAIN "Multiplcation test failed" KTHX I HAZ A TEST ITZ 75 / 5 IZ TEST LIEK 15? YARLY VISIBLE "Division test passed" KTHX NOWAI COMPLAIN "Division test failed" KTHX I HAZ A TEST ITZ 10 ^ 2 IZ TEST LIEK 100? YARLY VISIBLE "Exponentation test passed" KTHX NOWAI COMPLIAN "Exponentation test failed" KTHX I HAZ A TEST ITZ 100√ IZ TEST LIEK 10? YARLY VISIBLE "Square Root test passed" KTHX NOWAI COMPLAIN "Square Root test failed" KTHX KTHXBYE
When commands like "
CAN HAZ [LIBRARY]?" are performed, there are "AWSUM THX" and "O NOES" code blocks, for example:
HAI CAN HAZ STDIO? AWSUM THX VISIBLE "Hello World!" KTHX O NOES BTW This means that your LOLCODE implementation is rather a completely pointless implementation which doesn't even have STDIO and there is no way to show the error. KTHX KTHXBYE
If instructions that support error handling have no error handling code blocks, it will either continue if it would go to "AWSUM THX" or forcefully terminate the program if it would go to "O NOES".
In Objective LOLCODE, of course, there are objects. An object class can be defined like this:
HAI THRZ A NEW THNG CALLD OBJTESTZ OBJTESTZ HAZ VAL1Z WICH R INTGERZ OBJTESTZ HAZ VAL2Z WICH R STRNGZ I HAZ A TEST ITZ A NEW OBJTEST TESTZ VAL1 IZ 25 TESTZ VAL2 IZ "Objective LOLCODE" KTHXBYE
To test an object's type:
HAI CAN HAZ STDIO? THRZ A NEW THNG CALLD OBJTESTZ OBJTESTZ HAZ VAL1Z WICH R INTGERZ OBJTESTZ HAZ VAL2Z WICH R STRNGZ I HAZ A TEST ITZ A NEW OBJTEST IZ TEST LIEK A OBJTEST? YARLY VISIBLE "Type test passed" KTHX NOWAI VISIBLE "Type test failed" KTHX KTHXBYE
Objective LOLCODE, just like non-esoteric programming languages, there are collection types.
A basic collection is initialized with any of the following:
- I HAZ A CLECTUN F [VAR] (creates an empty basic collection)
- I HAZ A CLECTUN F [VAR] WID [VAR1] [VAR2] … N [LAST ITEM IN COLLECTION]
To add an item to a basic collection:
[ITEM] IZ NOW IN MY CLECTUN F [COLLECTION]
An example of getting an item from a collection:
HAI CAN HAZ STDIO? I HAZ A CLECTUN F MYCLECTUN WID 1 2 3 4 5 6 7 8 N 9 I HAZ A TEST ITZ TEH SCUND DING IN MYCLECTUN IZ TEST LIEK 2? YARLY VISIBLE "Collection test passed" KTHX NOWAI VISIBLE "Collection test failed" KTHX KTHXBYE
A dictionary can be initialized like this:
- I HAZ A [VAR] DICTUNRY (creates an empty dictionary)
- I HAZ A [VAR] DICTUNRY IN WIZ [KEY1] MENS [VALUE1] [KEY2] MENS [VALUE2] … N [FKEY] MENS [FVALUE]
To add a key and value or change a key to another value:
IN [DICTUNRY] [KEY] MENS [VALUE]
Code made available with "CAN HAZ STDIO?"
If the line "CAN HAZ STDIO?" is in the beginning of the program, these keywords become available.
||Prints STRING to the standard output stream.|
||Requests a line from the standard input stream and saves it as a string named VAR|
||Requests one character (symbol) from the standard input stream and saves it as a string named VAR|
||Displays STRING in the standard error stream.|
||Attempts to open a file with the path in the string named [FILENAME]. If [FILENAME] is a valid path according to the host OS and the file exists, it creates a STDIO FILE named [VAR], sets [VAR]Z TEXT to all the data it reads from the file, checks if the file is writable (if it is, the [VAR]Z TEXT string will be changeable for changing all the data in the file and a [VAR]Z STREAM will be created for adding data to the end of the file, otherwise [VAR]Z TEXT will be a constant attribute) and goes to the "AWSUM THX" block. Otherwise, it goes to the "O NOES" block.|
||Attempts to create a file named [FILENAME]. If [FILENAME] is a valid path according to the host OS, the file will be created, a writable STDIO FILE object named [VAR] will be created (just like a "PLZ OPEN [VAR] [FILENAME]?" after that) and goes to the "AWSUM THX" block. Otherwise, it goes to the "O NOES" block.|
||Writes the data in [STRING] to the STDIO STREAM named [STREAM] - for example:
HAI CAN HAZ STDIO? PLZ OPEN FILE "code.lol"? AWSUM THX TELL FILEZ STREAM "BTW I added a comment to this program." O NOES COMPLAIN "This is a null program; it's file does not exist." KTHXBYE
||Attempts to tell the host OS' shell to run [COMMAND]. If the command is valid and any program the shell tries to run before opening the streams has a valid path to a file that exists, a STDIO PROCESS object named [VAR] will be created and the program will go to the "AWSUM THX" code block. Otherwise, it goes to the "O NOES" code block.|
STDIO PROCESS objects have three attributes:
Code made available with "CAN HAZ STDLIB?"
||Creates an integer named [VAR], it's value is a random number from 0 to ([INT] - 1)|
Note: Regular Objective LOLCODE implementations should always change the seed for their host's random number generator, if the generator does not change it automatically, before every
||Attempts to convert [OLD] to the object type [TYPE]. if a conversion is possible, the variable [NEW] will be created with [OLD] converted to [TYPE] and the "AWSUM THX" code block will run. Otherwise, the "O NOES" code block will run.|
Code made available with "CAN HAZ TIME?"
||Creates an integer named [VAR], it's value is the Unix timestamp of how long your computer was on since the last power-on/reboot|
||Creates an integer named [VAR], it's value is the Unix timestamp of the current date and time|