arrays as function arguments



Barton Willis wrote:

> There are things I don't understand about Maxima arrays, 
> but this seems like a bug:
>
> (C1) sumit(a,n) := block([s : 0], for i : 1 thru n do s : s + a[i],
s)$
> (C2) array(a,5)$
> (C3) for k : 0 thru 4 do a[k] : k$
> 
> This is okay
> (C4) sumit(a,4);
> (D4)                          10
> (C5) array(b,5)$
> (C6) for k : 0 thru 4 do b[k] : x$
> 
> But this isn't
>
> (C7) sumit(b,4);
> (D7)                          10

This is a consequence of the manner in which arrays
made by ARRAY are implemented. (Note that MAKE_ARRAY 
is -not- like this, despite the similarity of the name.
Incidentally the examples work as expected with MAKE_ARRAY.)

The array made by ARRAY is not assigned to the variable as a
value. In fact, variable a has no value. The array is an
attribute associated with the name, and -retrieved by name-.

Thus in the function, a[k] refers specifically to the array
associated with variable a, not the real argument (namely b).
I don't see how to work around this; I did try -- I was
writing a function that took an array as an argument. But,
frankly, I don't think we need a work around, I think we 
need for arrays to act like other types in functions.

I'm inclined to recommend that ARRAY arrays be struck out
completely. MAKE_ARRAY seems to supply exactly the same 
functionality in a manner consistent with other types.

For what it's worth,
Robert Dodier

               

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/