SORTING a character matrix
Author Message
SORTING a character matrix

As a beginner, I am looking for simple APL code to sort a character
matrix
eg LIST is :
BBBB
CCCC
AAAA

and I need
AAAA
BBBB
CCCC

Any simple way?
Joe

Wed, 12 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:

> As a beginner, I am looking for simple APL code to sort a character
> matrix
> ....

Try this:

LIST[{quadav}{gradeup}LIST;]

The left argument is optional but when present gives information
regarding the collating sequence for character sorts. For exact details,
you should consult a manual.

As far as I know all implementations support this.

Mike Powell

Wed, 12 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:
>As a beginner, I am looking for simple APL code to sort a character
>matrix
>eg LIST is :
>BBBB
>CCCC
>AAAA

>and I need
>AAAA
>BBBB
>CCCC

>Any simple way?
>Joe

LIST<-LIST[{gradeup}LIST;]

John Sullivan
-------------
remove the dots from the first three (Welsh) words for my real address

Thu, 13 Apr 2000 02:00:00 GMT
SORTING a character matrix

try LIST[A gradeup LIST;]
where A is a character vector in desired sorting order.
i.e. A is 'AaBb.....'
--
Don Kelly

remove the "bull " to reply

Thu, 13 Apr 2000 02:00:00 GMT
SORTING a character matrix

: As a beginner, I am looking for simple APL code to sort a character
: matrix
: eg LIST is :
: BBBB
: CCCC
: AAAA
:
: and I need
: AAAA
: BBBB
: CCCC
:
: Any simple way?
: Joe
:

It cannot be simpler. Just write:

LIST[#av{gradeup}LIST;]

The grade up character comes with {left alt}{left shift} 4 if you are
using APL+Win.
Check your APL documentation for "character grade up".
Tomas

Thu, 13 Apr 2000 02:00:00 GMT
SORTING a character matrix

:
: > As a beginner, I am looking for simple APL code to sort a character
: > matrix
:
: Try this:
: LIST[{quadav}{gradeup}LIST;]
: The left argument is optional but when present gives information
: regarding the collating sequence for character sorts. For exact details,
: you should consult a manual.
: As far as I know all implementations support this.
: Mike Powell
:
Actually, APL+Win does not support it. It gives a DOMAIN ERROR if one tries
{gradeup} on characters without a left argument. It requires at least one
character (rank=1) to left. Of some reason, empty ('') will also do, but a
character without rank does not.

{gradeup} on numbers always gives an error when dyadic.

Perhaps not fully logic...?

Thu, 13 Apr 2000 02:00:00 GMT
SORTING a character matrix

list[{quad}av {upgrade} list;]
should do it.
Bob
ps: You can supply a fancier left argument if you want to do things
like:
- change the collating sequence of blank, numbers, etc
- make upper/lower case characters collate to the same value
and so on. RTFM.

Quote:

> As a beginner, I am looking for simple APL code to sort a character
> matrix
> eg LIST is :
> BBBB
> CCCC
> AAAA

> and I need
> AAAA
> BBBB
> CCCC

> Any simple way?
> Joe

Fri, 14 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:

[snip]

> I belive that (at least in APL+) the left argument is required when doing
> a character grade (sort).

> I have a standard variable which I use as the left arg to character grade
> -- it ensures that "Aa" sorts after "AA" but before "AB", which is not the
> case if []AV is the left arg. but this is an optional refinement.

>               -David E. Siegel
>                Software Developer, Financial Reporting Software (FRS)

From the Dyalog APL manual description of monadic Grade Up with a right
argument named Y:

If Y is a character array, the implied collating sequence is the ordering
of characters in [the atomic vector].

--

Sat, 15 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:
>From the Dyalog APL manual description of monadic Grade Up with a right
>argument named Y:

>If Y is a character array, the implied collating sequence is the ordering
>of characters in [the atomic vector].

>--

This is obviously an implementation difference:

From The APL+Win Manual:

|"Numeric Grade Up
|
|Syntax: res {gets} {gradeup} arg
|<snip descriptiption of numeric grade>
|
|Chararacter Grade Up
|
|Syntax: res {gets} larg {gradeup} rarg
|
|Return ascending sort order of a character array. larg, rarg: any
character nonscaler |array.
|<snip rest of manual entry>"
[End quote of manual]

In short, according to the manual, character grade up can not be monadic
in APL+

-David E. Siegel
Software Developer, Financial Reporting Software (FRS)

Sat, 15 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:

>> As a beginner, I am looking for simple APL code to sort a character
>> matrix
>> ....

>Try this:

>LIST[{quadav}{gradeup}LIST;]

>The left argument is optional but when present gives information
>regarding the collating sequence for character sorts. For exact details,
>you should consult a manual.

I belive that (at least in APL+) the left argument is required when doing
a character grade (sort).

I have a standard variable which I use as the left arg to character grade
-- it ensures that "Aa" sorts after "AA" but before "AB", which is not the
case if []AV is the left arg. but this is an optional refinement.

-David E. Siegel
Software Developer, Financial Reporting Software (FRS)

Sat, 15 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:

>try LIST[A gradeup LIST;]
>where A is a character vector in desired sorting order.
>i.e. A is 'AaBb.....'
>-

You will get a slightly bettter result if A is a two row matrix

ABCDE...
abcde...

In this way "AAq" will sort before "aaZ", and "Donald" will sort after
"doctor".  Case difference will be ignored unless it is the only tie
breaker available.

-David E. Siegel
Software Developer, Financial Reporting Software (FRS)

Sun, 16 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:

>> I belive that (at least in APL+) the left argument is required when doing
>> a character grade (sort).
>From the Dyalog APL manual description of monadic Grade Up..., the implied collating sequence
>is the ordering of characters in [the atomic vector].

An interesting fact would be the reasoning that APL+ has for not allowing an
implied left argument for grade.  In our environment we use a "sort" verb, to
cover this missing piece, but it would be interesting all the same.

--
|\/| Randy A MacDonald       | Bring me... BLUE PAGES!!!!

BSc(Math) UNBF '83      | APL: If you can say it, it's done.

| Also http://www.godin.on.ca/randy
------------------------------------------------<-NTP>----{ gnat }-

Sun, 16 Apr 2000 03:00:00 GMT
SORTING a character matrix

-

->> I belive that (at least in APL+) the left argument is required when doing
->> a character grade (sort).
-
->From the Dyalog APL manual description of monadic Grade Up..., the implied c
-ollating sequence
->is the ordering of characters in [the atomic vector].
-
-An interesting fact would be the reasoning that APL+ has for not allowing an
-implied left argument for grade.  In our environment we use a "sort" verb, to
-cover this missing piece, but it would be interesting all the same.
-

Characters have no implicit ordering. Even complex numbers can be partially
ordered, but characters can only be ordered with respect to a collating
sequence. It is true that most APL systems do have at least one collating
sequence that seems to be built in (usually called quad-av) but from a language
perspective this is in irrelevant. Since a collating sewuence is required to
formally define the meaning of the primitive, a collating sequence is required
as part of calling it.

../Leigh

--------------------------------------------------------
...but they were few and, as usually happens,
wisdom was forced to yield to numbers.
Titus Livius (History of Rome, XXI, 4)
--------------------------------------------------------
Leigh Clayton           loc at Soliton dot com

Sun, 16 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:

> -

> ->> I belive that (at least in APL+) the left argument is required when doing
> ->> a character grade (sort).
> -
> -An interesting fact would be the reasoning that APL+ has for not allowing an
> -implied left argument for grade.  In our environment we use a "sort" verb, to
> -cover this missing piece, but it would be interesting all the same.
> -

>  Characters have no implicit ordering. Even complex numbers can be partially
> ordered, but characters can only be ordered with respect to a collating
> sequence. It is true that most APL systems do have at least one collating
> sequence that seems to be built in (usually called quad-av) but from a language
> perspective this is in irrelevant. Since a collating sewuence is required to
> formally define the meaning of the primitive, a collating sequence is required
> as part of calling it.

Leigh's comment is correct, as far as it goes. The absence of a monadic case
for character gradeup/gradedown was intentional when we designed and implemented
it. Our rationale was that a monadic grade that used quadav (the vendor's internal
ordering of the APL character set. Different for EACH APL vendor, even to the
positions of the alphabets!) as its collating sequence would make porting of
APL applications to other platforms harder, because there would be no
obvious way to tell that a sensitivity to platform was present in the code.
(E.g., one vendor might sort blank before the alphabet, another might sort
blank after the alphabet.). By forcing the application writer to explicitly place
quadav as the left argument, that sensitivity would be explicit in the application.

Use of other collating sequences, such as ' abcd...' would be portable, and
present no problem.

Now, in retrospect, this was right up there with rearranging the deck chairs on
the Titanic. Nice work, and probably a good design decision, BUT it had a
few problems:
- The problems of porting APL applications to other systems are so huge
that this pales by comparison. For example, multiuser file applications
that require synchronization of many tasks, AND run efficiently.

- 99.9% of the uses of character upgrade that I have observed in running
systems use quadav as the left argument, because the writers don't care
about portability.  More properly, their management is not willing to
pay for them to be concerned about portability.

- Utility functions that are intended to accept a variety of data types
(numeric or character) end up getting really ugly, because they
have to split into two cases depending on the data type of the argument,
so they can do the monadic sort on numbers and the dyadic sort on
characters.
This often makes the utilities so slow (detect array type and handle
characters by some expression such as:
{->}( ' '=1{take}0{rho} argument){rho}label
NB. Yes, {*filter*}ia. That is a goto.) and hard to maintain
that the programmer codes something specific to the application,
rather than using the (already debugged) generic utility.

Given all this, I fully support removing the few lines of code from APL
interpreters that forbid the monadic character case...

Bob

Mon, 17 Apr 2000 03:00:00 GMT
SORTING a character matrix

Quote:

> A user-defined collating sequence was generally needed if the result
> was going to be shown to a user, and it had the advantage of making
> the code portable to APLs with different #AV ordering. Requiring a
> left argument nudged the programmer in the direction of portability.

Note that this only works if #AV is not ordered meaningfully.

Otherwise, the typical idiom is mat[#AV{gradeup}mat;]
Which is less portable than a language-defined ordering.

--
Raul

Mon, 17 Apr 2000 03:00:00 GMT

 Page 1 of 2 [ 24 post ] Go to page: [1] [2]

Relevant Pages

Powered by phpBB® Forum Software