pub enum DocumentationHelper {}
Expand description
Item purely for documentation purposes of the standard library. Dynamically made for easier browsing.
§Core macros
Even without the standard library, there are a few core macros that are always included. They are as follows:
§try
Executes some escaped macroscript, and returns a boolean value and output.
- If the inner script errors, then the boolean is
false
and the output is the error message. - If the inner script succeeds, then the boolean is
true
and the output is the result of the inner script.
This is reminiscent of Lua’s pcall
function.
§Examples
[try/\[add\/5\/5\]] -> true/10
[try/\[shl\/5\/100\]] -> false/shift amount of 100 is too large
§load
Loads a variable’s value and returns it. Errors if the variable doesn’t exist.
§Examples
[load/x] -> error: variable "x" does not currently exist
[store/x/5][load/x] -> 5
§store
Stores a value into a variable and returns nothing.
The variable table is global to the apply_macros
function.
§Example
[store/x/5] -> <no output>
§drop
Deletes a variable.
§Example
[store/x/5][drop/x][load/x] -> error: variable "x" does not currently exist
§get
Gets the value of a variable, storing a supplied default and returning it if the variable doesn’t exist.
§Example
[get/x/5],[load/x] -> 5,5
§is_stored
Returns whether a variable currently exists.
§Examples
[is_stored/x] -> false
[store/x/5][is_stored/x] -> true
§Standard library
These macros need to be included using crate::add_stdlib
.
§``
Comment. Returns nothing.
§Example
[/comment!] -> <no output>
§reverse
Reverses the given inputs.
§Example
[reverse/one/tw\/o/thr\\ee] -> thr\\ee/tw\/o/one
§add
Addition. Takes 0 or more numeric arguments and returns their sum.
§Examples
[add/3/2/3/5/3] -> 16
[add/5] -> 5
[add] -> 0
[add/a/b] -> error: could not convert argument 1 "a" to f64
§multiply
Multiplicaton. Takes 0 or more numeric arguments and returns their product.
§Examples
[multiply/1/2/3/4/5] -> 120
[multiply/5] -> 5
[multiply] -> 1
§unescape
Unescapes its input.
§Examples
[unescape/among\/us] -> among/us
[unescape/[if/true/\[add\/1\/1\]/\[add\/2\/1\]]] -> 2
§if
Basic alternation. Chooses between all even arguments with the condition of the odd ones, with the last as a base case.
§Examples
[if/true/a/true/b/c] -> a
[if/false/a/true/b/c] -> b
[if/false/a/false/b/c] -> c
[if/false/a/false/b] -> error: all conditions exhausted
[if/c] -> c
§truthy
Returns whether a string is “truthy”, i.e. whether it converts to true or false. Truthy strings have to be either “True”, “true”, or a number greater than 0.
§Examples
[truthy/1] -> true
[truthy/0] -> false
[truthy/ture] -> false
[truthy/among us] -> false
[truthy/True/true] -> true/true
§is_number
Returns whether a string can be converted to a number.
§Examples
[is_number/1] -> true
[is_number/abc/2] -> false/true
§pow
Raises a number to the power of another.
§Examples
[pow/7/2] -> 49
§subtract
Subtracts a number from another.
§Examples
[subtract/7/2] -> 5
[subtract/3/5] -> -2
§divide
Divides a number by another.
§Examples
[divide/5/2] -> 2.5
[divide/3/5] -> 0.6
[divide/1/0] -> inf
[divide/-1/0] -> -inf
[divide/0/0] -> NaN
§mod
Takes the modulus of one number with respect to another.
§Examples
[mod/5/2] -> 1
[mod/-3/5] -> 2
§log
Takes the logarithm of a number. The base is optional, and defaults to std::f64::consts::E
.
§Examples
[log/5] -> 1.6094379124341003
[log/16/2] -> 4
§rand
Gets a random number on the range [0, 1). A seed can optionally be supplied.
§Examples
[rand] -> ?
[rand/among us] -> 0.22694492387911513
§hash
Hashes many values, returning 64-bit integers.
§Examples
[hash/rain world/brain rot] -> -4983183619591677382/-1860790453662518022
§replace
Replaces all matches of a regular expression with a pattern. Both the pattern and replacement are unescaped.
§Examples
[replace/vaporeon/(\[aeiou\])/$1$1] -> vaapooreeoon
[replace/porygon/\[o/e] -> error: unclosed character class
§int
Converts the input to an integer, with an optional base to convert from.
§Examples
[int/54.2] -> 54
[int/-101/2] -> -5
[int/E621/16] -> 58913
§hex
Converts the input to a hexadecimal integer.
§Examples
[hex/16] -> 10
[hex/255/5] -> FF/5
§bin
Converts the input to a binary integer.
§Examples
[bin/5] -> 101
[bin/7/8] -> 111/1000
§oct
Converts the input to an octal integer.
§Examples
[oct/59] -> 73
[oct/1777/755] -> 3361/1363
§chr
Converts a unicode codepoint to a character. Note that this will error for invalid codepoints!
§Examples
[chr/55296] -> error: invalid codepoint at argument 1
[chr/65] -> A
[chr/65/109/111/110/103/32/85/115] -> Among Us
§ord
Converts characters into their unicode codepoints.
§Examples
[ord/] -> <no output>
[ord/A] -> 65
[ord/Among Us] -> 65/109/111/110/103/32/85/115
§len
Gets the length of the inputs.
§Examples
[len/] -> 0
[len/abc] -> 3
[len/abc/de] -> 3/2
§split
Splits the first input delimited by the second, then returns the section at the third argument.
§Example
[split/a,b,c/,/1] -> b
§select
Selects one of the arguments based on an index on the first.
If the index is #
, returns the number of arguments, minus 1 for the #
.
§Examples
[select/1/a/b/c] -> a
[select/#/one/two/three] -> 3
[select/0/it works, but why would you do this?] -> 0
[select/5/a/b] -> error: index 5 is out of bounds
[select/-1/nope, this isn't python] -> error: could not convert argument 1 "-1" to usize
§equal
Returns whether many strings are equal.
§Examples
[equal/one/one] -> true
[equal/one/two/three] -> false
[equal/1/1] -> true
[equal/1/1.0] -> false
§#equal
Returns whether a number is equal to another.
§Examples
[#equal/1/1.0] -> true
[#equal/0.3/[add/0.1/0.2]] -> false
[#equal/nan/nan] -> false
§greater
Returns whether a number is greater than another.
§Examples
[greater/1/1] -> false
[greater/0.2/0.1] -> true
[greater/nan/nan] -> false
§less
Returns whether a number is less than another.
§Examples
[less/1/1] -> false
[less/0.1/0.2] -> true
[less/nan/nan] -> false
§not
Negates many boolean inputs.
§Examples
[not/1.0] -> false
[not/true/false/3.0/-5.9] -> false/true/false/true
§and
Takes the logical AND of an arbitrary number of boolean inputs.
§Examples
[and/true/true] -> true
[and/false/true/true] -> false
§or
Takes the logical OR of an arbitrary number of boolean inputs.
§Example
[or/false/true] -> true
[or/false/true/true] -> true
§xor
Takes the logical XOR of an arbitrary number of boolean inputs.
§Examples
[xor/false/true] -> true
[xor/false/true/true] -> false
§#not
Takes the bitwise NOT of many 64-bit signed integer inputs.
§Example
[#not/0] -> -1 (0b00...0 -> 0b11...1)
[#not/5/-4] -> -6/3
§#and
Takes the bitwise AND of many 64-bit signed integer inputs.
§Examples
[#and/11/5] -> 1 (0b1011 & 0b0101)
[#and/8/13/7] -> 0 (0b1000 & 0b1101 & 0b0111)
§#or
Takes the bitwise OR of many 64-bit signed integer inputs.
§Examples
[#or/5/3] -> 7 (0b0101 | 0b0011)
[#or/9/5/2] -> 15 (0b1001 | 0b0101 | 0b0010)
§#xor
Takes the bitwise XOR of two 64-bit signed integer inputs.
§Examples
[#xor/5/3] -> 6 (0b0101 ^ 0b0011)
[#xor/8/11/5] -> 6 (0b1000 ^ 0b1011 ^ 0b0101)
§shl
Shifts the first argument’s bits to the left by the second argument. The second argument may not be greater than 63.
§Examples
[shl/5/2] -> 20 (0b101 -> 0b10100)
[shl/-9223372036854775808/1] -> 0 (0b100...0 -> 0b00...0)
§shr
Shifts the first argument’s bits to the right by the second argument. The second argument may not be greater than 63.
§Example
[shr/-9223372036854775808/1] -> 4611686018427387904 (0b100...0 -> 0b0100...0)
§#shr
Shifts the first argument’s bits to the right by the second argument, keeping the sign bit. The second argument may not be greater than 63.
§Example
[#shr/-9223372036854775808/1] -> -4611686018427387904 (0b100...0 -> 0b1100...0)
§abs
Gets the absolute value of many numbers.
§Examples
[abs/-5] -> 5
[abs/NaN/-inf] -> NaN/inf
§sin
Gets the sine of many numbers.
§Example
[int/[sin/3.14159]] -> 0
§cos
Gets the cosine of many numbers.
§Example
[int/[add/-0.01/[cos/3.14159]]] -> -1
§tan
Gets the tangent of many numbers.
§Example
[int/[multiply/2/[tan/1]]] -> 3
§asin
Gets the inverse sine of many numbers.
§Example
[asin/0/1] -> 0/1.5707963267948966
§acos
Gets the inverse cosine of many numbers.
§Example
[acos/1/0] -> 0/1.5707963267948966
§atan
Gets the inverse tangent of a number.
§Example
[int/[atan/1.5708]] -> 1
§error
Immediately raises an error. The error message is unescaped.
§Example
[error/oh no!] -> error: oh no!
§assert
Raises an error if the first argument is not truthy.
§Examples
[assert/1/all good] -> <no output>
[assert/false/yikes] -> error: yikes
§slice
Slices a string. The first argument is the start, the next is the end, and optionally, the last is the step size. This works similarly to Python’s string slicing rules (and is in fact carried over from it).
§Examples
[slice/abcdefg/1/4] -> bcd
[slice/abcde/1/] -> bcde
[slice/1,2,30,45///2] -> 123,5
[slice/kcab///-1] -> back
§find
Returns the start location of the second argument in the first. Returns -1 if it couldn’t be found.
§Examples
[find/homeowner/meow] -> 2
[find/clubstep monster/end] -> -1
§count
Returns the number of disjoint occurrences of the second argument in the first. Returns 0 if none were found.
§Examples
[count/Pacific Ocean/c] -> 3
[count/hellololo/lol] -> 1
§join
Joins all arguments with the unescaped first argument.
§Examples
[join/:/red/left/sleep] -> red:left:sleep
[join/\/\//dou/ble] -> dou//ble
§escape
Escapes the first argument.
§Example
[escape/add/5/3] -> add\/5\/3
§repeat
Repeats the first argument N times, where N is the second argument, optionally joined by the third argument.
§Examples
[repeat/5/5/:] -> 5:5:5:5:5
[store/x/0][unescape/[repeat/\[store\/x\/\[add\/\[load\/x\]\/1\]\]\[load\/x\]/5]] -> 12345
§lower
Turns the input into lowercase.
§Examples
[lower/VVVVVV/GO PLAY IT] -> vvvvvv/go play it
[lower/ὈΔΥΣΣΕΎΣ] -> ὀδυσσεύς
§upper
Turns the input into uppercase.
§Examples
[upper/vvvvvv/go play it] -> VVVVVV/GO PLAY IT
[upper/tschüß] -> TSCHÜSS
§map
Maps an escaped text macro over all of the inputs, returning the results as outputs.
§Example
[map/\[multiply\/$1\/2\]/1/2/3] -> 2/4/6
§fold
Performs a fold with an escaped text macro over all of the inputs, taking the first as a base case.
§Example
[fold/\[add\/$1\/$2\]/0/1/2/3] -> 6
Auto Trait Implementations§
impl Freeze for DocumentationHelper
impl RefUnwindSafe for DocumentationHelper
impl Send for DocumentationHelper
impl Sync for DocumentationHelper
impl Unpin for DocumentationHelper
impl UnwindSafe for DocumentationHelper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more