Lists

By default, a HyperScript 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) can be found using the count 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" }.