Contents  >>  << 

p {~ q i. ] Improved initial writing: 2006-11-07
last updated: 2007-11-29

The monad p {~ q i. ] where p and q are lists of 1-byte characters performs character mappings. For example:

   'AA aa'=: a.{~ 65 97 +/ i.26
   AA
ABCDEFGHIJKLMNOPQRSTUVWXYZ
   aa
abcdefghijklmnopqrstuvwxyz

   lc=: (aa,a.) {~ (AA,a.) i. ]

   lc 'United States of America, Union of South Africa'
united states of america, union of south africa

The phrase and its variants ( (q i.]){p"_ and q&i.{p"_ ) are now supported by special code and are faster and leaner. The following benchmarks demonstrate the improvement:

x=: a. {~ 1e6 ?@$ 256
p=: a. {~ 123 (22 b.) i.256

ts=: 6!:2, 7!:2@]  NB. time and space
ts 'Expression'
Expression    J 6.02    J 6.01    Ratio
lc x  0.004747 1.04934e6 0.018244 9.43795e6  3.84 8.99
(p{~a.i.]) x 0.001450 1.04979e6 0.018401 9.43840e6 12.69 8.99


Contents  >>  <<