C
ATS
(
TM
) P
ROGRAMMING
L
ANGUAGE
O
VERVIEW
As revised 2006.08.23
Bionic Buffalo Tech Note #84
Security:
Unrestricted
string1[1..2]=”ab”
assigns to the 2
nd
and 3
rd
characters of
string1
, leaving the other
characters of
string1
unaffected.
Disjoint elements of an array,
sequence
,
plex
, or
map
may be referenced by separating subscripts
using semicolons. For instance,
array1[3;5..6]
represents the 4
th
, 6
th
, and 7
th
elements of
array1
.
3.4.2. Anonymous Lists
An anonymous
list
may be written by enclosing its elements, separated by semicolons, within square
brackets (
[
and
]
). The range operator may be used with integers. For example, the list
[ 0; 2..3 ; 5 ]
contains the elements
0
,
2
,
3
, and
5
.
The square brackets used for subscripting are a special use of an anonymous
list
.
An anonymous
list
of lvalues may be used as an lvalue. For example,
list ( unsigned ) a = [ 2 ; 3 ] ; // initialize a
int j, k ;
[ a[1] ; a[0] ] = a ;
// swaps a[0], a[1]
[ j ; k ] = a ;
// now, j = 3 and k = 2
This allows extraction of the individual elements of a
list
.
3.4.3. Reverse
The
%%
operator reverses the sequence of elements in a
string
,
array
,
list
,
plex
, or
sequence
.
It does not affect the operand, only the way the operand is viewed in an expression.
For example,
string a = “abc”, b ;
b = %% a ;
// a is unchanged, b is “cba”
3.4.4. Sparse Increment and Decrement
When accessing a
map
, or a
sparse
sequence
or
plex
, it is sometimes convenient to know the next
lower or higher key or subscript. This can be done using the
++
or
operators in the context of the
subscript. For example,
map1[key1++]
will set
key1
to the next higher key value after making the
reference, and
map1[key1]
will “decrement” the key before making the reference.
Copyright 2006 Bionic Buffalo. All rights reserved.
File tn0084; Modified 20060830 08:00:17
http://www.tatanka.com/doc/technote/index.html
Email:
query@tatanka.com
Page 8 of 12