array arguments to function



As far as I know, lists and matrices are always
passed by reference:

(%i1) f(L) := L[1] : 77;
(%o1)                                     f(L) := L  : 77
                                                   1
(%i2) a : [1,2,3];
(%o2)                                        [1, 2, 3]
(%i3) f(a);
(%o3)                                            77
(%i4) a;
(%o4)                                        [77, 2, 3]
(%i5) b : matrix([1,2],[3,4]);
                                              [ 1  2 ]
(%o5)                                         [      ]
                                              [ 3  4 ]
(%i6) g(M) := M[1,1] : 77;
(%o6)                                    g(M) := M     : 77
                                                  1, 1
(%i7) g(b);
(%o7)                                            77
(%i8) b;
                                             [ 77  2 ]
(%o8)                                        [       ]
                                             [ 3   4 ]

I don't use arrays (since these are only global objects),
so I don't know about them.

Oliver


On Wed, Jan 30, 2008 at 09:19:40AM -0800, Thomas Widlar wrote:
> I'm not sure I understand the answer. Is it possible
> to pass arrays, lists or matrices to a function and
> have the function modify the actual array, list or
> matrix? 
> 
> In other words, are arrays, lists or matrices passed
> by value, reference or both? Is there a special
> syntax?
> 
> 
> --- Robert Dodier <robert.dodier at gmail.com> wrote:
> 
> > On 1/29/08, Thomas Widlar <twidlar at yahoo.com> wrote:
> > 
> > > We want to pass arrays to a subroutine (a
> > function)
> > > by reference not by value, that is, we need to
> > give
> > > the address of the actual array(s) so that the
> > > routine can access and modify them.
> > 
> > Whether or not that has the intended effect depends
> > on what
> > kind of arrays you have. Bear in mind that lists and
> > matrices
> > act like arrays but arrays are distinct from lists
> > and
> > matrices in Maxima. My advice is to use lists or
> > matrices if
> > you need one or two indices, respectively, and to
> > use arrays
> > as created by make_array if you need more indices.
> > 
> > Hope this helps,
> > 
> > Robert
> > 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima