For Programmers: Free Programming Magazines  


Home > Archive > APL > January 2005 > "Problem" with disclose









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author "Problem" with disclose
RAV

2005-01-06, 8:55 am

On both APL+Win and APL2, why does

{disclose}'A' 'B' '' 'D' 'E'

return 5 0{rho}'' ?

I would, of course, much prefer that it return 5 1{rho}'AB DE'

In other words, if the argument to disclose consists of a mixture of
scalars and empty vectors, disclose appears to "throw away" the
non-empty data.

At the company where I work, all the APLers use disclose as an idiom
to mean "remove one level of nesting from a nested vector, padding the
shorter items in the resulting array to be as long as the longest
item." Our code is full of such uses of disclose, and it shocked me
to see this "edge condition." I suppose there's some mathematical
reason why it works the way it does, but I don't find it very useful,
and it's causing us problems.
RAV

2005-01-06, 3:57 pm

On Thu, 30 Dec 2004 14:59:15 -0500, "David Liebtag"
<DavidLiebtag@vermontel.net> wrote:

>The first sentence of APL2 Programming: Language Reference Manual's
>discussion of disclose is:
>
>"All items of R must be scalars and/or arrays of the same rank."
>
>Clearly, this is not the case for your example.
>
>The LRM does go on to discuss the case where the items of the right argument
>have different shapes (on page 95). It states:
>
>If items of R are scalar or have different shapes, each is padded to a shape
>that represents the greatest length along each axis of all items of R; that
>is, the shape of each item is padded to
>
> {first}{max}/(,{rho}{each}R)~{enclose}{iota}0
>
>For your case, this results in each item being padded to zero length.
>
>Perhaps you would find the results more useful if you said this:
>
> {disclose}, {each} R
>
>David Liebtag
>IBM APL Products and Services
>


Thanks for your response, but they ARE scalars and arrays of the same
rank (1). If they weren't, you would get a RANK ERROR, which you do
get, for example, if you try {disclose}(,0) (1 1{rho}0). Only
scalars are scalar-extended.

I can see, though, why the maximum "length" in this case is 0, since
the length of the empty vector(s) is 0, and scalars have no "length."
True mathematically, but not nice in this case.

And while ,{each} would be fine if the argument to {disclose} could be
counted on to ALWAYS be a nested array containing items of rank 1 or
less, it can't. If, for example, a simple matrix is passed directly
to {disclose}, the result is the same simple matrix. Performing
,{each} beforehand would lead to a differently shaped result. I'm
afraid that a generalized solution is going to be more complicated
than that.
John Sullivan

2005-01-06, 3:57 pm

In message <r6p8t010f1kulqefqjei6nu9olc57s2lbp@4ax.com>, RAV
<PaulR@Case.com> writes
>
>I can see, though, why the maximum "length" in this case is 0, since
>the length of the empty vector(s) is 0, and scalars have no "length."
>True mathematically, but not nice in this case.


How else are you going to define scalar extension?


--
John Sullivan
gosi

2005-01-06, 3:57 pm


RAV wrote:
> On both APL+Win and APL2, why does
>
> {disclose}'A' 'B' '' 'D' 'E'
>
> return 5 0{rho}'' ?
>


www.jsoftware.com

a=:'A' 'B' '' 'D' 'E'
|syntax error
| a=: 'A''B''''D''E'

NB. this above does not work because space is not an operation

a=:'A';'B';'';'D';'E'
a
+-+-++-+-+
|A|B||D|E|
+-+-++-+-+
$a
5
>a

A
B

D
E
$>a
5 1
|:>a
AB DE
$|:>a
1 5

Martin Turner

2005-01-07, 3:55 am

The ultimate root cause of the "problematic" behaviour reported by RAV lies
in decisions of many years ago.

Trenchard Moore, a theoretician at IBM, proposed two possible ways of
handling generalised arrays. James Brown et al at IBM chose one path when
developing APL2 whereas Ken Iverson selected the other when extending Sharp
APL and developing J. Ultimately the selection between these possibilities
should be decided by utility - which choice gives a language that is more
useful and can be extended to consistently encompass new features.

I digress, but an easy distinction between these two routes (both equally
logical) is whether it is possible to enclose a scalar. In APL2 a scalar
cannot be enclosed whereas for SAPL and J it can.

As David Leibtag has pointed out, the linking of 4 scalars and one empty
vector into a single object cause the scalars to collapse to zero length
vectors because the scalars cannot be enclosed. It is necessary, therefore,
to change their rank beforehand. With SAPL and J the supposed "problem"
cannot occur and the result of the disclose would be a matrix of 5 rows and
one column.

Martin

"RAV" <PaulR@Case.com> wrote in message
news:jqd8t0t5urd33vhc3jmnj31ogq8ns9j4f2@
4ax.com...
> On both APL+Win and APL2, why does
>
> {disclose}'A' 'B' '' 'D' 'E'
>
> return 5 0{rho}'' ?
>
> I would, of course, much prefer that it return 5 1{rho}'AB DE'
>
> In other words, if the argument to disclose consists of a mixture of
> scalars and empty vectors, disclose appears to "throw away" the
> non-empty data.
>
> At the company where I work, all the APLers use disclose as an idiom
> to mean "remove one level of nesting from a nested vector, padding the
> shorter items in the resulting array to be as long as the longest
> item." Our code is full of such uses of disclose, and it shocked me
> to see this "edge condition." I suppose there's some mathematical
> reason why it works the way it does, but I don't find it very useful,
> and it's causing us problems.



Todd Marshall

2005-01-09, 3:55 am

I have been referring to this news group. What in particular do you want
to call my attention to?

/Todd

LatLong wrote:
> I would refer you to this new group thread.
>
> "Todd Marshall" <Todd@WithGLEE.com> wrote in message
> news:T9mBd.9768$iC4.5250@newssvr30.news.prodigy.com...
>
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com