Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Print in a loop

4 views
Skip to first unread message

kalym...@yahoo.fr

unread,
Oct 24, 2005, 1:50:30 AM10/24/05
to
Hi MathGroup

Consider

l={a,b,c,...}

Scan[ Print[#]&, l ]

gives
a
b
c
...

I would like that at each step, the new output erases the previous one,
i.e. that a be replaced by b and b by c etc (that is, a kind of
"clock")

How can I do that ?

Thanks

ggr...@sarj.ca

unread,
Oct 24, 2005, 3:42:23 AM10/24/05
to
On Monday, October 24, 2005 at 01:43 GMT -0400, Kalymereau wrote:

> I would like that at each step, the new output erases the previous one,
> i.e. that a be replaced by b and b by c etc (that is, a kind of
> "clock")

> How can I do that ?

Use the Notebook FrontEnd manipulation commands. I'm sure the
following isn't optimal, but is seems to do what you want.

l={a,b,c};
nb = EvaluationNotebook[];
SelectionMove[nb, All, GeneratedCell];
Scan[
(NotebookDelete[nb];
Print[#];
Pause[1];
SelectionMove[nb, All, GeneratedCell];
)&, l]


albert

unread,
Oct 24, 2005, 9:25:17 PM10/24/05
to
Hi,


> Consider
>
> l={a,b,c,...}
>
> Scan[ Print[#]&, l ]
>
> gives
> a
> b
> c
> ...
>
> I would like that at each step, the new output erases the previous one,
> i.e. that a be replaced by b and b by c etc (that is, a kind of
> "clock")

I have just seen another post which explains how you can do what you were
asking for by deleting the generated cells befor writing. Since it looks
like what you want to do is to give a status feedback, I wanted to draw
your attention to the following function which writes strings to the
status-bar, which is after all a nice place to put status-messages. The
original code for this function is from another post to this group, which
you can lookup when you are interested...

ShowStatus[status_] := If[
Head[$FrontEnd]===FrontEndObject,
LinkWrite[
$ParentLink,
SetNotebookStatusLine[FrontEnd`EvaluationNotebook[], ToString[status]]
]
,
Print[status];
];

The function can be used like Print but is limited to one argument (which
you can of course change). If no frontend is available, it will just print.
Note that you are limited to unformatted strings with this approach, but
for status messages, this is usually good enough...

l={a,b,c,...}

Scan[ (ShowStatus[#];Pause[1])&, l ]

will now show the symbols in l in the status bar. To clean up you might want
to use a ShowStatus[""] after you are finished. I couldn't find anything
about SetNotebookStatusLine in the documentation, so use at own risk :-)

hth

albert

0 new messages