Prevent evaluation



Am Dienstag, den 15.03.2011, 11:23 +0100 schrieb Rene Grothmann:
> You are giving me the kind of information, I need. However, I still have to figure out a lot of things myself. I would love to search for this myself, if you give me a hint, where to look for.
> 
> Can ?displa be configured to center its output? It does obey the line length, it seems. This might solve a lot of problems I have with Maxima. By the way, how to change the line length?
> 
> Here is what I need:
> 
> (1) A way to evaluate a command in Maxima and get the result as a string.
> (2) A way to find out, if there is was an error in the command, and a way to print that error to the user.
> (3) A way to print the result string in 2D.
> 
> Currently, I am doing (1) and (2) by parsing the output of Maxima. I use the input prompt for a sign, that the output is over. I am doing (3) by setting display2D to true and sending the result string once more.
> 
> Yours, thankfully,

First, some possibilities:

(%i1) display2d:false$

The function string evaluates its argument and converts the result into
a string:

(%i2) string(a + 2^3 + sin(0.5));
(%o2) "a+8.479425538604204"

(%i3) string(a + 2^3 + sin(0.5) + 'diff(cos(x),x));
(%o3) "'diff(cos(x),x,1)+a+8.479425538604204"

Maxima knows the function errcatch and the option variable errormsg. If
we set errormsg to false, we no longer get an error message.

(%i4) errormsg:false$

The function errcatch evaluates its argument and return the result as a
list:

(%i5) errcatch(string(2/3));
(%o5) ["2/3"]

If Maxima encounters an error the return value of errcatch is an empty
list:

(%i6) errcatch(string(2/0));
(%o6) []

In this case you can check the option variable error. It holds the last
error message in a list:

(%i7) error;
(%o7) ["expt: undefined: 0 to a negative exponent."]

I think you need both the string and the symbolic expression:

(%i1) errormsg:false$

(%i2) result : errcatch(factor(1000));
(%o2) [2^3*5^3]

(%i3) str : string(first(result));
(%o3) 2^3*5^3

(%i5) ?displa(first(result));
2^3*5^3
(%o5) false

Remark: I have not checked in detail, if the above scheme causes
problems with multiple evaluation. At least at the Lisp level all this
problems can be solved.

The length of a display line is changed with the option variable linel.
I had no detail look at the code of DISPLA. We might have some variants
which will give a centered output too.

Dieter Kaiser