How to assign the name of a variable to another variable inside a function
Subject: How to assign the name of a variable to another variable inside a function
From: Stavros Macrakis
Date: Fri, 10 Sep 2010 10:31:24 -0400
Maxima normally passes arguments by value, so the expression used to
calculate the value is not available to the function.
Maxima does support unevaluated arguments, but it is in general a bad idea
to use them except for very special cases. <<<I do not recommend it.>>>
Example:
f('expr) := [expr,ev(expr)]$
x:7$
f(x+3);
[x + 3, 10]
In general, it is much better practice to explicitly pass any names you want
to use, e.g.
f1(name,expr) := print("the value of",name,"is",expr)$
f1('x,x)$
the value of x is 3
-s
On Fri, Sep 10, 2010 at 10:08, Stefano Ferri <ferriste at gmail.com> wrote:
> No, I think. I don't want to change the value of matrix1, but just
> assign 'matrix1 to name_of_m.
> A clearer example could be:
>
> f(m):=(m:transpose(m),
> ... here some code to assign a value to name_of_m,
> print("Matrix", name_of_m, "transposed)
> )$
>
> let
>
> matrix1 : matrix([1,2],[3,4]);
>
> f(matrix1) function should return the tranposed of matrix1, and print
> the message
>
> Matrix matrix1 transposed.
>
> I am only able to print out the value of matrix1, not its name.
> name_of_m should evaluate to 'matrix1, but if I quote arguments inside
> the functions, I get
>
> Matrix m modified.
>
>
>
>
>
>
>
>
>
>
>
> 2010/9/10 Richard Fateman <fateman at cs.berkeley.edu>:
> >
> >
> > name_of_m: matrix1;
> > name_of_m:: newvalue;
> >
> > changes the value of matrix1.
> >
> > Is that what you need?
> >
> >
> >
> >
> >
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>