how to pass the name of a variable as argument?



Robert Dodier wrote:
> On Thu, May 1, 2008 at 6:14 PM, Oliver Kullmann
> <O.Kullmann at swansea.ac.uk> wrote:
>
>   
>>  Since global variables should be avoided,
>>     
>
> Bear in mind that, in Maxima, effectively ALL variables are global variables,
> or, more precisely, global variables and local variables act the same.
> All variables have dynamic scope, not lexical scope.
>
> As you doubtless know, dynamic scope can lead to subtle misbehavior.
> A lexically-scoped user language could be very useful.
> Instead of revising the existing Maxima language, at this point I think
> the easiest way to get lexical scope is to run a different language
> on top of Lisp. One possibility is Python; there is a CL implementation
> of Python name CLPython. The developer is talking about porting it
> to SBCL.
>   
 <snip>
The Macsyma/ Maxima language is modelled on Algol 60, a language which 
was sort of misunderstood when implemented at MIT.
The mistake was to adopt the dynamic scope of Maclisp in the Macsyma 
language.  The use of dynamic scope in lisp 1.5, according to John 
McCarthy, was a mistake.  Subsequent experiments at MIT in lisp-like 
languages got the Algol 60 lexical scope "right".  It resulted in  Scheme.

Now if you want to adopt lexical scope in Maxima,  I think it is not 
necessary to change the syntax or language at all, just the implementation.
(I am assuming that definition of procedures within procedures would be 
handled properly...)
That is, the surface syntax would look identical. There is no need to 
adopt python, or java or C# or ....

Would this break existing programs?  Maybe some.  It is my understanding 
that Maple, between versions 9 and 10 (I think) changed the language 
implementation from dynamic to lexical scope.  And there is way way more 
code in the Maple language than in Maxima top-level syntax.

Most programmers probably don't understand the scoping issues and use 
only global variables or local variables, and do not nest procedures.  
So it will not make any difference in their code.

There is another issue which has to do with 2-lisp vs 1-lisp semantics, 
and whether you can have two bindings for the same name, a function and 
a variable, or just one.
That is, can you do f(x):=.....  
and also f:3.
or will the second assignment over-write the first.

Common Lisp,  and Maxima,  is a 2-language. Scheme is  a 1-lisp.

Now it may be appropriate to build another front end, interpreter, etc, 
for Maxima, based on python.  Probably not too hard.  There is, for example,
another front end for Macsyma that used Matlab syntax. It could entirely 
co-exist with the existing one..

Or the alternative could be a front end for the lexically scoped 
language that looks just the same,  but is subtlely different.

My 2 cents..

RJF