2

I have this:

(loop for i below x
            do (update-world)
            if (zerop (mod i 1000))
            do (princ #\.))

It is working, except that all the princ invokations arrive at once, at the end. The idea here is that they are a progress indicator, printing a period to the screen every 1000 iterations. This is from the Land of Lisp book, and I'm wondering if expecting printing in the middle of a loop is not a portable expectation?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
johnbakers
  • 24,158
  • 24
  • 130
  • 258

1 Answers1

4

Add a (finish-output) after the princ.

http://clhs.lisp.se/Body/f_finish.htm

Lars Brinkhoff
  • 13,542
  • 2
  • 28
  • 48
  • `finish-output` isn't the only option, though. There's also `force-output`, as described in [slime prints my (format …) calls only when called function ends](http://stackoverflow.com/q/19204332/1281433) (of which I think this question qualifies as a duplicate). – Joshua Taylor Nov 27 '13 at 12:11