[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

Arrays

Arrays are composite types that are lists of values of one type.

Individual values are accessed by an index. The type of the index can be either numeric or an enumerated type.

Arrays are a fixed size and the size is determined by the a range of values for the index. The lower bound and upper bound of the array are set when the type is declared (or, in the case of an anonymous array, when it is used in a declaration). It is an error to access elements outside of the index's range.

The built-in arrays package contains basic array subprograms.

Anonymous Arrays

To declare an anonymous array (an array with no type name):

=> zerbra_population : array(1900..2009) of natural
=> type divisions is (america, asia, africa, europe, oceania )
=> sales : array (america..oceania) of float

The first array contains 100 entries and each entry is a natural number.  To assign values or to access array entries, put the index number in parentheses after the array name.

=> zebra_population(1950) := 150000
=> ? zebra_population( 1950 )
150000

Attempting to use an out-of-range index number is an error.

=> ? zebra_population( 0 )
   ^ exception raised

Array Types

You can create new array types.

=> type zebra_list is array( 1900..2009 ) of natural;
=> zl : zebra_list

Initial Values

When you declare an array, you can assign a list of initial values or copy the values of another identical array. When providing initial value, provide a value for each component in the array.

=> type grocery_list is array(1..10) of string

=> gl : grocery_list := ( "milk", "bananas", "bread", "butter", "salt", "flour", "pizza", "noodles",  "", "" )
=> gl2 : grocery_list := gl
=> ? gl2(2)
bananas

Empty Arrays

An empty array can be created using 1..0.  This is the only case where the low bound is higher than the high bound.

=> empty : array(1..0) of integer

SparForte does not support assigning one array to another in an assignment statement, unconstrained arrays or multi-dimensional arrays.

Ada: SparForte does not (yet) implement arrays with multiple dimensions (arrays of arrays). Character and indefinite indexes are not implemented. Arrays cannot contain records. others is not yet implemented for assignment.


 
[Right Submenu]

 AdaScript versus GCC

 Case Sensitivity

 Reserved Words

 Comments

 Literals

 Bourne Shell Word Expansions

 Fundamental Types

 User-defined Types

 Enumerated Types

 Arrays

 Records

 Basic Assignment

 The @ and % Operands

 Command Argument Shortcuts

 Redirection and Pipelines

 Command Line Interaction

 Built-in Shell Commands

 The Current Directory

 Database Commands

 Flow of Control

 Other Statements/ Subprograms

 External Commands

 Block Statements and Subprograms

 TCP/IP Sockets

 Numeric Formatting with Put

 Interpreter Directives

 Command Line Options

 Command Reference

 ASCII and Latin_1 Character Sets

 Common Error Messages

 Common PHP Functions and the SparForte Equivalent

[Back to Top] Back To Top [Small Forte Symbol]