background image
C
ATS
(
TM
) P
ROGRAMMING
 L
ANGUAGE
 O
VERVIEW
As revised 2006.08.23
Bionic Buffalo Tech Note #84 
Security: 
Unrestricted
ptr_to_char = ( char * ) “fine “ ; 
widestring = “a ” + ptr_to_char + L”pickle” ; // “a fine pickle”
The 
value_of
 operator can be used to extract the buffer pointer (
char *
 or 
wchar_t *
) of 
variables of these types. A subscript can be used to reference a particular character of the string. 
xchar
 represents an ISO 10646 character. (For almost all purposes, this is a Unicode character.) The 
generated C type is opaque to the application, but it can be assigned to a numeric type to extract the 
numeric value of the character. Unlike 
wchar_t
, a variable of type 
xchar
 will always be able to 
contain any ISO 10646 character.  
xstring
 is a string of ISO 10646 characters. (Practically, a Unicode string.) It can be mixed with 
char *
wchar_t *
string
, and 
wstring
 types in expressions; each type will be promoted to 
the next type as needed.  
list
 is a linked list. A variable of this type is declared as 
list (X)
, where 
X
 is the type of element 
in the list. Lists can be concatenated to form bigger lists (
list1 = list2 + list3
). 
Elements can be prepended to the beginning (
elem1 + list1
) or appended to the end (
list1 + 
elem1
). A subscript can be used to reference a specific element (
list1 [ n ]
). Negative subscripts 
cause the list elements to be referenced from the end, so 
list1 [­1]
 refers to the last element.  
The 
length_of
 operator returns the number of elements in the list. The code will not give up the 
address of a list element: you cannot write 
&(list1[n])
Using a subscript beyond the bounds of the list simply causes the reference to wrap around. In other 
words, if 
n>length_of list1
, then 
list1[n]
 is equivalent to 
list1[n mod length_of 
list1]
. If there are no elements in the list, then any reference to an element is equivalent to a 
reference to a block of 
NUL
­filled memory. 
When a subscript is followed by an exclamation mark, the referenced element is deleted from the list. 
For example, 
elem1=list1[­1!]
 deletes the last element of the list, assigning its value to 
elem1
sequence
 is almost the same as list, except for the implementation. Whereas 
list
 is implemented as 
a linked list, 
sequence
 is implemented as a flexible vector of the elements. Otherwise, 
sequence
are the same as 
list
s. A sequence is roughly equivalent to an array with flexible bounds. 
If a 
sequence
 must be expanded, then the entire sequence buffer will be re­allocated, and the old 
buffer copied to the new buffer. If an element is prepended to the beginning, then all the other values 
must be pushed up to make room. If an element is deleted from the middle, then the other elements 
above it must be moved downward to fill in the space. These can be expensive. The runtime will attempt 
to pre­allocate a buffer bigger than necessary, so reallocation is minimized. Furthermore, the buffer will 
be allocated in segments, and indexed, so the maximum disruption will be to a segment rather than to the 
Copyright 2006 Bionic Buffalo. All rights reserved.
File tn0084; Modified 2006­08­30 08:00:17
http://www.tatanka.com/doc/technote/index.html
E­mail: 
query@tatanka.com
Page 4 of 12