Re: Strange behaviour of *standard-output* in sbcl



pjb@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon) writes:

Haiwei <highfly22@xxxxxxxxx> writes:

Hi,

When executing following expression, the output file only has part of
contents. The size of this file is 12281.

(let ((*standard-output* (open "/home/haiwei/tmp/tmplog"
:if-exists :rename-and-delete
:if-does-not-exist :create
:direction :output)))
(judydl-enumerate root je))

You don't close the file, so some bytes remain in the buffer.
....

Also, it is often useful to include FORCE-OUTPUT at places where
interactive streams, in particular, are used.


Use rather WITH-OPEN-FILE,...

And to amplify Pascal's advice, I will point out that you can use
WITH-OPEN-FILE to bind *standard-output* as well:

(with-open-file (*standard-output* "/home/haiwei/tmp/tmplog"
:if-exists :rename-and-delete
:if-does-not-exist :create
:direction :output)
(judydl-enumerate root je))


--
Thomas A. Russ, USC/Information Sciences Institute
.