Builtins and Libraries
3.1 Global Utilities
3.2 Numbers
3.3 Strings
3.4 Booleans
3.5 Raw  Array
3.6 Tables
3.7 lists
3.8 sets
3.9 arrays
3.10 string-dict
3.11 option
3.12 pick
3.13 either
3.14 srcloc
3.15 pprint
3.16 s-exp
3.17 s-exp-structs
3.18 image-structs
3.19 image
3.20 world
3.21 reactors
3.22 plot
On this page:
Raw  Array
3.5.1 Raw  Array Functions
raw-array
raw-array-of
raw-array-get
raw-array-set
raw-array-length
raw-array-to-list
raw-array-fold

3.5 RawArray

The type of raw array values. Raw arrays are a primitive datastructure that allows for lookup and (mutable) update by non-negative integers.

Raw arrays are used in the interface to constructor functions like [constr: e1, e2, ...], as the way of bundling up the values from e1, e2, etc. to pass them to constr.make.

3.5.1 RawArray Functions
[raw-array: elt :: a, ...] -> RawArray<a>

Creates a RawArray with the given elements. Note that RawArrays are mutable, so comparisons using == (the operator for equal-always) will only return true on RawArrays when they are also identical, regardless of their contents. To compare the elements, use equal-now/=~, and test with is=~.

Examples:

check: [raw-array: 1, 2, 3] is-not== [raw-array: 1, 2, 3] [raw-array: 1, 2, 3] is-not [raw-array: 1, 2, 3] [raw-array: 1, 2, 3] is=~ [raw-array: 1, 2, 3] a = [raw-array: 1, 2, 3] a is a a is== a end

raw-array-of :: (value :: a, count :: Number) -> RawArray<a>

Creates a RawArray with length equal to count, and with each index holding value. Note that value is not copied, so, the elements of arrays created with raw-array-of will always be identical (with the usual caveats if the value was a function or method).

Examples:

check: a1 = raw-array-of("init", 3) raw-array-length(a1) is 3 a1 is=~ [raw-array: "init", "init", "init"] a2 = raw-array-of({}, 3) raw-array-length(a2) is 3 raw-array-get(a2, 0) is<=> raw-array-get(a2, 1) raw-array-get(a2, 1) is<=> raw-array-get(a2, 2) end

raw-array-get :: (array :: RawArray<a>, index :: Number) -> a
raw-array-set :: (
array :: RawArray<a>,
index :: Number,
new-value :: a
)
-> RawArray<a>
raw-array-length :: (array :: RawArray<a>) -> Number

Examples:

a1 = raw-array-of(0, 3) raw-array-length(a1) is 3 raw-array-set(a1, 0, 1) raw-array-set(a1, 1, 2) raw-array-set(a1, 2, 3) raw-array-get(a1, 0) is 1 raw-array-get(a1, 1) is 2 raw-array-get(a1, 2) is 3 raw-array-get(a1, 3) raises "too large"

raw-array-to-list :: (array :: RawArray<a>) -> List<a>

Converts a RawArray to a List containing the same elements in the same order.

Note that it does not recursively convert RawArrays; only the top-level is converted.

Examples:

check: a = [raw-array: 1, 2, 3] raw-array-to-list(a) is [list: 1, 2, 3] a2 = raw-array-of([raw-array:], 3) raw-array-to-list(a2) is=~ [list: [raw-array:], [raw-array:], [raw-array:]] raw-array-to-list(a2) is-not=~ [list: [list:], [list:], [list:]] end

raw-array-fold :: (
f :: (b, a, Number -> b),
init :: b,
array :: RawArray<a>,
start-index :: Number
)
-> b

Combines the elements in the array with a function that accumulates each element with an intermediate result. Similar to fold_n. Has an argument order that works with for. The numeric argument to the accumulator is the index of the current element.

Examples:

check: a = [raw-array: "a", "b", "c"] str = for raw-array-fold(str from "", elt from a, i from 0): if i < (raw-array-length(a) - 1): str + elt + ": " + tostring(i) + ", " else: str + elt + ": " + tostring(i) end end str is "a: 0, b: 1, c: 2" end