Maxima Function
printf (dest, string)
printf(dest,string,expr_1,...,expr_n)
Makes the Common Lisp function FORMAT available in Maxima. (From gcl.info: "format produces formatted output by outputting the characters of control-string string and observing that a tilde introduces a directive. The character after the tilde, possibly preceded by prefix parameters and modifiers, specifies what kind of formatting is desired. Most directives use one or more elements of args to create their output.")
The following description and the examples may give an idea of using printf
.
See a Lisp reference for more information.
~% new line ~& fresh line ~t tab ~$ monetary ~d decimal integer ~b binary integer ~o octal integer ~x hexadecimal integer ~br base-b integer ~r spell an integer ~p plural ~f floating point ~e scientific notation ~g ~f or ~e, depending upon magnitude ~a as printed by Maxima function ~s strings enclosed in "double quotes" ~~ ~ ~< justification, ~> terminates ~( case conversion, ~) terminates ~[ selection, ~] terminates ~{ iteration, ~} terminates
Please note that there is no format specifier for bigfloats. However bigfloats can
simply be printed by using the ~a
directive.
~s
prints strings enclosed in "double quotes", you can avoid this by using ~a
.
Note that the selection directive ~[
is zero-indexed.
Also note that there are some directives, which do not work in Maxima.
For example, ~:[
fails.
(%i1) printf( false, "~a ~a ~4f ~a ~@r", "String",sym,bound,sqrt(12),144), bound = 1.234; (%o1) String sym 1.23 2*sqrt(3) CXLIV (%i2) printf( false,"~{~a ~}",["one",2,"THREE"] ); (%o2) one 2 THREE (%i3) printf(true,"~{~{~9,1f ~}~%~}",mat ), mat = args(matrix([1.1,2,3.33],[4,5,6],[7,8.88,9]))$ 1.1 2.0 3.3 4.0 5.0 6.0 7.0 8.9 9.0 (%i4) control: "~:(~r~) bird~p ~[is~;are~] singing."$ (%i5) printf( false,control, n,n,if n=1 then 0 else 1 ), n=2; (%o5) Two birds are singing.
If dest is a stream or true
, then printf
returns false
.
Otherwise, printf
returns a string containing the output.