print_preprocess - Maple Help

print_preprocess

 Calling Sequence print_preprocess(e)

Parameters

 e - any expressions

Description

 • 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 sub-expression.
 • 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).

Examples

The module m below displays in the same way as its member m:-a, but with square (list) brackets around it.

 > m := module()   export a;   local ModulePrint := proc()     return [print_preprocess(a)];   end proc; end module:
 > $m:-a≔5:$$\mathrm{eval}\left(m\right)$
 $\left[{5}\right]$ (1)
 > $m:-a≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(20\right):$$\mathrm{eval}\left(m\right)$
  (2)

The function foo(...) displays in reverse.

 > print/foo := proc() local oof, i;   return oof(seq(print_preprocess([_passed][i]), i = _npassed .. 1, -1)); end proc:
 > $\mathrm{foo}\left(1,2\right)$
 ${\mathrm{oof}}{}\left({2}{,}{1}\right)$ (3)
 > $m:-a≔\mathrm{foo}\left(1,2\right):$$\mathrm{eval}\left(m\right)$
 $\left[{\mathrm{oof}}{}\left({2}{,}{1}\right)\right]$ (4)

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:

 > $\mathrm{lprint}\left(\mathrm{print_preprocess}\left(\mathrm{eval}\left(m\right)\right)\right)$
 [oof(2,1)]

Since lprint itself does not perform print preprocessing, it can also be used to see what the actual expression looks like:

 > $\mathrm{lprint}\left(\mathrm{eval}\left(m\right)\right)$
 module () local ModulePrint; export a; ModulePrint := proc () return [print_preprocess(a)] end proc; a := foo(1,2); end module