A multiple consists of a number of
elements, each of which have the same mode
(sometimes known as the base mode). The
mode of a multiple consists of the mode
indicant for each element preceded by brackets, and
is said “row of mode”. For example, here is an identity
declaration of a row of CHAR
multiple:
[]CHAR a = "abcd"
The phrase on the left-hand side of the equals symbol is read
“row of car a”. The phrase on the right-hand side of the
equals symbol is the denotation of a value whose
mode is []CHAR
. Spaces can, of course, appear before,
between or after the brackets.
Multiples of mode []CHAR
are so common that this
denotation was devised as a kind of shorthand. The maximum number of
elements in a multiple is equal to the maximum positive integer
(max int), although in practice, your
program will be limited by the available memory. The denotation of a
[]CHAR
may extend over more than one line. There are two
ways of doing this. You can simply write the denotation on more than
one line in which case every character “between” the
starting and ending quote characters is included except the newline
characters, or you can split the denotation with quote characters at
the end of one line and at the start of the continuation of the
denotation on the next line. Here are two declarations which exemplify
these rules:
[]CHAR long1 = "The first stage in the develo pment of a new program consists of analysing the problem that the program must solve."; []CHAR long2 = "The first stage in the " "development of a new " "program consists of " "analysing the problem " "that the program must " "solve."
Notice that the second method is neater because you can indent the
subsequent parts of the denotation. Everything “between”
the second and third quote characters and “between” the
fourth and fifth quote characters is ignored, although you should not
put anything other than spaces or tabs and newlines there. If you
want to place a quote character (") in the
denotation, you must double it, just as in the character denotation.
Here are two []CHAR
denotations, each containing two
quote characters:
[]CHAR rca = """Will you come today?""", rcb = "The minority report stated " "that ""in their opinion""";
The repeated quote characters are different from the quote
characters which chain the two parts of the denotation of
rcb
.
Multiples of other modes cannot be denoted as shown above, but use
a construct called a row-display. A
row-display consists of none or two or more units
separated by commas and enclosed by parentheses (or
BEGIN and
END). Here is the identity
declaration for a
written using a
row-display:
[]CHAR a = ("a","b","c","d")
It is important to note that the units in the row-display could be
quite complicated. For example, here is another declaration for a
multiple with mode []CHAR
:
[]CHAR b = ("a","P",REPR 36,"""")
In each of these two declarations, the number of elements is
4
.
Here are identity declarations for a multiple
of mode []INT
and a multiple of mode
[]REAL
:
[]INT c = (1, 2+3, -2**4, 7, -11, 2, 1); []REAL d = (1.0, -2.9, 3e4, -2e-2, -5)
Note that the last unit of the row-display for c
has
the same value as the first unit. In a multiple of mode
[]INT
, the individual elements can have any value of mode
INT
: that is to say, any integer or formula yielding an
integer. In d
, the unit yielding the last element is
written as a formula yielding a value of mode INT
. Since
the context of the row-display is strong (because
it occurs on the right-hand side of an identity declaration), this
context is passed on to its constituent units.
Thus, the context of the formula is also strong, and so the value
yielded by the formula is widened to yield
-5.0.
An empty row-display can be used to yield a flat multiple (one with no elements). For example, here is an identity declaration using an empty row-display:
[]REAL empty = ()
The denotation for a flat []CHAR
is used in the identity
declaration
[]CHAR none = ""
A multiple can also have a single element. However, a row-display cannot have a single unit (because it would be an enclosed clause, which is a different construct). In this case, we use a unit (or a formula, which is another kind of unit) for the only element, and the value of that unit is coerced to a multiple with a single element using the rowing coercion. For example,
[]INT ri = 4
yields a multiple with one element. An enclosed clause can be used instead:
[]INT ri1 = (4)
since an enclosed clause is also a unit (see section 10.4).
Rowing can only occur in strong contexts (and the right-hand side of an identity declaration is a strong context). Here is another example:
[]CHAR rc = "p"
A row-display can only be used in a strong context. Because the
context of an operand is firm, a row-display cannot
appear in a formula (but there is a way round this, see section
10.5). The shorthand denotation
for a []CHAR
is not a row-display and so does not suffer
from this limitation.
One of the properties of a multiple is its number of dimensions. All the multiples declared so far have one dimension. The number of dimensions affects the mode. A two-dimensional multiple of integers has the mode
[,]INT
(said “row-row-of-int”), while a 3-dimensional multiple of reals (real numbers) has the mode
[,,]REAL
Note that the number of commas is always one less than the number of dimensions. In Algol 68, multiples of any number of dimensions can be declared.4.1
To cater for more than one dimension, each of the units of a
row-display can also be a row-display. For example,
the row-display for a multiple with mode [,]INT
could
be
((1,2,3),(4,5,6))
The fact that this is the row-display for a 2-dimensional multiple would be clearer if it were written
((1,2,3), (4,5,6))
For two dimensions, it is convenient to talk of “rows” and “columns”. Here is an identity declaration using the previous row-display:
[,]INT e = ((1,2,3), (4,5,6))
The first “row” of e
is yielded by the
row-display (1,2,3)
and the second “row” is
yielded by (4,5,6)
. The first “column” of
e
is yielded by the row-display (1,4)
, the
second “column” by (2,5)
and the third
“column” by (3,6)
. Note that the number of
elements in each “row” is the same, and the number of
elements in each “column” is also the same, but that the
number of “rows” and “columns” differ. We say
that e
is a rectangular
multiple. If the number of “rows” and
“columns” are the same, the multiple is said to be
square. Here is an
identity declaration for a square multiple:
[,]CHAR f = (("a","b","c"), ("A","B","C"), ("1","2","3"))
All square multiples are also rectangular, but the converse is not
true. Note that in the row-display for a multi-dimensional multiple
of characters, it is not possible to use the special denotation for a
[]CHAR
.
The base mode of a multiple can be any mode, including another row mode. For example:
[][]CHAR days = ("Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday", "Sunday")
The mode is said “row of row of CHAR
”. Note that days
is one-dimensional, each element consisting of a one-dimensional
[]CHAR
. The shorthand denotation for a []CHAR
can be
used in this case. Because the base mode is []CHAR
, the
individual []CHAR
s can have different lengths. Here is another
example using integers:
[][]INT trapezium = ((1,2),(1,2,3),(1,2,3,4))
Each element of a multiple has one integer associated with it for
each dimension. These integers increase by 1
from the
first to the last element in each dimension. For example, in the
declaration
[]INT r1 = (90,95,98)
the integers associated with the elements are [1]
,
[2]
and [3]
(see the next section for an
explanation of why the integers are written like this). Remember that
the first element in a row-display always has an associated integer of
[1]
. These integers are known as
subscripts4.2 or
indexers. Thus the subscript of 98
in r1
is
[3]
. In the two-dimensional multiple
[,]INT r2 = ((-40, -30, -20), (100, 130, 160))
the subscripts for -40
are [1,1]
and the subscripts for
160
are [2,3]
.
We say that the lower bound of
r1
is 1
, and its upper
bound is 3
. The multiple
r2
has a lower bound of 1
for both the first
and second dimensions, an upper bound of 2
for the first
dimension (2 “rows”) and an upper bound of 3
for the second dimension (3 “columns”). We shall write the
bounds of r1
and r2
as [1:3]
and [1:2,1:3]
respectively. The bounds of a flat
multiple, unless specified otherwise (see the section on trimming),
are [1:0]
.
The bounds of a multiple can be interrogated
using the operators LWB for the lower
bound, and UPB for the upper bound. The
bounds of the first, or only, dimension can be interrogated using the
monadic form of these operators. For example,
using days
defined above, LWB days
yields
1
, and UPB days
yields 7
. Where
the multiple is multi-dimensional, the bounds are interrogated using
the dyadic form of LWB
and
UPB
: the left operand is the dimension while the right
operand is the identifier of the multiple. For example, 1 UPB
r2
yields 2
and 2 UPB r2
yields
3
. The priority of the dyadic operators
is 8
.
()CHAR c1 = "Today"
[]CHAR c2 = 'Yesterday'
[]INT i1 = (1, 2.0, 3)
first 4 odd numbers
, write an
appropriate identity declaration.
Ans[]CHAR s = "abcdefgh"; []REAL r = (1.4e2, 3.5e-1, -4.0); [,]INT t = ((2,3,5), (7,11,13), (17,19,23))
what is the value of the following:
Ans
UPB s
LWB r
2 UPB t - 1 LWB t + 1
[]REAL b = ()