|  |  | Sequences

## Sequences

Sequences are collections with nonnegative integer keys.

`<seq>` | `(<col>)` | `C`
`<seq.>` | `(<seq> <col.>)` | `C`
| immutable sequence. |
`1st` | `(x|<seq> => <any>)` | `G`
| == `(elt x 0)` |
`2nd` | `(x|<seq> => <any>)` | `G`
| == `(elt x 1)` |
`3rd` | `(x|<seq> => <any>)` | `G`
| == `(elt x 2)` |
`last` | `(x|<seq> => <any>)` | `G`
| == `(elt x (- (len x) 1))` |
`pos` | `(x|<seq> v|<any> => (t? <int>))` | `G`
| finds position of `v` in `x` else returns false. |
`finds` | `(x|<seq> y|<seq> => (t? <int>))` | `G`
| finds position of `y` in `x` else returns false. |
`add` | `(x|<seq> y|<any> => <seq>)` | `M`
| returns sequence with `y` added to the end of `x`. |
`push` | `(x|<seq> y|<any> => <seq>)` | `G`
| returns sequence with `y` added to `x`. |
`pop` | `(x|<seq> => (tup <any> <seq>))` | `G`
| returns last pushed element of `x` and new sequence with that element removed from `x`. |
`rev` | `(x|<seq> => <seq>)` | `G`
| returns reversed sequence. |
`cat` | `(x|<seq> more|... => <seq>)` | `G`
| returns concatenated sequences. |
`sub` | `(x|<seq> from|<int> below|<int> => <seq>)` | `G`
| subsequence of `x` between `from` and `below`. |
`'[' ... ']'` | `'[' ,x ,from ,below ']'` | `S`
| == `(sub ,x ,from ,below)` |
`sub*` | `(x|<seq> from|<int> => <seq>)` | `G`
| == `(sub x from (len x))` |
`'[' ... ']'` | `'[' ,x ,from * ']'` | `S`
| == `(sub* ,x ,from)` |
`ins` | `(x|<seq> val i|<int> => <seq>)` | `G`
| returns copy of `x`'s with `val` inserted before `i`. |
`del-dups` | `(x|<seq> => <seq>)` | `G`
| returns sequence with all duplicates removed. |
`del-vals` | `(s|<seq> val => <seq>)` | `G`
| returns sequence with all copies of `val` removed. |
`sort-by` | `(s|<seq> f|<fun> => <seq>)` | `G`
| returns a sorted copy of `s` using `f` as a comparator. |
`sort` | `(s|<seq> => <seq>)` | `G`
| == `(sort-by s <)` |
`pick` | `(f|<fun> x|<seq> => <seq>)` | `G`
| returns new sequence with elements corresponding to non-false results when calling predicate `f`. |
`prefix?` | `(x|<seq> prefix|<seq> => <log>)` | `G`
| returns true iff sequence `x` starts with sequence `prefix`. |
`suffix?` | `(x|<seq> suffix|<seq> => <log>)` | `G`
| returns true iff sequence `x` ends with sequence `suffix`. |
`repeat` | `(x|<seq> n|<int> => <seq>)` | `G`
| returns sequence with `n` concatenated copies of `x`. |
`split` | `(x|<seq> sep => <seq>)` | `G`
| returns sequence of subsequences of `x` separated by `sep`. |
`join` | `(xs|<seq> sep|<seq> => <seq>)` | `G`
| returns sequence composed of sequences in `xs` joined with `sep`. |

### Mutable Sequences

`<seq!>` | `(<seq> <col!>)` | `C`
`rev!` | `(x|<seq!> => <seq!>)` | `G`
| returns destructively reversed sequence. |
`cat!` | `(x|<seq!> more|... => <seq!>)` | `G`
| returns destructively concatenated sequences. |
`add!` | `(x|<seq!> y|<any> => <seq!>)` | `G`
| returns collection with `y` added to the end of `x`. |
`push!` | `(x|<seq!> y|<any> => <seq!>)` | `G`
| returns collection with `y` added to the front of `x`. |
`pop!` | `(x|<seq!> => (tup val|<any> <seq!>))` | `G`
| pops element from front of sequence. |
`PUSHF` | `(PUSHF ,place ,val)` | `S`
| pushes `,val` onto the sequence stored in `,place`, updates `,place` to contain the new sequence, and returns the new sequence. |
`POPF` | `(POPF ,place)` | `S`
| pops a value from the sequence stored in `,place`, replaces the sequence with an updated sequence, and returns the value. |
`ins!` | `(x|<seq!> v|<any> i|<int> => <seq!>)` | `G`
| inserts `v` before `i` in `x`. |
`sub-setter` | `(dst|<seq!> src|<seq> from|<int> below|<int>)` | `G`
| replaces subsequence in range between `from` and `below` of `dst` with contents of `src`. Provides insertion, deletion, and replacement operations rolled into one. |
`sub*-setter` | `(dst|<seq!> src|<seq> from|<int>)` | `G`
| == `(sub-setter dst src from (len dst))` |
`del-vals!` | `(x|<seq!> v|<any> => <seq!>)` | `G`
| removes all `v`'s from `x`. |
`del-dups!` | `(x|<seq!> => <seq!>)` | `G`
| removes all duplicates from `x`. |
`sort-by!` | `(s|<seq> f|<fun> => <seq>)` | `G`
| destructively sorts `s` using `f` as a comparator. |
`sort!` | `(s|<seq> => <seq>)` | `G`
| == `(sort-by! s <)` |

### Lists

Lists are always "proper" lists, that is, the tail of a list is always a list. Lists might be deprecated in future releases of GOO.

`<lst>` | `(<seq!>)` | `C`
`<list>` | `<lst>` | `A`
`head` | `(x|<lst> => <any>)` | `P`
`tail` | `(x|<lst> => <lst>)` | `P`
`lst` | `(elts|... => <lst>)` | `G`
| returns list of arguments. |
`list` | `lst` | `A`
`lst*` | `(elts|... => <lst>)` | `G`
| returns list of arguments with last argument tacked onto end. |
`nil` | `<lst>` | `I`
| aka `()`. |
`pair` | `(x|<any> y|<lst> => <lst>)` | `G`
| returns new list with `x` as head and `y` as tail. |

### Zips

A zip is a sequence of tuples of sucessive elements of sequences. A zip has the length of its shortest constituent sequence.

`<zip>` | `(<seq.>)` | `C`
`zip` | `(cs|(... <seq>) => <zip>)` | `G`
| returns a zip over sequences `cs`. |
`unzip` | `(z|<zip> => <tup>)` | `G`
| returns a tuple of `z`'s constituent sequences. |

### Flat Sequences

Flats represents sequences with constant access time. Flat enum provides an enum implementation of all but `now` and `now-setter`.

`<flat>` | `(<seq>)` | `C`
`<flat-enum>` | `(<enum>)` | `C`
`<tup>` | `(<flat> <seq.>)` | `C`
| Tuples are immutable flat sequences and represents multiple values in GOO. |
`tup` | `(elts|... => <tup>)` | `G`
| creates a tuple with elements being `elts`. |
`<vec>` | `(<flat> <seq!>)` | `C`
| Stretchy vectors resize when needed. |
`vec` | `(elts|... => <sec>)` | `G`
| returns new vector with elements `elts`. |

### Strings

GOO currently implements ASCII strings.

`<str>` | `(<flat> <mag> <seq.>)` | `C`
`str` | `(elts|... => <str>)` | `G`
| returns new string with elements `elts`. |
`case-insensitive-string-hash` | `(x|<tab> => (tup hash|<any> gc-state|<any>))` | `G`
`case-insensitive-string-equal` | `(x|<str> y|<str> => <log>)` | `G`

|  |  | Sequences