The bounds of a multiple can be changed using the @
construction. For example, in the declaration
[]CHAR digits = "0123456789"[@0]
the bounds of digits
are [0:9]
. Bounds do
not have to be non-negative. For example,
[,]INT ii = ((1,2,3),(4,5,6)); [,]INT jj = ii[@-3,@-50]
whence the bounds of jj
are
[-3:-4,-50:-48]
. Notice that you cannot change the
bounds of a row-display (except by using a cast--see section
10.5). For now, always declare an
identifier for the display, and then alter the bounds. The bounds of
a slice can be changed:
[,]INT ij = ((1,3,5),(7,9,11),(13,15,17)); []INT ij2 = ij[2,][@0]
The declaration for ij2
could also be written
[]INT ij2 = ij[2,@0]
Wherever an integer is required in the above, any unit yielding an integer will do. Thus it is quite in order to use the formula
(a+b) UPB r
where the parentheses are necessary if a+b
is expected to
yield the dimension of r
under consideration (because the
priority of UPB
is greater than the priority
of +
).
A trimmer uses the
: construction. In the context of the
declaration of digits
above, the phrase
digits[1:3]
yields the value "123"
with mode
[]CHAR
. Again, using the declaration of r
in the last set of exercises, r[1:2,1]
yields
(1,2)
, and r[1:2,1:2]
yields
((1,2),(5,6))
.
Trimming is particularly useful with values of mode
[]CHAR
. Given the declaration
[]CHAR quote = "Habent sua fata libelli"
(the quotation at the start of the acknowledgements in the “Revised Report”),
quote[:6] quote[8:10] quote[12:15]
yield the first three words. Note that when the first subscript in
a trimmer is omitted, the lower bound for that dimension is assumed,
while omission of the second subscript assumes the corresponding upper
bound. Again, any unit yielding INT
may be used for the
trimmers. The context for a trimmer or a subscript is
meek.
Omission of both subscripts yields the whole
slice with a lower bound of 1. So, the upper
bound of the phrase digits[:]
is 10
which is
equivalent to digits[@1]
.
The lower bound of a trimmer
is, by default,
1
, but may be changed by the use of @
. For
example, digits[3:6]
has bounds [1:4]
, but
digits[3:6@2]
has bounds [2:5]
. The bounds
of quote[17:]
mentioned above are [1:7]
.
months
on the lines of
the declaration of days
in section 3.1.
Ans[,]INT i = ((1,-2,3,4),(-5,6,7,8)); []REAL r= (1.4,0,-5.4,3.6); []CHAR s= "abcdefghijklmnopqrstuvwxyz" [@ ABS"a"]what are the values of the following phrases? Ans
2 UPB i + UPB s[@1]
r[2:3]
i[2,2] - r[3]
i[2,2:]
s[ABS"p":ABS"t"]
Sian Mountbatten 2012-01-19