C
ATS
(
TM
) P
ROGRAMMING
L
ANGUAGE
O
VERVIEW
As revised 2006.08.23
Bionic Buffalo Tech Note #84
Security:
Unrestricted
3.4.5. Iteration Over Lists
The
foreach
statement may be used to iterate over all of the elements in a
list
,
sequence
,
array
,
plex
, or
string
. For example,
list (string) a ;
foreach b ( a )
{ // some code goes here } ;
The code in the loop is executed as many times as there are elements in the
list
. The value of the
variable is set, in turn, to the values of every element of the
list
.
The
list
may be anonymous.
3.5. Other Features
In addition to the above, Cats includes support for exceptions, threads, objects, and other features. The
compiler also will generate additional code for debugging support. For complete details, the reader is
referred to the Cats
TM
Language Reference Manual.
4. Garbage Collection
When the
counted
keyword is used for a type, then pointers to variables of the type are counted.
When no pointers to an entity remain, then the entity is destroyed automatically.
This is not a perfect solution: it can be defeated by assigning a
counted
pointer value to a
void*
pointer. However, it can considerably reduce the number of inadvertent orphaned allocations.
5. Generated C Code
The Cats precompiler accepts Cats source code emitted by the C preprocessor, and emits C code
compliant with the C99 standard.
Ordinary C code is passed through the precompiler unchanged. Cats statements are replaced by
ordinary C statements implementing the semantics of the Cats statements. The original Cats statements
may be passed through as comments, and may be supplemented by additional commentary to aid in
understanding the generated code.
Some Cats statements can be replaced by C code at the places in the program where the Cats statements
were found. For example, type declarations without any necessary initialization translate directly at the
point of declaration.
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 9 of 12