let x_diff := x[1] - x[2]; y_diff := y[1] - y[2]; xd_sq := x_diff * x_diff; yd_sq := y_diff * Y_diff in sqrt( xd_sq + yd_sq ) end letThis is the calculation of the magnitude of separation of two two-space vectors. The vectors are named x and y, and their components are indexed in the usual way, using square brackets to separate the index expressions from the value names. Alternatively, we could represent the vectors as records, whose fields contain the components, and the calculation would them be as follows:
let x_diff := v1.x - v2.x; y_diff := v1.y - v2.y; xd_sq := x_diff * x_diff; yd_sq := y_diff * Y_diff in sqrt( xd_sq + yd_sq ) end letHere we have the two records, named v1 and v2, with fields in each named x and y. The record notation allows us to name the fields, and refer to them by use of the record and field names separated by a period. A third alternative we could use would allow a combination of these two notations, as follows:
let x_diff := vectors[1].x - vectors[2].x; y_diff := vectors[1].y - vectors[2].y; xd_sq := x_diff * x_diff; yd_sq := y_diff * Y_diff in sqrt( xd_sq + yd_sq ) end letHere we have an array, named vectors, whose elements are records. We index the individual records as array elements, and their components as record fields. But both these examples assume aggregates that already exist. How does one go about creating them?