Functions may leak information about names(!) of local variables.



hi Michel
Maybe this is caused by array-function.
so we do next best,as such using quatation
(%i1) g('s):=block([t],local(t), t[4]:subvar(s,4))$
(%i2) t[n]:=n^3$
(%i3) u[n]:=n^4$
(%i4) g(u);
(%o4)                                 256
(%i5) g(t);
(%o5)                                 t
                                       4
(%i6) ev(%);
(%o6)                                 64
if not use quatation,%o6 is 256 ,it's not good.
%o6 is the next best,I think.
thanks
Gosei Furuya



2006/12/29, Michel Van den Bergh <michel.vandenbergh at uhasselt.be>:
>
> van Nek wrote:
> > (%i1) g(s):=block([t],local(t), t[4]:subvar(s,4), t[4])$
> > (%i2) t[n]:=n^3$
> > (%i3) g(t);
> > (%o3)                                       t
> >                                      4
> > (%i4) g(s):=block([t],t[4]:subvar(s,4), t[4])$
> > (%i5) g(t);
> > (%o5)                                       64
> >
> > Hi Michel,
> >
> > the use of 'local' makes the difference here. As far as I understand
> (see doc of 'local'),
> > local(t) causes that all global information about t is forgotten and the
> substituted expression
> > subvar(t,4) is evaluated just as t[4], nothing more.
> >
> > Volker van Nek
> >
> This does not work: try
>
> g(s):=block([t],t[4]:subvar(s,4), t[4]);
> t[n]:=n^3;
> u[n]:=n^4;
> g(u);
> 256
> g(t);
> 256
>
> local is necessary to avoid the values of t being overwritten.
>
> Cheers!
> Michel
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>