> 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
Description: S/MIME cryptographic signature