[net.lang.apl] Indexing

honton (01/29/83)

  In working with apl for an extended period of time I find the indexing
operations inconsistent with the rest of the language.  What goes on is more
than what meets the I.
  In trying to come up with something better, I thought about an indexing
operator like the following:

	V _ I .lh A

with a default of indexing the last axis.  You could index the first axis by
specifying an axis and you could apply the indexing function several times:

	V _ I1 .lh [ 1 ] A	(meaning V _ A[ I1; ])

	V _ I1 .lh I2 .lh A	(meaning V _ A[ I1; I2 ])

  The real problem with this, and the problem which current indexing causes
is when the indexing occurs to the left of an assignment.  We could try to
do something with parenthesis;

	(I .lh A) _ V

but this is awkward and may be impossible to implement.  An alternative
is another operator:

	A _ I .rh V		(meaning A[I] _ V)

  This still seems a little backwards.   But maybe indexing is by nature
backwards.  I invite comments and suggestions on this idea.

  What is nice about using the left and right hook for indexing is that
they fit in well with SCTC's proposed extended arrays.  (Left hook for
disclosing, Right hook for enclosing.)

					chas
					  (..decvax!cwruecmp!honton)

kdmoen (02/11/83)

  Your indexing operations are a bit deceptive:
	I1 .lh I2 .lh A   equals   A[ I1; I2 ]
	       but doesn't equal   I1 .lh (I2 .lh A)

But yes, I agree.  Indexing in APL is inconsistent with the rest
of the language.  In particular, I feel that the action of replacing
part of an array value with something else should not be so closely
coupled to the assignment operation.  So here are some alternatives:

Introducing @, the selection & replacement function.
		@ array		<-> array (ie, the identity operation)
    replacement @ array		<-> replacement
		@[index] array	<-> selects subelements from array
    replacement @[index] array	<-> creates a new array with the
				    subelements selected by index
				    replaced by replacement

Thus,		A[index] <- replacement		in the old notation
becomes		A <- replacement @[index] A

Also,		0 @[3] .io 5	<-> 1 2 0 4 5

Note that indexing is now achieved by applying something similar to
an axis to the @ operator.  In the old APL, indexing could be applied
to any array value, but indexing with replacement could only be applied
to a variable.  This has been generalized, and the assignment statement
has been greatly simplified as a result.

The @ operator without an 'axis' doesn't look too useful, except perhaps
in 'expr2 @ expr1'.  Perhaps it could be used with operators.

Another syntax, achieving roughly the same effect, is:
		array [index]		-- as in normal APL
		array [index] replacement	-- as above

Thus,		A[index] <- replacement
becomes		A <- A [index] replacement

			Doug Moen, ...!watmath!kdmoen