Thank you. Here is my final progress bar code for anyone interested:
(defn progress-string
[i]
(str-join "" (seq (for [x (range 50)] (if (<= (/ i 2) x) " "
"=")))))
(defn show-progress-string
[t]
(dotimes [percent 100 ]
(do
(Thread/sleep t)
(print "\r|" (progress-string (inc percent)) "|" (inc percent)
"% done" )
(flush))))
(show-progress-string 1200)
Just adding (flush) solved it.
On Dec 15, 6:23 pm, "Stephen C. Gilardi" <[email protected]> wrote:
> > I have following script to show the progress status in Console. But I
> > am having an issue where print only prints final string (after 100
> > times loop finished) not those in between thread sleeps but println
> > prints out all in between. I am pretty new to Clojure ( Lisp for the
> > matter) and have no idea why. Can someone point out what is the
> > problem?
>
> > (defn progress-string
> > [i]
> > (for [x (range 50)] (if (<= (/ i 2) x) " " "=")))
>
> > (defn show-progress-string
> > [t]
> > (dotimes [percent 100 ]
> > (do
> > (Thread/sleep t)
> > (println "\r" (str-join "" (seq (progress-string (inc
> > percent))))))))
>
> The output is kept in an output buffer until it's flushed (either because the
> buffer is full or by request). println includes a call to (flush) (if
> *flush-on-newline* is true, which is the default). In your case, you can use
> an explicit call to (flush) when you want to be sure the user has seen what's
> been printed so far.
>
> --Steve
>
> smime.p7s
> 3KViewDownload
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en