hi,

still learning j... been looking at rosetta code which is handy.  the
example of changing case here:
  http://rosettacode.org/rosettacode/w/index.php?title=Change_string_case#J

and reproduced here:
  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?

i don't know if this is any 'better':

   A2Z=.(a.i.'A')+i.26
   a2z=.(a.i.'a')+i.26
   lower=.((a2z{a.) A2Z }a.) {~ a.i.]
   upper=.((A2Z{a.) a2z }a.) {~ a.i.]
   upper '123abcDEF'
123ABCDEF
   lower '123abcDEF'
123abcdef

how could i define a word 'cmap' so that
  lower2=.cmap A2Z a2z
  upper2=.cmap a2z A2Z
?

ta,  jack
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to