[Maxima] Bugs in printf?

Volker van Nek volkervannek at googlemail.com
Wed Mar 25 14:27:54 CDT 2009

Jaime Villate schrieb:
> Hi,
> I'm having problems with fprint, not behaving as format in Lisp.
> 1- Tildes can only be printed in some places and not in others:
> (%i1) :lisp(format t "~~ ~d" 4);
> ~ 4
> (%i2) printf(true, "~~ ~d", 4);
> printf: arguments exhausted.
>  -- an error.  To debug this try debugmode(true);
Hi Jaime,

this bug is easy to fix:
/share/contrib/stringproc/printf.lisp line 85
        (if (search spec "}]>;%&t") (progn (setq start pos2) (go tag1)))
        (if (search spec "}]>;%&t~") (progn (setq start pos2) (go tag1)))

I forgot to add the "~" here. I will fix this in CVS.

2- Conditional formatting fails:

> (%i3) :lisp(format t "~{~#[~;~d ~;~f ~;~a ~]~}~%" (list "numbers" 4 5));
> numbers 4.0 5 
> (%i4) printf(true, "~{~#[~;~d ~;~f ~;~a ~]~}~%", ["numbers", 4, 5]);
> printf: argument can't be supplied to d-directive: numbers
>  -- an error.  To debug this try debugmode(true);
I fear I have to say that this bug is impossible to fix in the current 
implementation of printf. 

printf basically uses format. Since format doesn't know a directive for 
bigfloats I invented the ~h directive (h=huge) and wrote a version of 
printf where each ~h directive is converted to an according ~a directive 
and the corresponding bigfloat argument is converted into a formatted string 
before calling format. 
As a result of this concept I already had to skip the ~* directive which allows 
to use arguments more than one time. In your example you effectively reorder 
the arguments. This also leads into trouble. 
My preprocessing the expressions before calling format needs a proper 
sequential correspondence of both directives and arguments. 

A way out of these problems will be an implementation of printf which uses 
format only in a very basic way (just single args). But that is a long way. 
I hope I can do it this year. 

At the moment I can't be more helpful.


> I'm using a very recent CVS version.
> Regards,
> Jaime
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima

More information about the Maxima mailing list