how to pass the name of a variable as argument?



On 5/2/08, Stavros Macrakis <macrakis at alum.mit.edu> wrote:

>  >  A lexically-scoped user language could be very useful.
>
>  Maybe.

I'm quite convinced of it, actually. Dynamic scope causes a lot
unpleasant surprises.

Aside from lexical scope, other languages have nice namespace
and object systems (which in Python are both covered by the
class system). These, also, are 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.
>
>  Could you be more specific?

I am mostly imagining a language which is happy with symbols and
partially-evaluated expressions. (I realize that excludes Python in
its current incarnation. Dunno how much work it would be to change it.)

As a stop-gap measure, one could devise classes Symbol and
Expression, say, and then explicitly create these, e.g.
x = Symbol ('x')
expr = Expression (x + 1)
but that's clumsy. Symbol and Expression might exist anyway
but it shouldn't be necessary for the user to explicitly create them.

>  Many Maxima idioms depend on conflating programming
> and mathematical variables,

Yeah, that's pervasive, and useful. I am inclined to attempt the
same conflation in Python or whatever language. Maybe changing
the evaluation policy to evaluate an unbound variable foo
to Symbol('foo') would help. The evaluator would have to look
at the value of Symbol('foo') if the variable foo occurs in some
expression.

I'm not sure how much run-time re-mogrification is possible in
Python. It might be necessary to modify & rebuild Python from
the source code. I would be inclined to use CLPython which
is written in Lisp, and recently ported to SBCL if I understand
correctly.

I would be inclined to modify Python only so as to allow existing
programs to run the same. Since unbound variables and
partially-evaluated expressions now cause errors, it seems
possible to introduce those without disturbing existing programs.
Dunno what other changes are needed to make a useful
Maxima user-language.

FWIW

Robert Dodier