We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Macrosia/Standard library
Jump to navigation
Jump to search
This list may be (and likely is) outdated; the authoritative source is stdlib.rs in the Macrosia source tree.
A question mark (?) denotes an optional parameter and an ellipsis (...) denotes a vararg.
List
[]
Discards all arguments, returning nothing. Will still run any macros within its arguments - this one isn't "special".
[add]
Adds all arguments, returning their sum. # Arguments 1... Any amount of strings coercible to numbers.
[and]
Takes the boolean and of all inputs. # Arguments 1... Any value. Will be converted to a boolean.
[argslice]
Gets a slice of the given arguments. # Arguments 1. The slice, of the form `<start>[:<stop>[:<step>]]`. 2... The arguments to slice.
[assert]
Raises an error with a specified message if the first argument is not truthy. # Arguments 1. The condition to check. 2? The error message. Defaults to `<unspecified>`.
[base64.decode]
Decodes some given Base64. # Arguments 1... The Base64 string to decode.
[base64.encode]
Encodes some given data to Base64. # Arguments 1... The string to encode.
[bin]
Converts its first argument to binary. # Arguments 1. The number to convert.
[bit.and]
Calculates the binary AND of the given values. All values will be coerced to integers. # Arguments 1... The numbers to operate on.
[bit.ashr]
Calculates the arithmetic right bit shift of the given value. All values will be coerced to integers. # Arguments 1. The number to shift. 2. The amount to shift by. Must be in the range of 0 to 63, inclusive.
[bit.lshr]
Calculates the logical right bit shift of the given value. All values will be coerced to integers. # Arguments 1. The number to shift. 2. The amount to shift by. Must be in the range of 0 to 63, inclusive.
[bit.not]
Calculates the binary NOT of the given values individually. All values will be coerced to integers. # Arguments 1... The numbers to operate on.
[bit.or]
Calculates the binary OR of the given values. All values will be coerced to integers. # Arguments 1... The numbers to operate on.
[bit.shl]
Calculates the left bit shift of the given value. All values will be coerced to integers. # Arguments 1. The number to shift. 2. The amount to shift by. Must be in the range of 0 to 63, inclusive.
[bit.xor]
Calculates the binary XOR of the given values. All values will be coerced to integers. # Arguments 1... The numbers to operate on.
[byte]
Returns a single byte from a hexadecimal value. # Arguments 1. The hexadecimal value of the byte to return.
[byte.get]
Gets a single byte of a variable as a hexadecimal value. # Arguments 1. The variable to index into. 2. The byte index in the variable. Must be greater than or equal to 0.
[byte.len]
Gets the byte length of a string. # Arguments 1. The string to get the length of.
[byte.set]
Sets a single byte of a variable to a hexadecimal value. # Arguments 1. The variable to index into. 2. The byte index in the variable. Must be greater than or equal to 0. 3. The value to set the byte to.
[byte.slice]
Slices the given string by a start, stop, and optional step, based on bytes. # Arguments 1. The string to slice. 2? The slice start. 3? The slice end. 4? The slice step.
[byte.splice]
Splices a string of hexadecimal bytes into a variable. # Arguments 1. The variable to splice. 2. The hexadecimal string splice into the byte. 3. The byte index to start in the variable. Must be greater than or equal to 0. 4? The byte index to end in the variable. Must be greater than or equal to 0. Defaults to the end of the string.
[chr]
Returns a single UTF-8 character from a given integer value. # Arguments 1. The codepoint of the character to return.
[cmp]
Compares a number to another. Returns `1` on [`Ordering::Greater`], `0` on [`Ordering::Equal`], `-1` on [`Ordering::Less`], and `nan` if an order cannot be determined. # Arguments 1. The number to compare. 2. The number to compare against.
[concat]
Joins each argument with an empty string. # Arguments 1... Strings to join.
[cos]
Gets the cosine of a number. # Arguments 1. The number.
[count]
Finds the amount of occurrences of a string within another, optionally between a given range. # Arguments 1. The value to search. 2. The value to search for. 3? The start index. Defaults to 0. 4? The end index. Defaults to the length of the string.
[divide]
Divides the first argument by the second. # Arguments 1. The numerator of the division. 2. The denominator of the division.
[drop]
Drops a variable from the variable registry. # Arguments 1. The name of the variable to drop.
[ease]
Interpolates a value using a given time and easing method. Supported easings: `back`, `bounce`, `circ`, `elastic`, `expo`, `sine`, `quad`, `cubic`, `quart`, `quint`, `linear` All easings except for `linear` must be followed by `_in`, `_out`, or `_in_out`. For more information, see https://easings.net/. # Arguments 1. The number at the start of the easing animation. 2. The number at the end of the easing animation. 3. The time the easing animation should calculate. 4. The easing animation kind.
[equal]
Checks if two strings are equal. # Arguments 1. The string to compare. 2. The string to compare against.
[error]
Raises an error with a specified message. # Arguments 1? The error message. Defaults to `<unspecified>`.
[expr]
Evaluates an RPN expression. See [expr.def]. # Arguments 1... The expression.
[expr.call]
Evaluates a stored RPN expression. # Arguments 1. The name of the expression to call. 2... The expression arguments. Must all be numbers.
[expr.def]
Parses a RPN expression and saves it to a function variable. # Syntax Expressions are defined using Reverse Polish Notation. For example, `1 2 +` -> `3`. Each operator or number (generally called a _node_) must be separated by at least one whitespace character. Also supported is the node `$N`, for input values, and `#<ident>`, which allows calling other expressions inside of an expression. Calling an expression will pop its required arguments from the stack. For example, `[expr.def/inc/1 +][expr.call/inc/5]` -> `6`. See the documentation for [expr.def_ops] for supported operators. # Arguments 1. The name to save the expression under. 2... The expression
[expr.def_ops]
## Supported Operators for `[expr.def]` - `**`: Exponent - `log`: Log of arg 1 with base of arg 2 - `abs`: Absolute value - `<=>`: Three-way comparison - `!=`: Not equal - `==`: Equal - `<=`: Less or equal - `>=`: Greater or equal - `<<`: Left shift - `>>`: Logical right shift - `>>>`: Arithmetic right shift - `<`: Less - `>`: Greater - `+`: Add - `-`: Subtract - `*`: Multiply - `/`: Divide - `%`: Modulus - `~`: Negate - `?`: Ternary (if first argument is nonzero, choose first argument, otherwise choose second argument) - `&`: Bitwise AND - `|`: Bitwise OR - `^`: Bitwise XOR - `!`: Bitwise NOT - `sin`: Sine - `cos`: Cosine - `tan`: Tangent - `asin`: Arcsine - `acos`: Arccosine - `atan`: Arctangent - `real`: Real component of complex number - `imag`: Imaginary component of complex number - `arg`: Argument of complex number
[expr.fwd]
Sets up an RPN expression with a given amount of arguments to be defined later. Useful for recursive calls. # Arguments 1. The name to save the expression under. 2. The amount of arguments the expression takes.
[find]
Finds the first occurrence of a string within another, optionally between a given range. Returns -1 if not found. # Arguments 1. The value to search. 2. The value to search for. 3? The start index. Defaults to 0. 4? The end index. Defaults to the length of the string.
[floatfmt]
Formats a float. # Arguments 1. The number to format. 2. The amount of desired digits after the decimal point. If set to 0, the formatter will automatically choose a length. 3? The amount of desired digits before the decimal point. Defaults to 1. 4? Whether to use scientific notation. Defaults to false.
[for]
Repeats a string for each element in a list, replacing one pattern in each with the list index and another with the value, optionally separated by a separator. The string, patterns, and list all must be valid UTF-8. # Arguments 1. The list to loop over 2. The list delimiter 3. The pattern to replace with the index 4. The pattern to repace with the value 5? The separator between repetitions # Example > `[for/a,b,c/,/#/@/#:@/,]` -> `0:a,1:b,2:c`
[get]
Loads a variable from the variable registry, or sets it to and returns the second argument if it doesn't exist. # Arguments 1. The name of the variable to load. 2. The value to output if the variable does not exist.
[greater]
Checks if one number is greater than another. # Arguments 1. The number to compare. 2. The number to compare against.
[hash]
Hashes the given value. # Arguments 1. The value to hash.
[hex]
Converts its first argument to hexadecimal. # Arguments 1. The number to convert.
[if]
Chooses between a set of return values from a chain of booleans. # Arguments 1... A condition to check. 2... The value to return if the condition is true. ... n? The value to return if no conditions are true. If this is not supplied, will return the empty string if reached.
[imag]
Gets the imaginary component of a number. # Arguments 1. The number.
[input]
Checks if the given input value to a text macro was used. # Arguments 1. The value to check.
[int]
Converts the first argument to an integer. # Arguments 1. The number to convert to an integer. 2? The base to convert from. Defaults to 10. Must be between 2 and 36.
[is_number]
Checks if a value is a number. # Arguments 1. The value to check.
[is_stored]
Checks if a variable exists. # Arguments 1. The variable name to check.
[join]
Joins each argument. # Arguments 1. The string to join each value with. 2... Strings to join.
[len]
Gets the character length of a UTF-8 string. # Arguments 1. The string to get the length of. Must be valid UTF-8.
[less]
Checks if one number is less than another. # Arguments 1. The number to compare. 2. The number to compare against.
[load]
Loads a variable from the variable registry. # Arguments 1. The name of the variable to load.
[log]
Takes the logarithm of the first argument with the second as a base. # Arguments 1. The value to take the logarithm of. 2. The base of the logarithm.
[lower]
Converts its first argument to ASCII lowercase. # Arguments 1. The string to convert.
[macro]
Checks if macros exist within the execution context. # Arguments 1... The macro names to check.
[mod]
Takes the modulus of the first argument with the second. # Arguments 1. The numerator of the modulus. 2. The denominator of the modulus.
[multiply]
Multiplies all arguments, returning their product. # Arguments 1... Any amount of strings coercible to numbers.
[not]
Logically negates a boolean. # Arguments 1. The boolean to negate. Will be converted if it's not already one.
[num_equal]
Checks if one number is equal than another. # Arguments 1. The number to compare. 2. The number to compare against.
[oct]
Converts its first argument to octal. # Arguments 1. The number to convert.
[or]
Takes the boolean or of all inputs. # Arguments 1... Any value. Will be converted to a boolean.
[ord]
Gets the Unicode codepoint of a given one-character string. # Arguments 1. The character to get the codepoint of. The string must be valid UTF-8, and have at least one character. All other characters will be ignored.
[pow]
Raises the first argument to the second. # Arguments 1. The base of the exponent. 2. The power of the exponent.
[rand]
Creates a random value on the range [0, 1). # Arguments 1? A string to seed the RNG with.
[random.shuffle]
Shuffles the given arguments. # Arguments 1... The arguments to shuffle.
[real]
Gets the real component of a number. # Arguments 1. The number.
[repeat]
Repeats a string a given amount of times. # Arguments 1. The amount of times to repeat the string. 2. The string to repeat. 3? The separator between each string.
[replace]
Replaces a string within another string, using regex matching. All arguments must be valid UTF-8.
Note that for legacy reasons, this uses `\1` instead of `$1`, to emulate Python's regex.
# Arguments 1. The string to replace substrings of 2... The substring to replace 3... The string to replace the substring with
[sequence]
Repeats a string a set amount times, replacing a pattern in each with a number on a range, optionally separated by a separator. The pattern, repeated string, and separator all must be valid UTF-8.
# Arguments 1. The pattern to replace in the repeated string 2. The start of the range to repeat on 3. The end of the range to repeat on 4. The string to repeat 5? The separator between repetitions
# Examples > `[sequence/@/1/5/(@)/,]` -> `(1),(2),(3),(4),(5)` > `[sequence/@/1/3/@]` -> `123`
[sin]
Gets the sine of a number. # Arguments 1. The number.
[slice]
Slices the given string by a start, stop, and optional step, based on UTF-8 characters. The string must be valid UTF-8. # Arguments 1. The string to slice. 2? The slice start. 3? The slice end. 4? The slice step.
[split]
Splits a string into a list by a delimiter, and then indexes into that list. # Arguments 1. The value to split. 2. The list delimiter. 3. The index to grab.
[sreplace]
Replaces a string within another string, using the Aho-Corasick algorithm.
All replacements happen _at once_, meaning, for example, `[replace/baba/a/i/bibi/koko]` will be `bibi`, not `koko`.
# Arguments 1. The string to replace substrings of 2... The substring to replace 3... The string to replace the substring with
[step]
Gets the current execution step number.
[store]
Stores a variable in the variable registry. # Arguments 1. The name to store the variable under. 2. The value to store in the variable.
[subtract]
Subtracts the second argument from the first. # Arguments 1. The number to subtract from. 2. The number to subtract.
[tan]
Gets the tangent of a number. # Arguments 1. The number.
[title]
Converts its first argument to ASCII title case. # Arguments 1. The string to convert.
[to_boolean]
Converts a value into a boolean. # Arguments 1. The value to convert.
[to_float]
Returns its first argument. Legacy alias for compatiblity reasons.
[unescape]
Unescapes the argument. # Arguments 1. The string to unescape. Must be valid UTF-8.
[unixtime]
Gets the amount of seconds since January 1, 1970, 00:00 GMT.
[upper]
Converts its first argument to ASCII uppercase. # Arguments 1. The string to convert.
[ureplace]
Replaces a string within another string, using regex matching. Unescapes needles and replacement patterns first. All arguments must be valid UTF-8.
# Arguments 1. The string to replace substrings of 2... The substring to replace 3... The string to replace the substring with
[utf8]
Converts the given bytestring to UTF-8 lossily, replacing errors with `U+FFFD`. # Arguments 1. The string to convert to UTF-8.
[zlib.compress]
Compresses a given string using zlib, returning the compressed data Base64-encoded. # Arguments 1... The string to compress. Slashes do not need to be escaped.
[zlib.decompress]
Decompresses a given string using zlib, first decoding it from Base64. # Arguments 1. The string to decompress. Must be valid Base64.