# Section 7.2.3:
AVAL

###### immutable class AVAL{T}

#### Formal Types

types
SAME = AVAL_T ;
AVAL_T = seq of T

This pervasive class is defined as a 'constructor' class. Immutable classes which include this class must redefine asize to get a non-trivial class. This class encapsulates the concept of a value array, the components of which are themselves are of type T which must itself be an immutable class.

Together with the pervasive class BIT this is the fundamental class for the construction of objects. As with the class AREF, all feature names begin with "a" to minimize name conflicts when included in other implementation classes.

The type of numeric arguments and results in this class is given as nat in order that implementations of the language which do not need the Required Library but wish to conform to the language specification may implement this unsigned number type in some suitable way - which must be implementation-defined. Where an implementation is providing the Required Library then these values must be of class CARD.

asize | : nat

##### Formal Signature

asize(self : SAME) res : nat

##### Post-condition

post res = card elems self

This feature returns the number of elements of type T of which self is composed.

NOTE | The including class must define a non-zero constant value for this feature, otherwise the objects generated will be null! It is not possible to alter this value after an object has been created!

#### aget

This feature provides the default indexed value retrieval operation. See the infix expression version which uses square brackets '[' and ']' to surround the index value.

aget | (
| index : nat
| ) : T

##### Formal Signature

aget(self : SAME, index : nat) res : T

##### Pre-condition

pre (index <= (asize(self) - 1))

##### Post-condition

post res = self(index + 1)

This routine returns the value of the element of self which has the given index.

NOTE | The index used in the vdm application to self in the above post-condition is one greater than that used in Sather. Indices in vdm-sl are an ordinal sequence starting at 1 - in Sather indices start from 0!

#### aset

This feature is the value setting counterpart of aget above. The corresponding 'infix' assignment version using square brackets '[' and ']' is defined in the assignment statement section of this document.

aset | (
| index : nat
| val : T
| )

##### Formal Signature

aset(self : SAME, index : nat, val : T)

##### Pre-condition

pre (index <= (asize(self) - 1))

##### Post-condition

post self(index + 1) = val

This routine sets the element of self indicated by the given index to val.

#### aind!

This feature is an iterator over the indices of the array, yielding each one in sequence from zero upwards.

aind! | : nat

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

aind_iter(self : SAME) yld : nat

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post ((history~ = []
or (yld > tl history~))
and history = history~ ^ yld)

##### Quit condition

For quit actions see the specificatiion of the quit statement.

errs QUIT : (set dom history~ = set inds self) -> quit

This iter yields the indices of self in numeric order, starting with zero. The iter quits when applied after yielding the value of the highest index of the array.

#### aelt!

This iter yields in sequence all of the array element values beginning with that element indexed by zero.

aelt! | : T

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

aelt_iter(self : SAME) yld : T

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post ((history~ = [])
or (yld = self(card elems history~ + 1)))
and (history = history~ ^ yld)

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (elems history~ = elems self) -> quit

This iter yields all of the elements of self in the order that they would be produced by applying the sequence of indices produced by aind! to self.

#### aelt!

This variant of aelt! takes an argument which is evaluated on first entry to give the index of the first element to be yielded.

aelt! | (
once | beg : nat
| ) : T

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

aelt_iter2(self : SAME, beg : nat) yld : T

##### Pre-condition

pre beg < card elems self

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post ((history~ = [])
or (yld = self(card elems history~ + beg + 1)))
and (history = history~ ^ yld)

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (card elems history~ = card elems self - beg) -> quit

This iter yields all of the elements of self in the order that they would be produced by applying the sequence of indices produced by aind! to self starting with the value indicated by the parameter.

#### aelt!

This variant of aelt!, in addition to the starting index argument, takes a second argument indicating the number of element values that are to be yielded.

aelt! | (
once | beg : nat
once | num : nat
| ) : T

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

aelt_iter3(self : SAME, beg : nat, num : nat) yld : T

##### Pre-condition

pre beg < card elems self
and (beg + num) <= card elems self

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post ((history~ = [])
or (yld = self(card elems history~ + beg + 1)))
and (history = history~ ^ yld)

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (card elems history~ = num) -> quit

This iter yields num elements of self in the order that they would be produced by applying the sequence of indices produced by aind! to self starting with the value indicated by the parameter.

#### aelt!

This final variant of aelt! takes three arguments - the index of the first element to be yielded, the count of elements and the increment/decrement of the index value between each application.

aelt! | (
once | beg : nat
once | num : nat
once | step : int
| ) : T

##### Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

aelt_iter4(self : SAME, beg : nat, num : nat, step : int) yld : T

##### Pre-condition

pre (((step > 0)
and beg < card elems self
and (beg + num * step) <= card elems self)
or ((step < 0)
and beg < card elems self
and (beg - num * step) >= 0))

##### Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post ((history~ = [])
or (yld = self((card elems history~ * step) + beg + 1)))
and (history = history~ ^ yld)

##### Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : (card elems history~ = num) -> quit

This iter yields num elements of self in the order that they would be produced by applying the sequence of indices produced by aind! multiplied by step to self starting with the value indicated by the parameter.

| Language Index |  | Library Index |  | Section 7 Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Friday, 19 May 2000. |