[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 Arrays

An array is an indexed collection of values that are all assigned to (parts of) one variable. Array names have the same rules as variable names: any string of letter or numbers, but must start with a letter.

In Bunao, arrays are referenced with parentheses surrounding a number (either a constant integer, or a variable whose value is an integer)(1) The reference index can itself be an array element. Examples of valid array elements:

 
A1(3)
mybigarray(78000)
name(nameid(thisperson))

Unlike most compiled languages like C and Fortran, Bunao/Tcl arrays do not need to be declared. Also, no element of an array exists until explicitly assigned to; setting A(3) does not imply anything about A(2) or A(1), etc.

Array names, like all Bunao variables can themselves contain expressions. This behavior simulates the old Listmaker Ai syntax. In Bunao, however, the substituted variable can expand to anything, not just integers, (and therefore has no limits like Listmaker's "array number" index).

 
A`i'(j)
my`pet'(43)

In the example below, say the value of i is `3', and pet is `dog'. The the corresponding array references are `A3(j)' and `mydog(43)'.

See section Variable Name Substitution.



This document was generated on October, 28 2005 using texi2html