obtain ready-to-pretty-print form of expressions
When a Maple expression is about to be printed, either via a call to the print function, or as output from a user-entered command, the expression undergoes print preprocessing. This modifies the expression in ways that make it easier for the user interface to render it in a suitable form, or to make it more human-readable.
Print preprocessing performs the following actions:
Names of tables, procedures, and modules are replaced by their values.
Procedures of the form `print/foo` are applied to unevaluated functions of the form foo(a, b, ...).
ModulePrint procedures/methods are applied to modules and objects.
Arrays, Matrices, Vectors, and tables are converted to a more compact form if they would be unwieldy to display.
The print_preprocess function can be used to apply print preprocessing to an expression, returning the preprocessed expression instead of printing it. (If the returned value were printed, it would produce the same output as printing the original expression.)
The print_preprocess function is most often used within a `print/foo` or ModulePrint procedure to recursively apply print preprocessing to a subexpression.
The lprint function does not perform full print preprocessing, since its purpose is to produce output that is syntactically correct Maple input that recreates the original expression. It does do some preprocessing however:
Arrays, Matrices, and Vectors are processed.
ModuleDeconstruct procedures/methods are applied to modules and objects (the purpose of ModuleDeconstruct is to generate a call to a constructor expression that would recreate the module or object if executed).
The module m below displays in the same way as its member m:-a, but with square (list) brackets around it.
m := module()
local ModulePrint := proc()
m:-a ≔ 5:eval⁡m
m:-a ≔ LinearAlgebra:-RandomMatrix⁡20:eval⁡m
The function foo(...) displays in reverse.
`print/foo` := proc()
local oof, i;
return oof(seq(print_preprocess([_passed][i]), i = _npassed .. 1, -1));
m:-a ≔ foo⁡1,2:eval⁡m
Use lprint to see the actual result of print_preprocess. Here, the outer list was produced by the ModulePrint procedure, and the oof(...) structure by `print/foo`, which in turn was called as a result of the call to print_preprocess within ModulePrint:
Since lprint itself does not perform print preprocessing, it can also be used to see what the actual expression looks like:
module () local ModulePrint; export a; ModulePrint := proc () return [print_preprocess(a)] end proc; a := foo(1,2); end module
Download Help Document
What kind of issue would you like to report? (Optional)