MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Print in a loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61649] Re: Print in a loop
  • From: albert <awnl at arcor.de>
  • Date: Mon, 24 Oct 2005 21:07:06 -0400 (EDT)
  • References: <djhsn6$shb$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • Prev by Date: Re: Use of CAS in introductory science&engineering courses
  • Next by Date: Re: Zero-based indexing option?
  • Previous by thread: Re: Print in a loop
  • Next by thread: Running the kernel command line with additional input files