Janet 1.32.1-cc5beda Documentation
(Other Versions: 1.31.0 1.29.1 1.28.0 1.27.0 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

Array Module

Arrays are the mutable indexed type in Janet. They contain a sequence of values that are keyed with an index. They can also be used to implement stacks and queues. See the Arrays documentation for more info.

Index

array/clear array/concat array/ensure array/fill array/insert array/new array/new-filled array/peek array/pop array/push array/remove array/slice array/trim array/weak


array/clear cfunction source
(array/clear arr)

Empties an array, setting it's count to 0 but does not free the backing capacity. Returns the modified array.
Community Examples

array/concat cfunction source
(array/concat arr & parts)

Concatenates a variable number of arrays (and tuples) into the first argument, which must be an array. If any of the parts are arrays or tuples, their elements will be inserted into the array. Otherwise, each part in `parts` will be appended to `arr` in order. Return the modified array `arr`.
Community Examples

array/ensure cfunction source
(array/ensure arr capacity growth)

Ensures that the memory backing the array is large enough for `capacity` items at the given rate of growth. `capacity` and `growth` must be integers. If the backing capacity is already enough, then this function does nothing. Otherwise, the backing memory will be reallocated so that there is enough space.
Community Examples

array/fill cfunction source
(array/fill arr &opt value)

Replace all elements of an array with `value` (defaulting to nil) without changing the length of the array. Returns the modified array.
Community Examples

array/insert cfunction source
(array/insert arr at & xs)

Insert all `xs` into array `arr` at index `at`. `at` should be an integer between 0 and the length of the array. A negative value for `at` will index backwards from the end of the array, inserting after the index such that inserting at -1 appends to the array. Returns the array.
Community Examples

array/new cfunction source
(array/new capacity)

Creates a new empty array with a pre-allocated capacity. The same as `(array)` but can be more efficient if the maximum size of an array is known.
EXAMPLES
(def arr (array/new 100)) # -> @[]

# Now we can fill up the array without triggering a resize
(for i 0 100
  (put arr i i))
Community Examples

array/new-filled cfunction source
(array/new-filled count &opt value)

Creates a new array of `count` elements, all set to `value`, which defaults to nil. Returns the new array.
Community Examples

array/peek cfunction source
(array/peek arr)

Returns the last element of the array. Does not modify the array.
Community Examples

array/pop cfunction source
(array/pop arr)

Remove the last element of the array and return it. If the array is empty, will return nil. Modifies the input array.
Community Examples

array/push cfunction source
(array/push arr & xs)

Push all the elements of xs to the end of an array. Modifies the input array and returns it.
Community Examples

array/remove cfunction source
(array/remove arr at &opt n)

Remove up to `n` elements starting at index `at` in array `arr`. `at` can index from the end of the array with a negative index, and `n` must be a non-negative integer. By default, `n` is 1. Returns the array.
Community Examples

array/slice cfunction source
(array/slice arrtup &opt start end)

Takes a slice of array or tuple from `start` to `end`. The range is half open, [start, end). Indexes can also be negative, indicating indexing from the end of the array. By default, `start` is 0 and `end` is the length of the array. Note that if the range is negative, it is taken as (start, end] to allow a full negative slice range. Returns a new array.
Community Examples

array/trim cfunction source
(array/trim arr)

Set the backing capacity of an array to its current length. Returns the modified array.
Community Examples

array/weak cfunction source
(array/weak capacity)

Creates a new empty array with a pre-allocated capacity and support for weak references. Similar to `array/new`.
Community Examples