# Vector! datatype

## 1. Abstract

A `vector!` value is an ordered sequence of values of identical type, which can be `char!`, `integer!`, `percent!` or `float!`.

`Vector!` is a member of the following typesets: `default!`, `series!`

## 2. Creation

Vector values can be created at runtime by using a `make` constructor.

### 2.1. Runtime creation

``````<vector> ::= make vector! <vector-spec>
<vector-spec> ::= <block> | [ <type-and-size> <block>]
<type-and-size> ::= char! 8 | char! 16 | char! 32 |
integer! 8 | integer! 16 | integer! 32 |
float! 32 | float! 64 | percent! 32 | percent! 64``````
``````>> make vector! [integer! 32 [1 2 3 4 5]]
== make vector! [1 2 3 4 5]

>> make vector! [#"r" #"e" #"d"]
== make vector! [#"r" #"e" #"d"]``````

If an `integer!` or `float!` value is supplied to `make`, a vector will be created of size `N` with values initialized to `0`.

``````>> make vector! 3
== make vector! [0 0 0]

>> make vector! 3.0
== make vector! [0 0 0]``````

## 3. Comparisons

All comparators can be applied on `vector!`: `=, ==, <>, >, <, >=, <=, =?`. In addition, `min`, and `max` are also supported.

## 4. Arithmetic

`+ - * / // %`

`add`, `average`, `divide`, `mod`, `modulo`, `multiply`, `remainder`, `subtract`, `sum`

Vector to vector arithmetic will return a new vector as the result.

``````>> x: make vector! [1 2 3 4]
== make vector! [1 2 3 4]

>> y: make vector! [5 6 7 8]
== make vector! [5 6 7 8]

>> x * y
== make vector! [5 12 21 32]``````

The vectors are unmodified.

``````>> x
== make vector! [1 2 3 4]

>> y
== make vector! [5 6 7 8]``````

Arithmetic on a single vector will modify the vector in place.

``````>> x * 2
== make vector! [2 4 6 8]

>> x
== make vector! [2 4 6 8]``````

`Copy` can be used to prevent a vector from being modified.

``````>> (copy x) * 2
== make vector! [2 4 6 8]

>> x
== make vector! [1 2 3 4]

>> 2 * copy x
== make vector! [2 4 6 8]

>> x
== make vector! [1 2 3 4]``````

## 5. Testing values

Use `vector?` to check if a value is of the `vector!` datatype.

``````>> vector? x
== true``````

Use `type?` to return the datatype of a given value.

``````>> type? y
== vector!``````

## 6. Predefined words

### 6.1. Actions

`add`, `and~`, `divide`, `multiply`, `or~`, `remainder`, `subtract`, `xor~`

### 6.2. Functions

`average`, `draw`, `mod`, `modulo`, `sum`, `vector?`

### 6.3. Operators

`%`, `*`, `+`, `-`, `/`, `//`