C
ATS
(
TM
) P
ROGRAMMING
L
ANGUAGE
O
VERVIEW
As revised 2006.08.23
Bionic Buffalo Tech Note #84
Security:
Unrestricted
3.3.3. Transliteration
The expression
string1 $ search1 $+ replace1 $: options1
causes transliteration: if a character from
string1
matches a character from
search1
, then it is
replaced by the corresponding character from
replace1
. The number of substituted characters is
returned in the predefined variable
count
.
This is equivalent to the Perl expression
$string1 =~
tr/$search1/$replace1/<options1>
, except that the Cats expression returns the
transliterated result rather than the number of substitutions.
3.3.4. Splitting
The expression
string1 $^ delimiter1 $: options1
returns a list of substrings created by splitting
string1
using a pattern
delimiter1
.
3.3.5. Compiling Regular Expressions
A regular expression is compiled from a string by simple assignment:
regex re1 ;
re1 = “[azAZ09]” ;
// compiles the string into a regex
The reverse is also possible. Either may be cast to another within an expression. (That is, one can write
a = (regex) b
, or
b = (string) c
.)
3.4. Other New Expression and Syntax Features
3.4.1. Ranges
The range operator (
..
) allows reference to multiple elements of an array,
sequence
,
plex
, or
map
at one time. For example, the notation
array1[4..6]
refers to an array consisting of the 5
th
, 6
th
, and
7
th
elements of
array1
. When ranges are used with
map
s, the sort order for the keys is a simple binary
comparison of the key values, which may have unexpected results in some cases. When assigning to a
range, the effect is as if only the referenced elements were assigned. For example,
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 7 of 12