global defined lists and hashed arrays in function bodies
Subject: global defined lists and hashed arrays in function bodies
From: Richard Fateman
Date: Sun, 24 Aug 2008 08:41:47 -0700
The functions are the same, but the meaning of x[1] and u[1] are different.
If u is a globally defined array, then u[1] means its value, and the binding
of u is not observed.
If u is not a globally defined array but is bound to a list [a,b,c..] then
u[1] means a.
I think that is the explanation, anyway.
> -----Original Message-----
> From: maxima-bounces at math.utexas.edu
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of van Nek
> Sent: Sunday, August 24, 2008 4:57 AM
> To: Maxima at math.utexas.edu
> Subject: global defined lists and hashed arrays in
> function bodies
>
> Hello.
>
> The function definition of foo and bar seem to be the same.
> The results are different. Why?
> I had expected foo(y); => y+2
> Does mdefine react on the symbol's properties?
>
> Volker van Nek
>
> (%i2) x:[2]$
> (%i3) properties(x);
> (%o3) [value]
> (%i4) foo(x):=x+x[1]$
> (%i5) :lisp $_
> ((MDEFINE) (($FOO) $X) ((MPLUS) $X (($X ARRAY) 1)))
> (%i5) foo(y);
> (%o5) y+y[1]
>
> (%i6) u[1]:2$
> (%i7) properties(u);
> (%o7) ["hashed array"]
> (%i8) bar(u):=u+u[1]$
> (%i9) :lisp $_
> ((MDEFINE) (($BAR) $U) ((MPLUS) $U (($U ARRAY) 1)))
> (%i9) bar(y);
> (%o9) y+2
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>