Lananang

From Esolang
Jump to navigation Jump to search

Overview

Variable Type Description
c<FF> A byte with the value 0xFF.
i<128> An integer with the value 128. These variables are always stored as signed longs.
f<12.8> A float with the value 12.8. These are always stored in double precision IEEE 754 format.
s<~>~>~> Hello, world!> A string with the value >>> Hello, world!. ~ is the escape character.
l<i<64>,s<Sixty-four>> An array containing an integer 64 and a string Sixty-four.
b<0> A false boolean value.
q<$<i<5>>> A query returning the integer 5.
v<> The abscence of a value.

Note that overflows and underflows will not stop execution.

Typecasting can be done using the following format:

s<f<64.7>> Represents the string value s<64.7>.

Casting a float to an integer will round down. Casting a string to an integer will return i<0> if the string is invalid. Casting a string to a float will return f<NaN> if the string is invalid.

A v<> cannot be typecasted, and will always return a v<>.

Variables are set using the following format:

![number:i<128>] This sets the variable number to the the number 128.

and are retrieved using the following format:

=[number] This returns the value stored at the variable number.

Values in lists are retrieved with Python's list slicing syntax:

=[l[i<0>]] This returns the first value stored in the array l.
=[l[i<1>:i<4>]] This returns values 2 through 4 stored in the array l as an array.

Setting a value in a list to v<> removes that value from the list, moving everything past back one.

Queries

Queries, analogous to functions, are variables with the type q. They are first class.

This code sets the variable f to a list variable that holds a list containing an input value, and said value plus five.
Keep in mind, all variables set inside a query are destroyed once it concludes.

![f:q{n}<
  ![l:l<=[n],=[n]+i<5>>]
  $[l]
>]

$[value] marks a return value.

Catching extraneous variables can be specified with a semicolon (;), like this:

![f:l{;n}< ? an array with every variable specified
  $=[map{n,q{n}<$<n+5>>}] ? return a list of every specified value plus five
>]

Boolean Comparison

Operator Description
x==y Returns b<1> if the two values are equal, or if they're equal when typecasted to each other's types, and b<0> otherwise.
x===y Returns b<1> if the two values are equal and their types are equal, and b<0> otherwise.
x~>y Returns b<1> if x is more than y, and b<0> otherwise.
x~<y Returns b<1> if x is less than y, and b<0> otherwise.

Inbuilt Commands

Command Description
=[print{*}] Prints anything to the output. If an array of bytes is supplied, it outputs each byte as if writing to a file.
=[input{string}] Returns user input as a string.
=[pipe{string}] Changes the output from the current output to a file path, or to the default stdout if a void is supplied.
=[import{string}] Imports the return value after running the .lnag (lananang) file stored at the file path relative to the directory the program was ran in. If it can't be read, returns v<>.
=[load{string}] Loads the file at the specified file path to an array of bytes. If it can't be read, returns v<>.
=[random{}] Returns a random float between 0 and 1.
=[round{number,mode}] Returns number rounded to an integer. Floor if mode is 0, nearest if it's 1, and ceiling if it's 2.
=[if{boolean,function 1,function 2 (optional)}] Evaluates object 1 if the boolean is true, and if not, object 2 if that's specified.
=[loop{function, boolean}] Evaluates object while the boolean is true.
=[length{array}] Returns the length of the input array.
=[map{array,function}] Applies a function to every value in a list and returns the result.
=[reduce{array,function}] Applies a function for every few values in a list (minimum number of arguments in the specified function) and returns the result. (e.g. [=reduce{l<i<1>,i<2>,i<3>,i<4>,i<5>,i{a,b}<$<a+b>>}] returns i<15>)
=[type{*}] Returns a string containing the specified variable's type. (e.g. =[type{i<1>}] would return s<i>)

Math

Math Operations
Operator Function
x+y Adds two values
x-y Subtracts two values
x*y Multiplies two values
x/y Divides two values
x%y Gets the modulo of x to y
x^y Raises x to the power of y
x&y Bitwise and of two values
x||y Bitwise or of two values
!!x Bitwise not of a value
x^|y Bitwise xor of two values

Bitwise operators on booleans, integers, or bytes work as one would expect.
Any bitwise operators on strings or floats will operate with their byte representation.
Dividing by 0 is valid, and will return either f<+Inf> or f<-Inf> according to if the number was positive or negative, assuming 0 is positive.
Getting the square root of a negative number will return f<NaN>. Any invalid computation returns a v<>.

Other Notes

Anything on a line following an unescaped ? is a comment, and will be ignored.

Newlines are ignored except for in strings (where they get parsed as newlines) and in comments.

Trying to retrieve a variable that doesn't exist returns a v<>.

Basic programs

Cat

=[print{input{s<>}}] ?Gets the user input with no message, then prints the output.

Truth machine

![num: ? Set variable num to
    i<=[input{s<>}]> ? Input with empty string getting converted to a number
]
=[if{
    b<=[num] == i<1>>, ? If variable num is 1:
    =[loop{
        =[print{ ? Print 1
             i<1>
        }],
        b<1> ? Loop infinitely
    }],
    =[if{
        b<=[num] == i<0>>, ? If variable num is 0:
        =[print{ ? Print 0
            i<0>
        }]
    }] ? No other argument so the program ends if it's not 0
}]

Computational class

Not proven to be TC.

Implementations

None