Functions may leak information about names(!) oflocalvariables.



> -----Original Message-----
> From: maxima-bounces at math.utexas.edu [mailto:maxima-
> bounces at math.utexas.edu] On Behalf Of Michel Van den Bergh
> Sent: Thursday, December 28, 2006 7:08 AM
> To: fateman at cs.berkeley.edu
> Cc: maxima at math.utexas.edu
> Subject: Re: [Maxima] Functions may leak information about names(!)
> oflocalvariables.
> 
> What you say is not true. Changing t to tt makes no difference!
> 
> Michel
> 
> 
You are right... I didn't try the whole example! I looked again...
What is happening is, locally the "s" is bound to "t",
But not the global "t", just the symbol t.  When maxima tries to find the
properties of the symbol t, it looks inside your local scope and finds a
local t. This is Maxima's version of "dynamic scope". So when you do
t[4]:subvar(s,4)
All you are doing is t[4]:t[4].

To avoid this "capture" some people use the trick you've mentioned, which is
to have local variables with unusual names. Lisp makes it possible to
generate truly unique names (via gensym -- no one else can use them); it's
harder to do with maxima.

There are other ways of messing up with dynamic scope, e.g. binding of
arguments in function calls can make trouble as well. This type of binding
is now considered to be more trouble than it is worth.

Common Lisp has the more usual scope rules (essentially inherited from
Algol-60). You can write programs in Common Lisp, too.

RJF