Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

To Upper Case

77 views
Skip to first unread message

Ray Cannon

unread,
Mar 4, 2002, 11:13:25 AM3/4/02
to
Hi,

Here is a very simple question.

What is the "best" way to convert lower case letters in an DYALOG APL/W
variable to uppercase?

There may be more than one correct answer <evil grin>.

I am particularly interested in :-

a) Large VTVs (Vector of Text Vectors with a large number of elements)

b) Simple small text vectors

The solution can use []NA calls (e.g. C's or .Net "toUpper") or be all in
APL.

Should one replace individual characters "in-situ" or create a new variable?

"I" am not interested in how to do it in A, J or K etc, but I know that wont
stop you <grin>.

I am assuming that conversion from uppercase to lowercase, is the same basic
problem and so can be solved in a similar fashion, but if you know of any
pitfalls in this area, please let me/us know.

Ray

"Best" = robust, fast, maintainable. Might also be Elegant, Transportable
(between APL's and/or environments).


Fred Honea

unread,
Mar 5, 2002, 3:26:10 AM3/5/02
to
Ray,

Here is one way:

[0] R<-CAP S;A
[1]
A<-'ABCDEFGHIJKLMNOPQRSTUVWXYZÇÑÜÁÉÍÓÚabcdefghijklmnopqrstuvwxyzçñüáé³óú'
[2] R<-{quad}AV
[3] R[ {quad}AV{iota}A[34+{iota}34]]<-R[{quad}AV{iota}A[{iota}34]]
[4] R<-R[{quad}AV{iota}S]

A is the alphabet you want to mask and 34 are the number of caps in your
alphabet.

/fred

----- Original Message -----
From: "News Gateway" <owner...@sol.sun.csd.unb.ca>
To: <AP...@LISTSERV.UNB.CA>
Sent: martes, 05 de marzo de 2002 3:14
Subject: To Upper Case


> X-From: "Ray Cannon" <ray_c...@compuserve.com>

Morten Kromberg

unread,
Mar 5, 2002, 4:42:02 AM3/5/02
to
Hi Ray,

Don't have any code for you, but my suggestion would be:

- Build a fixed 256-element translate table once and for all (you can replace it at startup if different language environments make this necessary). Don't use a function which builds the translate table each time, the overhead is too big.
- ENLIST the vectors of vectors to make a single vector and translate that using TABLE[{quad}AV{iota}data]
- Use partitioned enclose to convert the long vector back into individual pieces.
- Put a test on the depth of the argument and special-case the simple case.

/ Morten

Richard Harrison

unread,
Mar 5, 2002, 9:03:19 AM3/5/02
to
Ray,

"Best"? Hmmmm...it's indefinitely extensible. Chopping out the upper-
to-lower aspect of the functionality would decrease "fat-in-the-middle"
memory demands. Here, the dialect is native Dyalog, i.e., []ML=0, but
I have a corresponding widget in my APL2 toolbox on the mainframe.

Read "©" as "lamp"...
-----------------------------------------------------------------------
R<-{CSW}SWAP_CASE CHAR;AV
©' RFH - Swap alphabetic case from lower-to-upper or
© upper-to-lower, according to preference set by
© (optional) case-switch, >CSW< as:
© CSW=0...lower case to upper case (default)
© CSW=1...upper case to lower case
© >CHAR< simple, character scalar or array of any shape or rank.

© Take control of positions of English alphabet from []AV.
AV<-'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
AV<-((AV iota AV)=iota rho AV)/AV<-AV,[]AV © Kill redundant entries.
->(0=[]NC'CSW')take LSWAP diamond CSW<-0 © Default, if no >CSW<.
LSWAP:R<-AV[R+26×((R<-AV iota CHAR)epsilon(26×CSW)+iota 26)ׯ1*CSW]
-----------------------------------------------------------------------

Note: the use of *each* extends this to nested vectors and arrays, e.g.,

SWAP_CASE each A

where A is nested, so long as each nested element discloses to a simple
character scalar or array.

Richard

Tomas Gustafsson

unread,
Mar 5, 2002, 12:23:08 PM3/5/02
to
Converting to upper- or lowercase is often done in order to perform
case-insensitive string searches. I'd like to point out, that the best way
to improve performance in such operations is to completely eliminate the
need for change of case. The possibilities much depend on the type of stored
data, but if you are able to save it already turned into uppercase, the only
thing you need to do is change the search keyword to uppercase.

There may be a lot of techniques to use. For example, in search-intense
applications you could keep handy an additional variable, which indicates
which of the words start with an uppercase character, and then store all
character data in lowercase. With one byte (= 8 bits) you will be able to
describe case for eight words in the string.
/ Tomas

"Ray Cannon" <ray_c...@compuserve.com> skrev i meddelandet
news:e3Ng8.93541$Ah1.12...@news2-win.server.ntlworld.com...

Richard Harrison

unread,
Mar 5, 2002, 3:53:55 PM3/5/02
to
Ooops! Should have typed "drop" instead of "take", i.e.,

->(0=[]NC'CSW')take LSWAP diamond CSW<-0

should have been

->(0=[]NC'CSW')drop LSWAP diamond CSW<-0

Tracker

unread,
Mar 5, 2002, 9:47:09 PM3/5/02
to
I'd use the Windows API Call, CharUpperBuffA in USER32.DLL.
APL/W
'CUB' []na 'USER32|CharUpperBuffA =T[] I4'
CUB 'Test' 4
TEST


In APL+Win, it would be:
'DLL USER32.CharUpperBuffA(*C1<-,I4) []NA 'CUB'
CUB 'Test' 4
TEST


This is a very fast on both systems for large arrays. I guess you also need
to define large! <g> 4MB variables work fine.

Brent


"Ray Cannon" <ray_c...@compuserve.com> wrote in message
news:e3Ng8.93541$Ah1.12...@news2-win.server.ntlworld.com...

Tracker

unread,
Mar 6, 2002, 11:33:50 AM3/6/02
to
And alternately, in APL+Win what I really use is:
[]wcall 'CharUpper' text

where text is any text string.


"Tracker" <latitude...@yahoo.com> wrote in message
news:Nqfh8.38854$ZC3.3...@newsread2.prod.itd.earthlink.net...

Kevin R. Weaver

unread,
Mar 6, 2002, 12:16:17 PM3/6/02
to
Here's A (another) way:

B {assigned} DATA {epsilon} lower_case_alphabet

DATA[B/{iota}{rho}B] {assigned} upper_case_alphabet[lower_case_alphabet {iota}
B/A]

Veli-Matti Jantunen

unread,
Mar 6, 2002, 1:15:18 PM3/6/02
to
>Ray Cannon:

> What is the "best" way to convert lower case letters in an DYALOG APL/W
> variable to uppercase?

> "Best" = robust, fast, maintainable. Might also be Elegant, Transportable


> (between APL's and/or environments).

Aarghh - no one this far has proposed any dfns, so...

N.B.
a = <alpha> = left arg; may be 0 (default) = convert to uppercase, or 1
= vice versa
w = <omega>
<- = <assign>
<> = <diamond>
@ = <lamp>

UC <- {
fr <- 'abc...',[]AV @ list of lower case characters, MAY be
different than eg. with []NA's
to <- 'ABC..',[]AV @ corresponding upper cases
a <- 0 @ default left arg = 0 = change to
uppercase
(fr to) <- a {a=1: <reverse>w <> w}to fr @ check for a = 1 = change
to lowercase
{1< <abs><depth>w: <del><each>w <> to[fr<iota>w]}w @ nested?
}

"Best" - hmmm... this _has_ been my old workhorse, but of course there are
better
ones around the corner, "Transportable" this ain't -- but the basic <gawk>
idea can
be easily rewritten, "Elegant" is in the eye of the beholder...

-Veli-Matti


Eric Landau

unread,
Mar 6, 2002, 5:51:40 PM3/6/02
to
In article <Oxrh8.40902$0C1.3...@newsread1.prod.itd.earthlink.net>,
"Tracker" <latitude...@yahoo.com> wrote:

|And alternately, in APL+Win what I really use is:
|[]wcall 'CharUpper' text
|
|where text is any text string.

In APL+Win, you might try the UPPERCASE function in the TOOLS\ASMFNS
WS (which has been shipped with the interpreter at least since
APL*Plus III became APL+Win, and which has a LOWERCASE function also).


Eric Landau, APL Solutions, Inc.
"Sacred cows make the tastiest hamburger." - Abbie Hoffman

Tracker

unread,
Mar 6, 2002, 8:38:19 PM3/6/02
to

"Eric Landau" <ela...@cais.com> wrote in message
news:a666hs$3e8...@news.rcn.com...

And yes, UPPERCASE is fast. If UPPERCASE is a 1, The []NA using
USER32.CharUpperBuffA is a 3.5 and []WCALL 'CharUpper' is a 5, lower number
being fastest under APL+Win.


Fred Honea

unread,
Mar 7, 2002, 6:38:23 AM3/7/02
to
"Tracker" latitude...@yahoo.com wrote:
>
> And alternately, in APL+Win what I really use is:
> []wcall 'CharUpper' text
>
> where text is any text string.

Watch out with this one if your text is not English!

/fred

Gilbert Giappési

unread,
Mar 7, 2002, 1:04:25 PM3/7/02
to
Hello,
I am not sure I have followed the matter since its beginning.
I am just discovering the forum!
(Sorry, I am not familiar with how to represent APL but the following
may help.)

This is how I do it under IBM/APL2 (Sorry this is the only flavor I have
ever practiced, with its APL father(s) ) and may be it can be
"transposed" to other flavors(??). This is a 100% APL solution.

RESULT is TABLE [1+quadAF FIELD]

where
RESULT is the translated field
TABLE is a vector containing quadAV where the any lowercase combination
of characters to be translated have been rewritten in upper case at
their locations
3-FIELD is the vector where the lowercase are to be upped.

This works well and so far has satisfied my needs.
It translates ONLY the characters that are modified in TABLE.
... and all have already inferred it : it translates whatever in
whatever else provided it the ad hoc modification is made in TABLE.

Hope my explanations are clear enough.

Gilbert

0 new messages