It turns out that all members, even ordinary members of composite variables that have names, can be accessed with the array-index operators. For example, if we have
CountryInfo :: {
name := "Angola"
stats := @Angola_stats | defined elsewhere
rep := @Ambassadors.Angola }
then CountryInfo[1] is "Angola'', CountryInfo[2] is an alias for the Angola_stats variable, and CountryInfo[3] is an alias to the name of the Angolan ambassador.
It is possible, and probably inadvisable, to come up with confusing mixed-breeds between composite variables and arrays:
Compound :: {
member1 := "1"
this[2, 4] :: ulong | indices 2 - 4
}
Compound.five := 5
Compound[8] :: double | indices 6-8
The final line, it must be emphasized, does not define a single index, nor does it redefine all indices 1-8; instead since the previous highest index was 5 it defines a new width-3 member that brings the total number of indices to 8. As a general rule, an index operator in a define statement defines a new member if the index is above the current top index, but if the given index currently exists it tries to redefine only that index.
This past example illustrates an important distinction in Yazoo: the difference between a member and an index. The Compound variable above has 4 members spanning 8 indices. The first and third members have names and each has only one associated index; the second and fourth members are unnamed and have three indices apiece.
Let's extend our earlier rule on allowed and disallowed ranges of indices in the logical way: all indices in a range of elements must be part of the same member. So for example Compound[3, 4] is allowed but Compound[4, 5] is not. Remember that Yazoo only manipulates contiguous blocks of memory, and if two indices are not even part of the same member this requirement is thoroughly violated.
The small difference between the [+...] and +[...] operators is illustrated by the following example:
TwoArrays :: {
this[5] :: ulong
this[10] :: ulong }
TwoArrays[+6] | adds an index to the beginning of the second member
TwoArrays+[6] | adds an index to the end of the first member
There is no operator that inserts a member in between two existing ones.
Let's take a step back and just take a last look at how the basic one-dimensional array `works':
OneD[10] :: ulong
OneD itself is a member that points to a composite variable. That composite variable itself has in turn a single, unnamed member with ten indices, spanning an array of unsigned longs. So when the user accesses OneD[3], he navigates first to the composite variable, then to index 3 of the sole member within that variable. Note that the composite variable was defined implicitly without any code (there is no `{}' anywhere). As the section on type-casting explains, code and type are two sides of the same coin for composite variables; as a result OneD (both the member and the variable) are very general objects, and can be specialized arbitrarily, or aliased later on to any composite variable or function.
Last update: July 28, 2013