chars ← ##.ucase chars                      ⍝ Upper-casification.

Returns  the  upper-case equivalent of its simple character array argument. Note
that  this function works with arguments of any rank. Note also, that the funct-
ion may easily be extended to work with "Dyalog ALT" or a font of our own.

Technical note:

The code for ucase looks like this:

    ucase←{                                         ⍝ Upper-casification,
        lc←'abcdefghijklmnopqrstuvwxyzåäöàæéñøü'    ⍝ (lower case alphabet)
        uc←'ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖÀÆÉÑØÜ'    ⍝ (upper case alphabet)
        (uc,⎕av)[(lc,⎕av)⍳⍵]                        ⍝ ... of simple array.
    }

John Daintree  points out that, as ⎕AV⍳ is an "idiom" in Dyalog Version 10.0 and
above,  ⎕av⍳⍵ is considerably faster than (lc,⎕av)⍳⍵. To exploit this we inject,
rather  than  prefix, mapping characters into a copy of ⎕av. A further advantage
is  that  we can do this ahead of time and avoid the runtime construction of the
"from" and "to" vectors, by binding (deriving) a ucase function:

    lc←'abcdefghijklmnopqrstuvwxyzåäöàæéñøü'    ⍝ (lower case alphabet)
    uc←'ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖÀÆÉÑØÜ'    ⍝ (upper case alphabet)

    av←⎕av                                      ⍝ temp copy of ⎕av.
    av[av⍳lc]←uc                                ⍝ subs upper for lower case.

    ucase ← av∘{⍺[⎕av⍳⍵]}                       ⍝ derive new function.

    ⎕ex'av'                                     ⍝ remove temp variable.

    ucase 'Toto'
TOTO

Note  that  in the experimental "Function Results Edition" version of Dyalog, we
can  encapsulate  the  construction of the function in a function- or "closure-"
returning function:

    mapsto∆ ← {             ⍝ returns function, which maps ⍺ chars to ⍵ chars.
        av←⎕av              ⍝ all chars.
        av[av⍳⍺]←⍵          ⍝ subs ⍺ chars with ⍵ chars.
        {av[⎕av⍳⍵]}         ⍝ return mapping function.
    }

    ucase ← lc mapsto∆ uc   ⍝ upper-casification closure.

    lcase ← uc mapsto∆ lc   ⍝ lower-casification closure.

    ⎕←lcase ⎕←ucase 'Toto'  ⍝ test upper- and lower-case cases.
TOTO
toto

Finally,  we  could exploit "retained hash tables" (introduced in Dyalog version
10.0)  and "squad indexing" (from version 11.0) to produce this reasonably quick
derived function:

    ucase ← (uc,⎕av)∘(⌷⍨)∘⊂∘((lc,⎕av)∘⍳)    ⍝ upper-casification.           <V>

Example:

      ucase 2 8⍴'please, speak up'
PLEASE,
SPEAK UP

See also: lcase

Back to: contents

Back to: Dyalog APL

Trouble seeing APL font?