Pref::postOutput -- actions
after any output
IntroductionPref::postOutput controls user defined actions directly
after any output.
Call(s)Pref::postOutput( <func>)
Parametersfunc |
- | function to be executed after output, or NIL |
Returnsthe last defined function
Related
FunctionsPref::postInput,
Pref::promptString
DetailsPref::postOutput(func) declares the
function func to be called after every output.func will be called with the result of
any evaluation after the output of the result.Pref::postOutput without arguments returns
the current value. The argument NIL resets the default
value, which is NIL.Pref::postOutput in joint with Pref::promptString und Pref::postInput can be used to
create status informations about evaluation. Possibilities are
informations to time and memory usage, types of results etc. (see
Pref::postInput)
Example
1>>
Example
2Pref::postOutput will be used to numerate
the output lines and show the type of the result. The global variable
NumberOfLine must be initialized with 0. This
all can be done in the file ``userinit.mu''.
>> NumberOfLine:= 0:
Pref::postOutput(proc()
begin
NumberOfLine:= NumberOfLine + 1;
stringlib::format(NumberOfLine, TEXTWIDTH, Right)."\n".
stringlib::format("Type: ".expr2text(map([args()], domtype)),
TEXTWIDTH, Right)
end_proc):
Example
3Time mesure in seconds.
>> Pref::postInput(() -> (TIME:= time())):
Pref::postOutput(proc()
local Time;
begin
Time:= trunc((time() - TIME)/1000);
stringlib::format("Time: ".expr2text(Time)." s",
TEXTWIDTH, Right)
end_proc):
T:= time(): while time() - T < 1000 do null() end_while
Time: 2 s
The output depends on the value of the variable TEXTWIDTH.
Example
4Show all identifiers of the result, that have properties assumed by the user.
The first assignment to ID selects all
identifiers of the output, that have properties. The second assignment
to ID collects the properties of all identifiers.
>> Pref::postOutput(proc()
local ID;
begin
if args(0) > 0 then
ID := select(indets(args()), property::hasprop);
else
ID := {};
end_if;
if nops(ID) > 0 then
stringlib::format("Props: ".expr2text(op(ID)),
TEXTWIDTH, Right)
else
null()
end_if
end_proc):
assume(a>0): a
a
Props: a
The output depends on the value of the variable TEXTWIDTH.