Subject: how to pass the name of a variable as argument?
From: Stavros Macrakis
Date: Fri, 2 May 2008 13:14:08 -0400
On Fri, May 2, 2008 at 12:00 PM, Robert Dodier <robert.dodier at gmail.com> wrote:
> 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.
Yes, all variables have dynamic, not lexical scope. But how does that
make all variables global?
> As you doubtless know, dynamic scope can lead to subtle misbehavior.
Agreed.
> A lexically-scoped user language could be very useful.
Maybe.
> 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.
Could you be more specific? Are you thinking that Maxima expressions
would be somehow quoted so that mathematical variables/expressions and
programming variables/expressions would be distinct, e.g.
taylor("sin(x)","x",0,5) << where taylor is a Python function call
Many Maxima idioms depend on conflating programming and mathematical
variables, e.g.
ex: x^3-1$
factor(ex) <<< ex is a programming variable, but x is
a mathematical variable
ex, x=3 <<< hmm, is x a programming or a
mathematical variable?
makelist(factor("x^i-1"),i,1,10) <<< i is a programming
variable, x a mathematical variable; how would we say this in Python?
Is the "i" here a mathematical or a programming variable? If
programming, how does the mathematical system learn its value?
Something like
makelist(factor("x^getval(i)-1"),i,1,10) ?
I just don't see what you have in mind.
-s