StaticArray

is a data type for static, immutable arrays. They are stack-allocated. For a more flexible, heap-allocated version, you might want to look at the Array module.

=

defn

(Fn [(Ref (StaticArray a) b), (Ref (StaticArray a) b)] Bool)

                        (= a b)
                    

compares two static arrays.

all?

defn

(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] Bool)

                        (all? f a)
                    

checks whether all of the elements in a match the function f.

any?

defn

(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] Bool)

                        (any? f a)
                    

checks whether any of the elements in a match the function f.

aset!

template

(Fn [(Ref (StaticArray a) b), Int, a] ())

sets a static array element at the index n to a new value in place.

aset-uninitialized!

template

(Fn [(Ref (StaticArray a) b), Int, a] ())

sets an uninitialized static array member. The old member will not be deleted.

aupdate!

defn

(Fn [(Ref (StaticArray a) b), Int, (Ref (Fn [a] a c) d)] ())

                        (aupdate! a i f)
                    

transmutes (i.e. updates) the element at index i of an array a using the function f in place.

contains?

defn

(Fn [(Ref (StaticArray a) b), (Ref a b)] Bool)

                        (contains? arr el)
                    

checks wether an element exists in the array.

delete

template

(Fn [(StaticArray a)] ())

deletes a static array. This function should not be called manually (there shouldn't be a way to create value types of type StaticArray).

element-count

defn

(Fn [(Ref (StaticArray a) b), (Ref a b)] Int)

                        (element-count a e)
                    

counts the occurrences of element e in an array.

empty?

defn

(Fn [(Ref (StaticArray a) b)] Bool)

                        (empty? a)
                    

checks whether the array a is empty.

find

defn

(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] (Maybe a))

                        (find f a)
                    

finds an element in a that matches the function f and wraps it in a Just.

If it doesn’t find an element, Nothing will be returned.

find-index

defn

(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] (Maybe Int))

                        (find-index f a)
                    

finds the index of the first element in a that matches the function f and wraps it in a Just.

If it doesn’t find an index, Nothing will be returned.

first

defn

(Fn [(Ref (StaticArray a) b)] (Maybe a))

                        (first a)
                    

takes the first element of an array and returns a Just.

Returns Nothing if the array is empty.

foreach

macro

Macro

                        (foreach binding expr)
                    

foreach-internal

dynamic

Dynamic

                        (foreach-internal var xs expr)
                    

index-of

defn

(Fn [(Ref (StaticArray a) b), (Ref a b)] (Maybe Int))

                        (index-of a e)
                    

gets the index of element e in an array and wraps it on a Just.

If the element is not found, returns Nothing

last

defn

(Fn [(Ref (StaticArray a) b)] (Maybe a))

                        (last a)
                    

takes the last element of an array and returns a Just.

Returns Nothing if the array is empty.

length

template

(Fn [(Ref (StaticArray a) b)] Int)

gets the length of the static array.

map!

defn

(Fn [(Ref (StaticArray a) b), (Ref (Fn [(Ref a b)] a c) d)] ())

                        (map! xs f)
                    

Maps a function over the static array xs, mutating it in place. The difference to Array.endo-map (which does the same thing internally) is that this function takes a ref (since you can never have static arrays as values) and that it returns ().

maximum

defn

(Fn [(Ref (StaticArray a) b)] (Maybe a))

                        (maximum xs)
                    

gets the maximum in an array (elements must support <) and wraps it in a Just.

If the array is empty, it returns Nothing.

minimum

defn

(Fn [(Ref (StaticArray a) b)] (Maybe a))

                        (minimum xs)
                    

gets the minimum in an array (elements must support >) and wraps it in a Just.

If the array is empty, returns Nothing

nth

defn

(Fn [(Ref (StaticArray a) b), Int] (Maybe a))

                        (nth xs index)
                    

gets a reference to the nth element from an array arr wrapped on a Maybe.

If the index is out of bounds, return Maybe.Nothing

predicate-count

defn

(Fn [(Ref (StaticArray a) b), (Ref (Fn [(Ref a b)] Bool c) d)] Int)

                        (predicate-count a pred)
                    

counts the number of elements satisfying the predicate function pred in an array.

reduce

defn

(Fn [(Ref (Fn [a, (Ref b c)] a d) e), a, (Ref (StaticArray b) c)] a)

                        (reduce f x xs)
                    

reverse!

defn

(Fn [(Ref (StaticArray a) b)] ())

                        (reverse! a)
                    

Reverse array in place.

scan!

defn

(Fn [(Ref (Fn [a, a] a b) c), (Ref (StaticArray a) d)] ())

                        (scan! f xs)
                    

Scans and replaces the array in-place, using a binary function.

For example, give (def numbers [1 1 1]), a scan! using Int.+ will mutate numbers to be [1 2 3].

str

template

(Fn [(Ref (StaticArray a) b)] String)

converts a static array to a string.

sum

defn

(Fn [(Ref (StaticArray a) b)] a)

                        (sum xs)
                    

sums an array (elements must support + and zero).

swap!

defn

(Fn [(Ref (StaticArray a) b), Int, Int] ())

                        (swap! a i j)
                    

swaps the indices i and j of an array a in place.

unsafe-first

defn

(Fn [(Ref (StaticArray a) b)] a)

                        (unsafe-first a)
                    

takes the first element of an array.

Generates a runtime error if the array is empty.

unsafe-last

defn

(Fn [(Ref (StaticArray a) b)] a)

                        (unsafe-last a)
                    

takes the last element of an array.

Generates a runtime error if the array is empty.

unsafe-nth

template

(Fn [(Ref (StaticArray a) b), Int] (Ref a b))

gets a reference to the nth element from a static array a.

unsafe-nth-value

template

(Fn [(Ref (StaticArray a) b), Int] a)

returns the value at index i of a static array a (just like unsafe-nth) but does not take its reference, and does not copy the value. Should only be used for optimizations and when you know what you're doing, circumvents the borrow checker!

unsafe-raw

template

(Fn [(Ref (StaticArray a) b)] (Ptr a))

returns an array a as a raw pointer—useful for interacting with C.