FLOLCODE

From Esolang
Jump to navigation Jump to search

FLOLCODE (Formal LOLCODE) is a esolang by Mihai Popa. It's a formal version of LOLCODE. After seeing that LOLCODE is weird, I made this.

Keywords

These are the main keywords. All FLOLCODE keywords can be written in uppercase, lowercase or mixed case.

Code Comment
HI, VERSION [version] In all FLOLCODE programs, HI introduces the program, but VERSION specifies the version (although it isn't used yet).
COMMENT Comment Introduces a single line comment.
START COMMENT Comment

STOP COMMENT

Introduces a multi line comment.
CAN HAS [library]? Includes a library. Currently (version 1.4) the following libraries are available: STDIO, STRING, SOCKS and STDLIB.
SHOW [string] Prints STRING to the standard output stream. If an exclamation mark (!) is added outside the string, no newline will be printed.
GIVE ME [var] Reads a string from the standard input stream into the variable.
I HAVE A [var] Declares a variable without a value. Its type will be NOPE.
I HAVE A [var] IT'S [value] Declares a variable and assigns a value to it.
I HAVE A [var] IT'S A [type] Declares a variable of the specified type and assigns the initial value of that type to it. (See Types)
I HAVE A [var] IT'S LIKE A [other var] Declares a variable and copies the contents of the other variable into the newly created variable. This is only valid if the other variable is a ARRAY.
[var] IS [value] Assigns a value to a variable.
BOTH SAME [expression] AND [expression] Compares two expressions (a variable, a value or another comparison). Returns OK if both expressions have the same value.
DIFFERENT [expression] AND [expression] Compares two expressions (a variable, a value or another comparison). Returns OK if both expressions have different values.
BIGGER OF [expression] AND [expression] Returns the bigger of the two given expressions.
SMALLER OF [expression] AND [expression] Returns the smaller of the two given expressions.
SUM OF [expression] AND [expression] Calculates [expression1] + [expression2]
DIFFERENCE OF [expression] AND [expression] Calculates [expression1] - [expression2]
PRODUCT OF [expression] AND [expression] Calculates [expression1] * [expression2]
DIVISION OF [expression] AND [expression] Calculates [expression1] / [expression2]
MODULO OF [expression] AND [expression] Calculates [expression1] modulo [expression2]
GLUE [argument1] AND [argument2] (AND [argument3] (AND [argument4] ...)), OKAY Concatenates the given STRINGs.
MAKE [expression] A [type] Explicitly casts the expression to the given type. If the expression is a variable it is not changed. To also change a variable use [var] IS, MAKE [var] A [type].
[variable] IS NOW A [type] Explicitly casts a variable to the given type. The value of the variable is changed to the new type. This is equivalent to [var] IS, MAKE [var] A [type].
IDENTIFY [var] Interprets a STRING variable as an identifier.
[expression], REALLY?
	YES, REALLY
		...SOMECODE
	NO WAY
		...SOMECODE
	END
An if statement. If the expression can be evaluated to OK (equivalent of true) the YES, REALLY branch is executed, otherwise the NO WAY branch is executed.
[expression], SWITCH!
	CASE [value]
		[code]
	CASE [value]
		[code]
	ELSE
		[code]
	CLOSE
The SWITCH!-statement compares the expression to the values of the CASE-statements. The values must be distinct and literal, i.e. they mustn't contain any variables or expressions which have to be evaluated at runtime. The CASE block can be followed by any number of statements and can be terminated with BREAK. If an CASE-block is not terminated with BREAK the next CASE will be executed too, regardless of the comparison value. The default case (ELSE) is executed when no value matches the expression.
I'M IN YOUR [label] (UP|DOWN YOUR [var] (TILL|WHILE [expression]))
	...SOMECODE
I'M OUT OF YOUR [label]
Runs the code in the loop. If UP|DOWN YOUR [var] is included the loop iterates over the variable increasing (UP) or decreasing (DOWN) it. If TIL|WILE [expression] is included (may only be included, if an iteration variable is specified) the loop executes until (TILL) or while (WHILE) the expression is OK. The keyword BREAK exits any loop immediately.
OK, THANKS, BYE! OK, THANKS, BYE! terminates the program.

Functions

Functions can be declared with HOW IS I? [function name] (YOUR [argument1] (AND YOUR [argument2] (AND YOUR [argument3] ...))) [code block] IF YOU SAY SO, THANKS!

A function can return with one of the following statements:

  • FOUND YOUR [expression] returns the value of the expression
  • BREAK return without value (NOPE)

A function can be called with I, IS [function name] (YOUR [argument1] (AND YOUR [argument2] (AND YOUR [argument3] ...))), OKAY. If the arguments are expressions, they are evaluated before the function is called.

Types

There are currently 6 types available: STRING (string), NUMBER (integer), FLOAT (float), BOOLEAN or shorter BOOL (boolean), ARRAY (array) and NOPE.

NOPE

This is the untyped type. All declared variables without a value are of this type and their value is also NOPE. This type can implicitly only be cast to BOOL and returns FAIL. If explicitly cast to other types it will return the default value for the new type.

BOOL

This is the equivalent of a boolean variable. It can have one of two values: OK (true) and FAIL (false). When types are cast to BOOL, an empty string (""), an empty array and numerical zero return FAIL. All other values are cast to OK.

Numerical types

A NUMBER is an integer as specified in the host implementation/architecture. Any contiguous sequence of digits outside of a quoted YARN and not containing a decimal point (.) is considered a NUMBER. A NUMBER may have a leading hyphen (-) to signify a negative number.

A FLOAT is a float as specified in the host implementation/architecture. It is represented as a contiguous string of digits containing exactly one decimal point. Casting a FLOAT to a NUMBER truncates the decimal portion of the floating point number. Casting a FLOAT to a STRING (by printing it, for example), truncates the output to a default of two decimal places. A FLOAT may have a leading hyphen (-) to signify a negative number.

Casting of a string to a numerical type parses the string as if it were not in quotes. If there are any non-numerical, non-hyphen, non-period characters, then it results in an error. Casting OK to a numerical type results in "1" or "1.0"; casting FAIL results in a numerical zero.

STRING

STRINGs are demarked with double quotation marks ("). A STRING without a closing quote will cause an error. All characters inside a string represent their own value except the colon (:), which is being used as the escape character. The following escape sequences are available:

  • :N is a newline (\n)
  • :T is a tab (\t)
  • :B is a beep (\a)
  • :Q is a literal double quote (")
  • :C is a literal colon (:)
  • :([hex]) resolves the hex number into the corresponding Unicode code point.
  • :{[var]} interpolates the current value of the enclosed variable, cast as a string.
  • :[[char name]] resolves the [char name] in capital letters to the corresponding Unicode normative name.

ARRAY

This type represents an array. It has named slots, which can contain either variables or functions.

A variable inside a ARRAY can be used with [object]'S [var].

A function inside a ARRAY may also access variables and other functions of the ARRAY by using ME'S [var] or ME IS [function name] (YOUR [argument1] (AND YOUR [argument2] (AND YOUR [argument3] ...))), OKAY

Examples

Hello World

This program prints "Hello, world!" to the standard output.

HI, VERSION 1.3
SHOW "Hello, world!"
OK, THANKS, BYE!

Truth-Machine

A truth-machine asks for input, then checks if it equals 1. If true, then output 1s indefinitely, otherwise, output a 0 and terminate the program

HI, VERSION 1.3
COMMENT since FLOLCODE doesn't have input, we just use this variable as input
I HAVE A input IT'S A BOOL
input IS [input]
input, REALLY?
    YES, REALLY
        I'M IN YOUR loop
            SHOW "1"!
        I'M OUT OF YOUR loop
    NO WAY
        SHOW "0"
    END
OK, THANKS, BYE!

Criticism

FLOLCODE is often praised for being formal (that's what I said). It's not a weirdlang, for example..