rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

printf tilde-m outputs a line termination even when there is none in control string #2693

Open rtoy opened 1 month ago

rtoy commented 1 month ago

Imported from SourceForge on 2024-07-06 18:09:11 Created by robert_dodier on 2024-03-04 13:08:37 Original: https://sourceforge.net/p/maxima/bugs/4271


The ~m directive for printf displays expressions via the pretty printer. printf always outputs a line termination, even when there is none in the control string. Just one extra line termination is printed for the whole control string, not one per ~m directive.

(%i1) for i thru 5 do printf(true, "~a", i);
12345(%o1)                                                               done
(%i2) for i thru 5 do printf(true, "~m", i);
1
2
3
4
5
(%o2)                 done
(%i3) for i thru 5 do printf(true, "~m ~m ~m", i, i+1, i+2);
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
(%o3)                  done

To handle ~m, printf calls AFORMAT, which punts to MFORMAT. I looked around in src/mformt,lisp and src/mforma.lisp, and I don't see an obvious way to suppress the line termination.

rtoy commented 1 month ago

Imported from SourceForge on 2024-07-06 18:09:12 Created by rtoy on 2024-03-13 23:26:55 Original: https://sourceforge.net/p/maxima/bugs/4271/#6fcc


Perhaps it's the mterpri call in output-linear-one-line in "displa.lisp". I commented out the call and your "~m" example prints "12345". But if I try printf(true, "~M~%", i), no new line is printed either. I guess whatever handles "~%" really need to force a new line. I didn't look into that.