Reputation: 13173
I use worksheet (not document mode).
I know one can do Edit>Remove Output>From Worksheet
to "Removes Maple output from all execution groups in a worksheet."
But I could not find a command to do this. I need to do this, since when I run a loop as in
for i from 1 to n do
some_function();
od
And the function above say prints to the screen (i.e. worksheet currently open) lots of information, then the worksheet slows down and I really also do not want to see the logging from all the calls accumulated any way. I just need to see prints from one iteration only at a time.
(Maple has other problems with having large output accumulate in worksheet also, but this is for another topic).
I'd like to do something like this
for i from 1 to n do
some_function();
delete_all_output_in_current_worksheet();
od;
So only one call's output shows up as the some_function
is running.
In Matlab, this is easily done using clc which clears the command windows in Matlab.
Is there something like the above in Maple?
Maple 2018.1 on windows.
Upvotes: 2
Views: 2068
Reputation: 7271
There is no programmatic way to clear all the output of the current worksheet.
But you can push the running result from some_function()
(each time through the loop) to Embedded Components, eg. TextBox, MathContainer, etc.
You don't even have to manually insert such Components from the palettes. Instead you can use the DocumentTools:-Tabulate
command to programmatically insert a tabulated collection of components right after the current Execution Group.
For example, as 1D code in a Worksheet, you could have these blocks of code in three separate Execution Groups.
restart;
and,
some_function:=proc(i)
int( sin(x)^i, x);
end proc:
Leafcutoff := 150:
and,
# Put all this in the same Execution Group
for i from 1 to 111 by 10 do
res[i] := some_function(i);
K := MmaTranslator:-Mma:-LeafCount(res[i]);
if K <= Leafcutoff then
L := res[i];
else
L := sprintf("LeafCount > %a",Leafcutoff);
end if;
DocumentTools:-Tabulate(
[["i","LeafCount","result"],
[sprintf("%a",i), K, L]],
':-weights'=[10,10,40],
':-fillcolor'=((T,i,jj)->`if`(i=1,"grey",
"white")),
':-widthmode'=':-pixels',
':-width'=600);
Threads:-Sleep(1.5); # delay at least 1.5 sec
end do:
DocumentTools:-Tabulate([[]]):
I put in a time-delay of 1.5 seconds just to illustrate it working. You can adjust that, or remove it.
The last call to Tabulate
is only there to blank it out, when the loop is finished.
The GUI Table inserted by Tabulate
actually appears in a region right after the Execution Group. Only one such region appears, per Execution Group. Basically, each call to Tabulate overwrites that region.
If you changed the end do:
to end do;
then all the regular output would also be shown, as usual for a loop.
Upvotes: 1