Standard Library: General functions
alt
[%alt: a; b+]
→ any
Prints the first argument that isn't of type nothing
. If all arguments are nothing
, prints nothing.
Parameters
a
← any
The first value to check.
b
← any+
The rest of the values to check.
call
[%call: func; args]
→ any
Calls the function func
with the argument list args
.
Parameters
func
← function
The function to call.
args
← list
The arguments to pass to the function.
cat
[%cat: values*]
→ any
Concatenates the provided values and prints the result.
Parameters
values
← any*
The values to combine.
copy
[%copy: value]
→ any
Returns a shallow clone of value
.
Parameters
value
← any
The value to clone.
either
[%either: condition; true-val; false-val]
→ any
Returns true-val
if condition
is @true
, or false-val
if condition
is @false
.
Parameters
condition
← bool
The boolean value to use to select the output.
true-val
← any
The value to print if condition
is true.
false-val
← any
The value to print if condition
is false.
irange
[%irange: a; b?; step?]
→ range
Creates a new inclusive range
with the specified bounds and step value.
- If
a
andb
are present, range will start ata
(inclusive) and end atb
(inclusive). - If
a
is present butb
is omitted, range will start at 0 (inclusive) and end ata
(inclusive).
The step
value determines the spacing of the range values and must be a positive integer. A step value of 0 defaults to 1.
The step
value does not affect the first value in the range and is only applied on subsequent values.
Parameters
a
← int
The starting (inclusive) bound. Used as the ending (inclusive) bound if b
is omitted.
b
← int
(optional)
The ending (inclusive) bound.
step
← int
(optional)
The absolute difference between adjacent values in the range.
fork
[%fork: seed?]
Forks (overrides) the current RNG with a new RNG seeded by both the old RNG's seed and the specified seed. If no seed is provided, a random one is generated.
Parameters
seed
← int | string
(optional)
The seed value to branch with.
Example
# Entangles {yee|woo} with {haw|hoo}, i.e. forces them both to pick the same index
[fork:a]{yee|woo}[unfork]-
[fork:a]{haw|hoo}[unfork]!
# Output is either "yee-haw!" or "woo-hoo!"
nop
[%nop: args*]
Does absolutely nothing. Intended as a convenience function for use as a default/placeholder callback.
Parameters
args
← any*
The arguments to unceremoniously toss into a bottomless void, never to be seen again.
[%print: values*]
→ any*
Prints the provided values directly to the calling scope's output.
Parameters
values
← any*
The values to print.
Remarks
Because this function does not use an internal output, sinking a call to it will have no effect.
range
[%range: a; b?; step?]
→ range
Creates a new exclusive range
with the specified bounds and step value.
- If
a
andb
are present, range will start ata
(inclusive) and end atb
(exclusive). - If
a
is present butb
is omitted, range will start at 0 (inclusive) and end ata
(exclusive).
The step
value determines the spacing of the range values and must be a positive integer. A step value of 0 defaults to 1.
The step
value does not affect the first value in the range and is only applied on subsequent values.
Parameters
a
← int
The starting (inclusive) bound. Used as the ending (exclusive) bound if b
is omitted.
b
← int
(optional)
The ending (exclusive) bound.
step
← int
(optional)
The absolute difference between adjacent values in the range.
require
[%require: module-path]
Imports the module at the specified relative path and assigns it to a local variable with a name matching the file name.
Rant requires module files to have the .rant
extension in order to load them; as such, it is not necessary to supply the file extension in the path.
Parameters
module-path
← string
The path to the module to load.
Example
# Import module `my-module`
[require: my-module]
# Call `hello-world` function in `my-module`
[my-module/hello-world]
seed
[%seed]
→ int
Prints the seed value of the currently active runtime RNG.
type
[%type: value]
→ string
Returns the name of value
's type. The type name can be any of the following:
string
float
int
bool
function
list
tuple
map
selector
nothing
Parameters
value
← any
The value whose type name to retrieve.
unfork
[%unfork]
Removes the last RNG created by [fork]
and resumes use of the previous RNG.