Skip to content
Jan Špaček edited this page Apr 13, 2016 · 2 revisions

Arrays from module std.array are mutable arrays with variable number of elements. The elements are accessed by 0-based indices. It is forbidden to access elements out of the valid range [0, length). In particular, setting an element beyond the last element will not cause the array to resize.

  • (array-new) creates a new, empty array.
  • (array-copy ary) creates a new array with the elements copied from array ary.
  • (array-new-filled len value) creates a new array with len elements consisting of value.
  • (array? val) returns true if val is an array.
  • (array-empty? ary) returns true if the array ary is empty.
  • (array-first ary) returns the first element of ary.
  • (array-last ary) returns the last element of ary.
  • (array-len ary) returns the number of elements in the array.
  • (array-push! ary x) pushes x to the end of array ary.
  • (array-pop! ary) pops the last value from array ary and returns it.
  • (array-get ary index) returns the element at zero-based index idx in array ary.
  • (array-set! ary idx val) sets the element at index idx of array ary to val.
  • (array-swap! ary idx-1 idx-2) swaps the elements at indices idx-1 and idx-2.
  • (array-each ary callback) will call callback with every element of ary in order by index. The iteration will stop if the callback returns false.