print_preprocess - Help

print_preprocess

obtain pretty-printed form of expressions

 Calling Sequence print_preprocess(e)

Parameters

 e - any expressions

Description

 • The function print_preprocess returns the pretty-printed form of an expression, as print would display it.
 • In particular, procedures of the form print/foo are applied to functions foo(a, b, ...) and ModulePrint procedures are applied to modules. This is particularly useful when you write a print/foo or ModulePrint procedure and want to display a subobject.

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)