Home > Archive > APL > December 2005 > EACH and empty arrays
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 |
EACH and empty arrays
|
|
| Roland Besserer 2005-12-08, 6:56 pm |
|
I would appreciate if someone could explain why the following
application of EACH does not work.
The following vars and fns are defined:
MX{<-}0 3{rho}0
M{<-}1 0 0
{del}Z{<-}X LE Y
[1] @ LESS THEN OR EQUAL and ALLOWS {omega} (GREATER THEN ANYTHING)
[2] {->}((0{/=}{depth}X){or}0{/=}{depth}Y)/L1 @ RECURSIVE IF NOT SCALAR
[3] Z{<-}1 @ YES ...
[4] {->}(Y='{omega}')/0 @ ... IF Y IS {omega}
[5] Z{<-}0 @ NO ...
[6] {->}(X='{omega}')/0 @ ... IF X IS {omega}
[7] Z{<-}X{<=}Y @ OTHERWISE NORMAL FUNCTION
[8] {->}0
[9] L1:
[10] Z{<-}X LE{each}Y @ RECURSE
Now the following works:
MX ^.{<=} M
But using LE instead of <= returns a DOMAIN ERROR:
MX ^.LE M
which appears to be an issue with the use of EACH on line 10 of fn LE
when one of the arguments is an empty (aka prototype) array.
I went over the formal definition of EACH and came to the conclusion
this should work. What am I missing?
Regards
roland
APLX
| |
| David Liebtag 2005-12-08, 9:55 pm |
| Roland,
You wrote:
> I went over the formal definition of EACH and came to the conclusion
> this should work. What am I missing?
What formal definition?
The APL2 Programming: Language Reference manual says in the description of
dyadic each on page 108:
"Empty Argument: If L or R is empty, the function LO is not applied.
Instead, a related function called the fill function of LO is applied."
....
"Some functions derived by inner product or reduction may not have fill
functions. An attempt to apply such a function to each item of an empty
array generates a DOMAIN ERROR."
Implementation of support for fill functions is tricky. There are
differences even between IBM's mainframe and workstation APL2
implementations. It would not surprise me if APLX and other dialects'
implementations also had subtle variations in behavior.
David Liebtag
IBM APL Products and Services
| |
|
| David,
Not the one in the APL2 Language Reference Manual (I've been trying to
get a copy a few times in the past, even ordered it once, but got a copy
of `An Introduction to APL2' instead). Gleaned from APL2 In Depth and
the APLX docs.
I knew I was overlooking something. It's easy to forget that even for
build-in functions, a fill function is silently applied. It's now
obvious the same mechanism would apply when a user defined function is
used with an operator.
So how does one write a fill version of a user defined function?
roland
In article <1134095948.949749@r2d2.vermontel.net>,
"David Liebtag" <liebtag@us.ibm.com> wrote:
> Roland,
>
> You wrote:
>
>
> What formal definition?
>
> The APL2 Programming: Language Reference manual says in the description of
> dyadic each on page 108:
>
> "Empty Argument: If L or R is empty, the function LO is not applied.
> Instead, a related function called the fill function of LO is applied."
>
> ...
>
> "Some functions derived by inner product or reduction may not have fill
> functions. An attempt to apply such a function to each item of an empty
> array generates a DOMAIN ERROR."
>
> Implementation of support for fill functions is tricky. There are
> differences even between IBM's mainframe and workstation APL2
> implementations. It would not surprise me if APLX and other dialects'
> implementations also had subtle variations in behavior.
>
> David Liebtag
> IBM APL Products and Services
| |
| microapl@microapl.demon.co.uk 2005-12-09, 7:55 am |
| Roland,
David has correctly pointed to the problem. In APLX we try (as far as
possible) to be consistent with APL2, and if there are any differences
between mainframe APL2 and the Workstation product, we try to follow
the mainframe version. So you get a DOMAIN ERROR as specified in IBM's
APL2 Language Manual.
Ron wrote:
>
> I knew I was overlooking something. It's easy to forget that even for
> build-in functions, a fill function is silently applied. It's now
> obvious the same mechanism would apply when a user defined function is
> used with an operator.
If you think about it, there is good reason why the interpreter can't
choose a fill function for a user-defined function. It doesn't know
what the function does, and so can't know what would be a sensible
choice for the edge condition which applies when the argument is an
empty array.
>
> So how does one write a fill version of a user defined function?
>
I suppose strictly speaking you should be able to, but as far as I know
no existing interpreter would allow this. So you'd have the check the
empty case explicitly before the operation.
Richard Nabavi
MicroAPL
| |
| David Liebtag 2005-12-09, 7:55 am |
| Roland,
You can get a copy of the APL2 Programming: Language Reference manual from
our web site:
http://www.ibm.com/software/awdtools/apl/library.html
APL2 does not provide supported for developers to supply fill functions for
defined functions.
David Liebtag
IBM APL Products and Services
| |
| nospam 2005-12-09, 6:57 pm |
| It's been a while, but was that supported in the original FDP?
"David Liebtag" <liebtag@us.ibm.com> wrote in message
news:1134136099.390747@r2d2.vermontel.net...
> Roland,
>
> You can get a copy of the APL2 Programming: Language Reference manual from
> our web site:
>
> http://www.ibm.com/software/awdtools/apl/library.html
>
> APL2 does not provide supported for developers to supply fill functions
> for defined functions.
>
> David Liebtag
> IBM APL Products and Services
>
| |
|
|
David,
thanx for the link.
While the ability to use user-defined functions with operators is one of
the great evolutionary steps in APL2, isn't the inability of handling
empty arguments (I like to call them prototype arguments because that is
how I mostly use them) a major inconsistency? I does throw a wrench in
my current efforts to 'clean up' some code :-) Back to the drawing board.
Anyone know why the ability to define fill versions of user defined
functions is not support in APL2? It seems such an obvious deficiency -
now that I need it :-)
roland
In article <1134136099.390747@r2d2.vermontel.net>,
"David Liebtag" <liebtag@us.ibm.com> wrote:
> Roland,
>
> You can get a copy of the APL2 Programming: Language Reference manual from
> our web site:
>
> http://www.ibm.com/software/awdtools/apl/library.html
>
> APL2 does not provide supported for developers to supply fill functions for
> defined functions.
>
> David Liebtag
> IBM APL Products and Services
| |
|
|
Richard,
this is a case where I wouldn't care about compatibility with APL2 :-)
I have started to make more use of empty arrays (or prototypes) - it
works great as a documentation tool. While in the past I've often
pre-allocated arrays to introduce more deterministic behavior, as a
performance aid and to manage memory allocation, much faster machines
and lots more physical memory (not just virtual memory space) have
really changed my programming style.
That coupled with increased use of user defined functions applied to
operators looked like a pretty good path to me but now I have to
re-think this issue due to the added complexity of having, as you
correctly pointed out, to add checks for empty arrays (basically the
initial condition).
Wouldn't support for user defined fill functions be a great feature for
APLX V4? :-)
roland
In article <1134123516.246661.239640@f14g2000cwb.googlegroups.com>,
microapl@microapl.demon.co.uk wrote:
> Roland,
>
> David has correctly pointed to the problem. In APLX we try (as far as
> possible) to be consistent with APL2, and if there are any differences
> between mainframe APL2 and the Workstation product, we try to follow
> the mainframe version. So you get a DOMAIN ERROR as specified in IBM's
> APL2 Language Manual.
>
> Ron wrote:
>
>
> If you think about it, there is good reason why the interpreter can't
> choose a fill function for a user-defined function. It doesn't know
> what the function does, and so can't know what would be a sensible
> choice for the edge condition which applies when the argument is an
> empty array.
>
>
> I suppose strictly speaking you should be able to, but as far as I know
> no existing interpreter would allow this. So you'd have the check the
> empty case explicitly before the operation.
>
> Richard Nabavi
> MicroAPL
| |
| Jane Sullivan 2005-12-10, 3:55 am |
| In message <roland-9A243A.12120309122005@cnews.newsguy.com>, Ron
<roland@quadsys.com> writes
>
>
>Richard,
>
>this is a case where I wouldn't care about compatibility with APL2 :-)
>
>I have started to make more use of empty arrays (or prototypes) - it
>works great as a documentation tool. While in the past I've often
>pre-allocated arrays to introduce more deterministic behavior, as a
>performance aid and to manage memory allocation, much faster machines
>and lots more physical memory (not just virtual memory space) have
>really changed my programming style.
>
>That coupled with increased use of user defined functions applied to
>operators looked like a pretty good path to me but now I have to
>re-think this issue due to the added complexity of having, as you
>correctly pointed out, to add checks for empty arrays (basically the
>initial condition).
Does APLX have error trapping? (I'd have thought so.) Why not try the
operation first, then if it fails do the empty array check.
>
>Wouldn't support for user defined fill functions be a great feature for
>APLX V4? :-)
>
>roland
--
Jane
| |
| Ted Edwards 2005-12-11, 6:56 pm |
| Ron wrote:
> Anyone know why the ability to define fill versions of user defined
> functions is not support in APL2? It seems such an obvious deficiency -
> now that I need it :-)
What do you mean by "define fill versions"? How would that work? APL
knows how {and}, {or} and / work so it is easy to define {and}/{iota}0.
Only you know what FUN and OP do so only you can define how to deal
with empty arrays.
As to starting documentation, I use the APL2 editor and start with
document{is}0{rho}''
and double click document to edit it. I wind up with a vector of
character vectors with empties for blank lines. It's never given me any
trouble.
Ted
| |
| Dick Bowman 2005-12-12, 3:55 am |
| Ted Edwards <Ted_Espamless@telus.net> wrote in news:IiZmf.146211$S4.130317
@edtnps84:
> Ron wrote:
>
> What do you mean by "define fill versions"? How would that work? [...
deleted ...]
It would (I believe) need some sort of extension to to function definition
syntax. In the same way that the (arguably more useful) ability to define
a function inverse would.
Both these proposals trade simplicity for versatility.
I have nothing to offer in the way of suggesting how either might be
realised.
I think that extending APL in these ways might be desirable in terms of
allowing the programmer to make defined functions which behave more like
primitives.
| |
| nospam 2005-12-12, 6:56 pm |
| Wasn't such a facility one of the things removed from the original APL2 FDP
before it was brought to market? Maybe an extra local quad-variable or two?
"Dick Bowman" <dick@dickbowman.org.uk> wrote in message
news:Xns972A5254CAB0Fbowmanapldemoncouk@
158.152.254.254...
> Ted Edwards <Ted_Espamless@telus.net> wrote in news:IiZmf.146211$S4.130317
> @edtnps84:
>
> deleted ...]
>
> It would (I believe) need some sort of extension to to function definition
> syntax. In the same way that the (arguably more useful) ability to define
> a function inverse would.
>
> Both these proposals trade simplicity for versatility.
>
> I have nothing to offer in the way of suggesting how either might be
> realised.
>
> I think that extending APL in these ways might be desirable in terms of
> allowing the programmer to make defined functions which behave more like
> primitives.
>
|
|
|
|
|