So if the difference is 0.348399 versus 0.896669 for using
(let ((A_ (array-getter A))) ... (A_ i j))
versus
( ... (array-ref A i j))
then it's worth investigating.
That is remarkably large. Still, the rationale here is convenience/familiarity rather than performance.
> They are also convenient for arrays that need to
> be accessed and changed randomly, such as a multidimensional histogram.
I don't get this, it would seem that you'd have to choose randomly among
the arrays, and not among the indices, to benefit from array-ref and
array-set! over (let ((A_ (array-getter A)) (A! (array-setter A))) ...)
What makes histograms different from other uses of arrays is the general structure of
while (input properties p1 ... pn of next observation)
do A[p1, ... pn] = A[p1, ... pn] +1
where there is no reason to think that the properties of the observation being counted resemble in any way the previously processed observation. (By properties I mean, for example, the temperature, systolic pressure, diastolic pressure, oxygen saturation, heart rate, and respiration rate of a particular patient at a particular time, grouped and counted using a six-dimensional array.) Now clearly this can be done with the setter and getter, but this is not an "APL-ish" problem, and we might as well provide a convenient and familiar way to do it, even if it is less efficient than binding the getter and setter to local variables.
Come to think of it, if you do implement the row-major affine transformation, then a procedure that, given an interval and a set of indices, returns a single row-major index, would optimize away half the index calculations. (This procedure presumably already exists, even though it isn't exposed.) Then you can do this:
Arm = row-major(A)
while (get observation)
do index = row-major-index(interval(A), p1, ... pn)
Arm[index] = Arm[index] + 1
Using array-ref and array-set! extensively in programs that use this
SRFI will result in slower, clumsier, code that will compare (more)
unfavorably to codes written in a similar way in other languages (for
which compile-time bounds checks, number of arguments checks, etc., can
be elided at run time using compile-time type declarations, etc.).
Undoubtedly. It's hard to beat Fortran 66/77 in its domain.
John Cowan
http://vrici.lojban.org/~cowan xxxxxx@ccil.orgKnowledge studies others / Wisdom is self-known;
Muscle masters brothers / Self-mastery is bone;
Content need never borrow / Ambition wanders blind;
Vitality cleaves to the marrow / Leaving death behind. --Tao 33 (Bynner)