Pref::postOutput

Actions after output

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

Pref::postOutput(f)
Pref::postOutput(NIL)
Pref::postOutput()

Description

After the result x, say, of a MuPAD® command is printed on the screen, f(x) is called and executed before the next prompt for user input appears. This happens for any output until the post-output is switched off via Pref::postOutput(NIL).

After the usual output of the result x of a MuPAD command, the return value of f(x) is printed on the screen with PRETTYPRINT = FALSE. However, f(x) does not return any value to the MuPAD session. It cannot be accessed via last.

Pref::postOutput() returns the current value of the post-output function or NIL, respectively.

Pref::postOutput, possibly in conjunction with Pref::postInput, can be used to produce status information after each output. One may think of timer informations, memory usage, result types etc.

Examples

Example 1

Here, Pref::postOutput is used to enumerate the output line and display the type of the result. It uses the global variable LineNumber which must be initialized before any output is produced. The definition of the post-output operation as well as the initialization of the global variable can be done in the file "userinit.mu" which is read automatically during start-up.

Pref::postOutput(
  proc()
  begin
    LineNumber:= LineNumber + 1;
    "Out[" . expr2text(LineNumber). "]: ".
    "type = ".expr2text(op(map([args()], domtype)));
  end_proc):
LineNumber:= 0:
int(x^5*exp(-x), x)

Out[1]: type = DOM_EXPR
int(x^5*exp(-x), x = 0..infinity),
numeric::int(x^5*exp(-x), x = 0..infinity)

Out[2]: type = DOM_INT, DOM_FLOAT

The following print command returns the void object null() to the MuPAD session. The output of null() is suppressed:

print("print returns the void object")

The following command is terminated by a semicolon to suppress the output. Consequently, no post-output is created, either.

x := sin(2):

Post-output is switched off:

Pref::postOutput(NIL): delete LineNumber, x:

Example 2

For any command, the run time is to be computed and displayed. The function declared in Pref::postInput sets a global timer value TIME after each input. After the output of the result, the function declared in Pref::postInput compares the current time and the starting time TIME. The current TEXTWIDTH is used to prepend some suitable whitespace via stringlib::format to flush right the timer information:

Pref::postInput(() -> (TIME:= time())):
Pref::postOutput(
  proc() begin
   stringlib::format("Time: ".expr2text(time() - TIME)." msec",
                     TEXTWIDTH-1, Right)
  end_proc):
int(x^10*exp(-x), x)

 
                                           Time: 84.005 msec 
Pref::postInput(NIL): Pref::postOutput(NIL): 
delete T, TIME:

Example 3

The following post-output lists all identifiers with properties in the result of the last MuPAD command. It extracts the indeterminates via indets and uses property::hasprop to query whether they have properties:

Pref::postOutput(
  proc()
  begin
    select(indets({args()}), property::hasprop);
    "identifiers with properties: " . expr2text(op(%))
  end_proc):
assume(0 < a < b): a + b + c

identifiers with properties: a, b
Pref::postOutput(NIL): delete a, b:

Parameters

f

The function to be executed after output: a procedure. The default value of this function is NIL (no post-output).

Return Values

Previously set post-output function.

See Also

MuPAD Functions

Was this topic helpful?