[net.lang.apl] another bug with scan...

gj@cornell.UUCP (Greg Johnson) (06/23/84)

Lee Dickey mentioned that the scan operator in APL 11 does not work right for
some non-associative operators.  Here is another error:
	+\ iota 0
0
	rho rho +\ iota 0
0

        m { 1 2 0 3 rho 0
	n { 1 2 3 0 rho 0
	+\m

	rho rho +\m
1 2 0 3

	+\n
0
	rho rho +\n
0

It turns out that at least in the APL distributed with 4.2 BSD UNIX
the problem illustrated above is easy to fix.  The result of applying
the scan operator to a function and then to some data is ALWAYS supposed
to have the same shape as the data.  If the last dimension of the data
is zero, then the interpreter tries to return (as a scalar) the identity
element of the function used with scan.  In module ak.c there is an
explicit test to see whether the last dimension is zero, and if it is
the appropriate identity element is created.  This entire "if" statement
(it is about thirty lines long) can simply be commented out.  Its
first line is:

	if(idx.dimk == 0) {

I found this bug while figuring out a solution to the "runs and wedges"
problem of a few articles back.

				- Greg Johnson
				  ...!ihnp4!cornell!gj
				  gj@cornell

ljdickey@watmath.UUCP (Lee Dickey) (06/29/84)

Greg is right.  The expression
	rho rho +\ iota 0
should return the value  1 .  And the expression
	rho rho +\[i] 1 2 0 3 rho 0
should return the value  4  for each index  i  in  iota 4.

-- 
  Lee Dickey, University of Waterloo.  (ljdickey@watmath.UUCP)
 	... {allegra, decvax} !watmath!ljdickey