Vector Functions

Summary
 Vector Functions size Get how many elements are in the vector. clone@ Create a new vector containing a copy of each element in the source vector. split@ Break a string into parts using a substring delimiter. splitc@ Separate a string using a set of character delimiters. words@ Extract the words of a string into a vector. join\$ Join the elements of a vector with a string. shift Remove the first element in a vector and return its value as an integer. shift\$ Remove the first element in a vector and return its value as a string. unshift Insert a new integer on the front of a vector. unshift Insert a new string on the front of a vector. pop Remove an element from the end of a vector and return its value as an integer. pop\$ Remove an element from the end of a vector and return its value as a string. push Insert an integer at the end of a vector. push Insert a string as the end of a vector. insert Inesrt an integer value in the middle of a vector. insert Insert a string value in the middle of a vector. delete Remove an element from a vector. delete\$ Remove an element from a vector. clear Remove all the elements from a vector. sort@ Sorts the vector using string comparison. nsort@ Sorts the vector using numeric comparison. reverse@ Returns the vector in reversed order.

size

Get how many elements are in the vector.

Params

 v@ the vector

Returns

An integer count of the number of elements in the vector.

clone@

Create a new vector containing a copy of each element in the source vector.

This has no practical effect, and is provided for compatibility only.

Params

 v@ the vector

Returns

A copy of the vector and each element in it.

split@

Break a string into parts using a substring delimiter.

Params

 str\$ the source string sep\$ a substring delimiter

Returns

Each part of the string between delimiters is returned in a new vector.

splitc@

Separate a string using a set of character delimiters.  Break the string using any of the given characters as a delimiter.  Subsequent delimiter characters are merged and treated as one delimiter.

`splitc@("abc|:|xyz", ":|") = [ "abc", "xyz" ]`

Note the similarity of this function to words\$()’s behavior.  The following two expressions are equivalent.

`words\$(str\$, 2, 2)splitc@(str\$, " \t\n")[2]\$`

Params

 str\$ the source string delims\$ a string of characters to used as delimiters

Returns

Each part of the string between delimiters in a new vector.

words@

Extract the words of a string into a vector.

Params

 str\$ the source string

Returns

A vector containing the words in the string.

join\$

Join the elements of a vector with a string.  The ‘glue’ is inserted between each element and the result is concatenated into a single string.

Params

 v@ the vector whose elements should be joined glue\$ the string to use when joining elements

Returns

A string obtained by concatenating each element with glue\$ between each.

shift

Remove the first element in a vector and return its value as an integer.

Params

 v@ the vector

Returns

An integer (0 if there are no more elements).

shift\$

Remove the first element in a vector and return its value as a string.

Params

 v@ the vector

Returns

A string (“” if there are no more elements).

unshift

Insert a new integer on the front of a vector.

Params

 v@ the vector value the value to insert

nothing

unshift

Insert a new string on the front of a vector.

Params

 v@ the vector value\$ the value to insert

nothing

pop

Remove an element from the end of a vector and return its value as an integer.

Params

 v@ the vector

Returns

An integer (0 if there are no more elements).

pop\$

Remove an element from the end of a vector and return its value as a string.

Params

 v@ the vector

Returns

A string (“” if there are no more elements).

push

Insert an integer at the end of a vector.

Params

 v@ the vector value the value to insert

nothing

push

Insert a string as the end of a vector.

Params

 v@ the vector value\$- the value to insert

nothing

insert

Inesrt an integer value in the middle of a vector.

Params

 v@ the vector index the spot to insert the new element at value the value to insert

nothing

insert

Insert a string value in the middle of a vector.

Params

 v@ the vector index the spot to insert the new element at value\$ the value to insert

nothing

delete

Remove an element from a vector.

Params

 v@ the vector index the element to remove

Returns

the removed element, or 0

delete\$

Remove an element from a vector.

Params

 v@ the vector index the element to remove

Returns

the removed element, or “”

clear

Remove all the elements from a vector.

Params

 v@ the vector

nothing

sort@

Sorts the vector using string comparison.

 This function returns the sorted vector the original vector is NOT modified.

Params

 v@ the vector

sorted vector

nsort@

Sorts the vector using numeric comparison.  String values are treated as zeroes, and their relative ordering is preserved.

 This function returns the sorted vector the original vector is NOT modified.

Params

 v@ the vector

sorted vector

reverse@

Returns the vector in reversed order.  The original vector is not modified.

Params

 v@ the vector

reversed vector