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

aany
The first value to check.

bany+
The rest of the values to check.

call


[%call: func; args]

any

Calls the function func with the argument list args.

Parameters

funcfunction
The function to call.

argslist
The arguments to pass to the function.

cat


[%cat: values*]

any

Concatenates the provided values and prints the result.

Parameters

valuesany*
The values to combine.

copy


[%copy: value]

any

Returns a shallow clone of value.

Parameters

valueany
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

conditionbool
The boolean value to use to select the output.

true-valany
The value to print if condition is true.

false-valany
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 and b are present, range will start at a (inclusive) and end at b (inclusive).
  • If a is present but b is omitted, range will start at 0 (inclusive) and end at a (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

aint
The starting (inclusive) bound. Used as the ending (inclusive) bound if b is omitted.

bint (optional)
The ending (inclusive) bound.

stepint (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

seedint | 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

argsany*
The arguments to unceremoniously toss into a bottomless void, never to be seen again.

print


[%print: values*]

any*

Prints the provided values directly to the calling scope's output.

Parameters

valuesany*
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 and b are present, range will start at a (inclusive) and end at b (exclusive).
  • If a is present but b is omitted, range will start at 0 (inclusive) and end at a (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

aint
The starting (inclusive) bound. Used as the ending (exclusive) bound if b is omitted.

bint (optional)
The ending (exclusive) bound.

stepint (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-pathstring
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

valueany
The value whose type name to retrieve.

unfork


[%unfork]

Removes the last RNG created by [fork] and resumes use of the previous RNG.