How to get maxima variable value by its name string



On 07-12-2013 17:15, - wrote:
> Hi,
>
> Thanks the help from Jaime (Jaime Villate <villate at fe.up.pt 
> <mailto:villate at fe.up.pt>>), I was recently able to read and modify 
> some of the lisp source code of maxima.
>
> Now I want to write a lisp function that is able to replace variable 
> names in a string to their current values in maxima. For example:
>
> var2:3+2;
> var1:"3+2=$var2$";
> str: " The value of var1 is: $var1$";
> str2:name2value(str);
>
> I want str2 to be " The value of var1 is: 3+2=5" after running the 
> function name2value.
>
> I am struggling with how to get maxima variable value by its name 
> string (e.g. "var1") in lisp.
>
> If you know how to do this using maxima code, that would help as well.
>
>
Hi Leo,
Richard Fateman has already told you what to do in Lisp. In Maxima, you 
can do the following:

(%i1) var2: 3+2;
(%o1)                            5
(%i2) var1: printf (false, "3+2=~a", var2);
(%o2)                          3+2=5
(%i3) str: printf (false, "The value of var1 is: ~a", var1);
(%o3)               The value of var1 is: 3+2=5

Notice that print(false,"format", a, b, ...) is the Maxima equivalent of 
Lisp's
(format nil "format" $a $b ...)

And a brief introduction to the various different format directives that 
can be used is found in:
http://www.gigamonkeys.com/book/a-few-format-recipes.html

Regards,
Jaime