Re: mutable-array setter vs SRFI-17 Jamison Hope 28 Sep 2015 23:03 UTC

On Sep 28, 2015, at 4:44 PM, Bradley Lucier <xxxxxx@math.purdue.edu> wrote:

> On 09/27/2015 12:33 AM, Per Bothner wrote:
>> In this letter I'll rename the specification of mutable-array to avoid
>> confusion, to:
>>   (mutable-array domain get-proc set-proc)
>>
>> The "standard" Scheme argument-order for a "set-proc" is to have the new
>> value *last*.
>> E.g. (vector-set! vec index new-value).  That is why SRFI-17 defines:
>>   (set! (proc arg ...) value)
>> as
>>   ((setter proc) arg ... value)
>>
>> The setter procedure passed to mutable-array has the order:
>>   (setter value i1 ... in)
>> I think it should be:
>>   (setter i1 ... in value)
>> That would allow:
>>   set-proc == (setter get-proc)
>>
>> Of course the downside of that is that you can't use a "rest" argument to
>> writer the setter:
>>   (lambda (value . indexes) ...)
>> This issue is discussed in SRFI-17.
>
> Thank you for your comments; I have thought about similar issues.
>
> Newly-developed procedures have differed from previous naming conventions.  Thus we have
>
> set-car!
>
> but
>
> vector-set!
>
> I think the order of arguments to vector-set! was an error that doesn't become clear until you use a multi-index instead of a a simple index as argument.

I agree with Per about the argument order, it matches the argument order
for set-car!, set-cdr!, string-set!, vector-set!, and the various other
setters in (at least) SRFIs 4, 13, 25, 66, 69, 74, and 101 and RnRS (for
all n, AFAICT).

It also matches the order in which arguments appear for array-setting
expressions in other languages:

(setf (aref array x y z) newvalue) ;; Common Lisp
array[x][y][z] = newvalue;         /* C, C++, Java, ... */
Array(x,y,z) = newvalue;           # Matlab
ARRAY[$x]=$newvalue;               # Bash
$array[$x] = $newvalue;            # Perl

On the other hand, SRFI-47 agrees with you and the world didn't explode.

--
Jamison Hope
xxxxxx@alum.mit.edu