Built-in functions¶
Trepresents any type.
<T>represents any expression of typeT.
arg: Trepresents a function argument of typeT.
-> Tmeans that the function returns a value of typeT.
Print¶
print(T)
Used to print anything.
Type¶
type(T) -> string
Returns the type of the object as a string.
Float¶
float(string | int) -> float
Returns the string or int interpreted as a float. It will crash the program at runtime if the given string cannot be converted into a float.
Int¶
int(string | float) -> int
Returns the string or float interpreted as an int. It will crash the program at runtime if the given string cannot be converted into an int.
Str¶
str(T) -> string
Returns the given object as a string.
Bool¶
bool(s: string) -> bool
Returns s interpreted as a boolean. It will crash the program at runtime if s cannot be converted into a boolean.
Input¶
input() -> string
input(p: string) -> string
Asks the user for input.
If provided, it will print p prompt before asking.
Range¶
range(j: int) -> int[]
range(i: int, j: int) -> int[]
Returns an array containing the numbers from 0 or i to j-1.
TheAnswer¶
the_answer() -> int
Prints "The answer to the Ultimate Question of Life, the Universe, and Everything is 42." and returns the int 42.
Uppercase¶
<string>.uppercase() -> string
Returns the given string as uppercase.
Lowercase¶
<string>.lowercase() -> string
Returns the given string as lowercase.
Len¶
<string | T[]>.len() -> int
Returns the length of the given collection.
Contains¶
<string>.contains(e: string) -> bool
<T[]>.contains(e: T) -> bool
Returns a bool depicting whether or not the collection contains e.
Trim¶
<string>.trim() -> string
Returns the given string, trimmed (leading and trailing whitespace removed).
TrimLeft¶
<string>.trim_left() -> string
Returns the given string, with the left trimmed (leading whitespace removed).
TrimRight¶
<string>.trim_right() -> string
Returns the given string, with the right trimmed (trailing whitespace removed).
TrimSequence¶
<string>.trim_sequence(s: string) -> string
Returns the given string, with s removed from the start and end of the string.
TrimSequenceLeft¶
<string>.trim_sequence_left(s: string) -> string
Returns the given string, with s removed from the start of the string.
TrimSequenceRight¶
<string>.trim_sequence_right(s: string) -> string
Returns the given string, with s removed from the end of the string.
Find¶
<string>.find(e: string) -> int
<T[]>.find(e: T) -> int
Returns the index of e in the collection. If the element isn't found, it will return -1.
[1,2,3,4].find(2) // Returns 1
"Hello".find("l") // Returns 2
"Hello".find("el") // Returns 1
[1,2,3,4].find(5) // Returns -1
Repeat¶
<string>.repeat(n: int) -> string
<T[]>.repeat(n: int) -> T[]
Returns a collection repeated n times.
Push¶
<T[]>.push(e: T)
Adds e to the end of an array.
Remove¶
<T[]>.remove(n: int)
Removes the n-th element from an array.
Sqrt¶
<float>.sqrt() -> float
Returns the square root of a float.
Round¶
<float>.round() -> float
Rounds a float to the nearest int
Floor¶
<float>.floor() -> float
Floors a float.
Abs¶
<float>.abs() -> float
<int>.abs() -> int
Returns the absolute value of a number.
IsFloat¶
<string>.is_float() -> bool
Returns whether or not a string represents a float.
"6".is_float() // Returns false
"Hello, World!".is_float() // Returns false
"42.0".is_float() // Returns true
"6.7".is_float() // Returns true
IsInt¶
<string>.is_int() -> bool
Returns whether or not a string represents an int.
"6".is_int() // Returns true
"Hello, World!".is_int() // Returns false
"42.0".is_int() // Returns false
"6.7".is_int() // Returns false
Reverse¶
<T[]>.reverse()
<string>.reverse() -> string
Reverses a collection.
let x = [1,2,3];
x.reverse();
print(x); // Prints "[3,2,1]"
print("Hello".reverse()); // Prints "olleH"
Split¶
<string>.split(separator: string) -> string[]
Splits a string with the given separator separator.
Partition¶
<T[]>.partition(separator: T) -> T[][]
Partitions a collection with the given separator separator.
StartsWith¶
<string>.starts_with(s: string) -> bool
Returns whether or not the given string starts with s.
EndsWith¶
<string>.ends_with(s: string) -> bool
Returns whether or not the given string ends with s.
Replace¶
<string>.replace(a: string, b: string) -> string
Returns the given string with all occurrences of a replaced with b.
Join¶
<string[]>.join() -> string
<string[]>.join(separator: string) -> string
Joins all elements of the array into a single string, with separator or "" inserted between each element.
["a","b","c"].join() // Returns "abc"
["a","b","c"].join(",") // Returns "a,b,c"
["1","2"].join("--") // Returns "1--2"
Sort¶
<T[]>.sort()
Sorts an array in place and returns it. Supports arrays of ints, floats, and strings.
Argv¶
argv() -> string[]
Returns the arguments passed to the script, excluding the interpreter path and script name.
Exit¶
exit()
exit(exit_code: int)
Exits the program with the exit code 0, if not provided with one.
Throw¶
throw(error: string)
Throws an error. Read more in Error handling
fn main() {
try {
let idk = [][0];
} catch "index_out_of_bounds" {
print("This WILL be printed!");
}
}
Get¶
<[K: V]>.get(key: T) -> V
Returns the value associated with the key in the given map. If the key doesn't exist, it raises the unknown_map_key error.
Insert¶
<[K: V]>.insert(key: T, value: V)
Inserts the given key-value pair in the map. It updates the value if the key already exists.