-
Notifications
You must be signed in to change notification settings - Fork 0
module std.array
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 arrayary
. -
(array-new-filled len value)
creates a new array withlen
elements consisting ofvalue
. -
(array? val)
returns true ifval
is an array. -
(array-empty? ary)
returns true if the arrayary
is empty. -
(array-first ary)
returns the first element ofary
. -
(array-last ary)
returns the last element ofary
. -
(array-len ary
) returns the number of elements in the array. -
(array-push! ary x)
pushesx
to the end of arrayary
. -
(array-pop! ary)
pops the last value from arrayary
and returns it. -
(array-get ary index)
returns the element at zero-based indexidx
in arrayary
. -
(array-set! ary idx val)
sets the element at indexidx
of arrayary
toval
. -
(array-swap! ary idx-1 idx-2)
swaps the elements at indicesidx-1
andidx-2
. -
(array-each ary callback)
will call callback with every element ofary
in order by index. The iteration will stop if thecallback
returns false.