Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

Birds fly over the rainbow...

Why then, oh why can't I?

- E.Y. Harburg


Aztec supports multi-dimensional arrays. Array braces "[ ]" are used to denote an array when defining a data type, when creating a new array, and when accessing individual elements of the array. The comma "," is used to separate dimensions or indices for the array.

♦ When an array name is used, it is always treated as a reference. The Aztec documentation sometimes uses the more formal term "array reference" but also sometimes uses just the term "array". They are synonymous.

♦ The size of an array can be specified at compile-time and at run-time.

♦ If the array size is defined at compile-time, the array braces must be placed after the variable name and the size of each array dimension must be specified as a constant. The virtual machine automatically creates the array based on the specified size when appropriate. Global arrays and class/local arrays that are shared are created at script/application startup. Local arrays are created each time the method is executed.

♦ This type of array is treated as a read-only array reference. It can be used in most cases just like an array reference with the size defined at run-time, with the exception that it cannot be the target of an assignment statement.

♦ If size is defined at run-time, the "new<>" keyword is used to create the array and the size of each array dimension can be specified at run-time. The array data type itself must be defined with the array braces attached to the data type (within the 'data<>' keyword), with no size specified for the dimension(s).

♦ All array elements are accessed using ONE based index values.

♦ A special data type, referred to as a "base array" or "base array reference" also exists. It is very similar in concept to the "base method reference" data type used for generic method references.

♦ The syntax "base [ ]" is used to denote a base array reference.

♦ The base array reference provides a "generic" storage item for any type of array and any number of dimensions.

♦ The generic array storage concept makes the base array reference very useful in a method argument list so the user can pass in any type of array.
♦ The "base [ ]" syntax is used regardless of number of dimensions that the generic storage item may ultimately hold. No commas are allowed inside the braces for the base array definition.

♦ The base array reference can not be used to access individual elements of the array, since the compiler does not know ahead of time what type of data the array might hold.

♦ The base array reference can be "evaluated" or "converted" to a standard array reference using the 'is' and 'as' keywords, similar to how they are used with base method reference testing and conversion.

♦ The 'is' operator will return true if the base array reference points at an array that matches the type of array object being tested. The data type and the number of dimensions both must match.
♦ The 'as' operator will return the actual array reference if the base array reference matches the type of array object and number of dimensions being tested, and returns null if it does not match.
♦ Example: if ( BaseArray is type<string[ , ]> ) { String2DArray = BaseArray as type<string[ , ]> }

♦ Some example array syntax with applicable descriptions

Aztec Array Syntax


♦ There is no specific limit to the number of array dimensions. The Aztec multi-dimensional array uses a rectangular array model, and the total size of the array is given by the mathematical product of the size of each of the dimensions. There is a limit for the total array size (number of individual elements), and it is dependent on the type of data being stored. The current limits on total Aztec array size are shown in the following table.

Aztec Array Maximum Sizes


♦ An array can be passed as an argument to a method, and can also be returned from a method. The data type and number of dimensions of the method argument must exactly match the data type and number of dimensions of the array that is being passed in. For a method that returns an array, the array type/dimensions must match the context of how the method call is used. The dimension sizes of the array in the method argument or method return value must be left empty. For a method argument, the array being passed in determines the size, and for a method return, the expression used in the 'return' statement determines the size.

♦ As mentioned above, the single exception to this rule is if the method argument is a "base array reference", which can accept any type of array.

♦ An Aztec Array is also a special object in and of itself, separate from the objects that it holds. An entire set of methods is provided to perform operations on an array. Array braces are not used when accessing an array method.

♦ An Aztec array is a special object. It is currently not derived from Collection, and it is also not derived from Base. It has its own set of "object methods" as described below.

♦ There are several internal reasons for this, but Aztec Development Group is considering changing this model in the future to have every array derived from Collection.

♦ An array can not contain another array. However, a future enhancement to support the concept of a jagged array is being considered. In this case, each level of an array would be dynamically allocated separately, and each level of the array would support a multi-dimensional array (data<string[ ] [ , ]>).

♦ Some key methods that are available to arrays

Key Aztec Array Methods


♦ An example script showing the use of Aztec arrays.

# Example Script: Aztec "Using Arrays" Script
# Demonstrates use of Aztec arrays, dynamically allocating, and automatially resizing.

# Main class that is derived from Thread. VM automatically creates us and executes Run().
method Main()
data<int> Count
data<int> ArraySize = 10
data<string> StringArray[5] # Array created automatically by system.
data<SimpleBaseClass[]> BaseArray # Array must be manually created at run-time.
data<SimpleBaseClass[]> InitBaseArray = { new<SimpleClass1("Array_101")>,
new<SimpleClass1("Array_103")> } # Array also created automatically.

# Make the string array be "auto resizable" and then jam ten items into it.
iterate ( Count in 1..ArraySize )
StringArray[Count] = "Text string for array element " + Count.Str()

# Allocate the array and then sit in loop and allocate elements of the array.
BaseArray = new<SimpleBaseClass[ArraySize]>
iterate ( Count in 1..BaseArray.Size() )
# Allocate element (of a real class derived from the base) and put it into the array.
BaseArray[Count] = new<SimpleClass1("Array_" + Count.Str())>

# Send the two "base arrays" arrays to another method to dump out the contents.

# This method takes an array and writes out the contents.
method DumpBaseArray(SimpleBaseClass[] BaseArray)
data<int> Count

iterate ( Count in 1..BaseArray.Size() )
# Write out the name of this element.
StdIO.Write("Element name from array is " + BaseArray[Count].GetName())

# Simple class hierarchy to use for array demonstration. There is an
# abstract base class and one class derived from that base.
class SimpleBaseClass
method<string> abstract GetName()

# This class is derived from abstract SimpleBaseClass and overrides GetName().
class SimpleClass1 from<SimpleBaseClass>
method SimpleClass1(string Name)
ClassName = Name

method<string> virtual GetName()
return("SimpleClass1->" + ClassName)

data<string> ClassName

Page UpPage DownCopyright © 2010-2017
Aztec Development Group
All Rights Reserved

Download Aztec