On Dec 21, 2007 8:22 AM, Jack Andrews <[EMAIL PROTECTED]> wrote:
>  upper=: (a.,~a.{~65+i.26) {~ (a.,~a.{~97+i.26) i. ]
>  lower=: (a.,~a.{~97+i.26) {~ (a.,~a.{~65+i.26) i. ]
> seems a little unwieldy... are there better ways?

Sure.

For example (with my verb display set to linear):
   (a.{~a.i.upper a.) {~ a.i.]
(a. (97+i.26)}~'ABCDEFGHIJKLMNOPQRSTUVWXYZ') {~ a. i. ]

In other words:
   up=: (a. (97+i.26)}~a.{~65+i.26) {~ a. i. ]
   (up -: upper) a.
1

Which is essentially your A2Z and a2z -- everything between
those parenthesis will be evaluated only once (when the verb
is defined).

And, as you have noted, you can define lower basically the same way
(swapping 65 and 97 in this case).

In other words, most of the complexity of this problem has to
do with specifying the upper case and lower case sets of characters.

That said, in terms of efficiency, these approaches are essentially
identical:
   ts=:6!:2,7!:2
   text=:a.{~32+?1e7#95
   ts 'up text'
0.019557 1.6778e7
   ts 'upper text'
0.01945 1.67781e7
   ts 'up text'
0.019705 1.6778e7
   ts 'upper text'
0.0207132 1.67781e7
   ts 'up text'
0.0194938 1.6778e7
   ts 'upper text'
0.0217025 1.67781e7

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to