Actions after input
This functionality does not run in MATLAB.
Pref::postInput(f) Pref::postInput(NIL) Pref::postInput()
Pref::postInput allows to set user actions directly after input.
After entering any MuPAD® command x, say, and sending this command to the kernel, f(x) is called before the kernel starts to process the input. This happens for any input until the post-input is switched off via the call Pref::postInput(NIL).
The function f implicitly uses the option hold, i.e., f sees the input command as entered and parsed without any evaluation.
f cannot change the input command that is sent to the kernel for evaluation. However, f can store the input in some global variable for later processing, or some other actions can be performed.
Pref::postInput() returns the current value of the post-input function or NIL, respectively.
Pref::postInput, possibly in conjunction with Pref::postOutput, is useful for initializing variables to compute status information such as the execution time for the command that is to be executed. See Example 2.
The post-input function sees the input as entered, i.e., before evaluation by the kernel:
Pref::postInput(proc() begin print(Unquoted, "input" = args()) end):
1 + 2
input = 1 + 2
1 + 2, x = sin(0.1)
input = (1 + 2, x = sin(0.1))
x := 1234; y := 5678
input = (x := 1234)
input = (y := 5678)
Post-input is switched off. This command calls the post-input function for the very last time:
input = Pref::postInput(NIL)
delete x, y:
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::postOutput compares the current time and the starting time TIME.
Pref::postInput(() -> (TIME:= time())): Pref::postOutput(() -> "Time: ".expr2text((time() - TIME)*msec)):
Time: 40 msec
Time: 40 msec
Pref::postInput(NIL): Pref::postOutput(NIL): delete TIME:
As another example of using Pref::postInput for storing information to influence the output, we combine it with Pref::output to include (a rendered version of) the input and the result:
Pref::postInput(() -> (LASTINPUT := args())): Pref::output(() -> val(LASTINPUT) = args()):
This makes MuPAD write "input = result" to the screen, while leaving the history (accessible by %) intact:
int(x, x); sum((-1)^i/(2*i+1), i=0..infinity); sin(%)