-
Notifications
You must be signed in to change notification settings - Fork 2
lists
bergsma edited this page Jul 31, 2014
·
2 revisions
By default, a HS variable is created as a list, which means that it can have zero, one, or many values, where each value in the array can be of any of the supported data types, including list.
The expression:
a = { 99, 1.23, "mystring" };
_
creates a list variable a with the values 99, 1.23, and "mystring". In its most explicit form, the above statement is equivalent to:
list 'a' = { int (99), float (1.23), str ("mystring") };
_
The sizes of lists are dynamic. For example, the contents and size of the variable a can be easily changed:
a = { 1, 2, 3, 4, 5};
_
We can also change the size of _a _using the following statement:
list a[3]; /* Truncate the list so that it has only 3 values */
_
The size of a list (or [vector][0]) can be found using the [count][1] method:
a_size = count ( a );
_
An individual list element can be accessed or changed using subscripts.
/* Print subscripted values */
for ( int i=0; i<a_size; i++ ) put ( a[i] );`
/* Assign a subscript value */ a[0] = 66;
_
## Strings and Lists
A _str _variable is a special case of a _list_ variable where all
the elements are of type _str_. In the above example, if the variable _a_
is converted to type _str_, all the values in the list become type _str_:
str a;
_
converts the elements of the _list_ to { "99", "1.23", "mystring" }. The
original _list _can be restored easily enough:
list a;
_
converts the _str_ elements back to the original _list_ elements {
99, 1.23, "mystring" }.
[0]: /docs/language/vectors.php
[1]: http://www.abinition.com/cgi-bin/dofunction.cgi?function=count