[Maxima] how to pass the name of a variable as argument?

Richard Hennessy rvh2007 at comcast.net
Fri May 2 01:04:51 CDT 2008

I just use global variables but sometimes I have the function return a list instead of a number where the list contains all of the values of the locals that are needed to pick up where you left off.  The first element of the list could be the actual answer.

f(x):=block(... [ans,i,j,localvar1,localvar2, etc...])

if you just want the answer you get it by saying something like

->  .8765


Just an idea

 ------------Original Message------------
From: "Stavros Macrakis" <macrakis at alum.mit.edu>
To: "Oliver Kullmann" <O.Kullmann at swansea.ac.uk>
Cc: maxima at math.utexas.edu
Date: Thu, May-1-2008 8:42 PM
Subject: Re: [Maxima] how to pass the name of a variable as argument?

On Thu, May 1, 2008 at 8:14 PM, Oliver Kullmann
<O.Kullmann at swansea.ac.uk> wrote:
>  Since global variables should be avoided, a good
>  solution would be to pass the name of a variable
>  to f, so that then we could use

I am not sure that global variables are any worse than this method, but....

To name a variable, use 'var.  To assign to a variable through its
name, use var :: newval. To access the value of the value of a
variable, use ev(var).  So your example becomes

    f(x) := x :: adjoin(1,ev(x));

and is called as


I don't know what your overall problem is, but I think I would just
use global variables with a naming convention, e.g. global_x,
global_y, or a hasharray global['x], global['y].

Maxima mailing list
Maxima at math.utexas.edu

More information about the Maxima mailing list