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



On Jul 30, 9:38 am, Haiwei <highfl...@xxxxxxxxx> wrote:
On Jul 30, 9:20 pm, p...@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)
wrote:

Haiwei <highfl...@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.

Thanks. I got all the output after closed the stream.

But I wrote another function which open a file and write data into
it.  Then I got all the contents.
Is there any buffer or size limit on *standard-output* in sbcl?
My OS is ubuntu 8.04. The version of sbcl is 1.0.11.debian.

No, just be sure to close the file.  WITH-OPEN-STREAM makes sure
stream is closed, which is why JUDYDL-ENUMERATE-FILE works.
By the way, isn't there anything choking you?

        WITH-OPEN-STREAM
 JUDYDL-ENUMERATE-FILE

Use rather WITH-OPEN-FILE, in JUDYDL-ENUMERATE-FILE.  
Or implement a JUDYDL-ENUMERATE-STREAM.

In general, you will use WITH-OPEN-FILE.  

Yes. I will. But when to use WITH-OPEN-STREAM?


The Hyperspec says about WITH-OPEN-FILE, "with-open-file uses open to
create a file stream to file named by filespec. Filespec is the name
of the file to be opened. Options are used as keyword arguments to
open." From an issue write (about dynamic extent, not directly
relevant here), "[WITH-OPEN-FILE] probably should inherit whatever
restrictions are placed on WITH-OPEN-STREAM, so you can implement it
that way."

This suggests that WITH-OPEN-FILE could be implemented as

(defmacro with-open-file2 ((var filename &rest options) &body body)
`(with-open-stream (,var (open ,filename ,@options))
,@body))

So I'd guess that WITH-OPEN-STREAM is the choice whenever the stream
isn't going to be associated with a file. There are a number of other
stream constructors other than open, including MAKE-SYNONYM-STREAM,
MAKE-BROADCAST-STREAM, MAKE-TWO-WAY-STREAM, MAKE-ECHO-STREAM... (I'm
getting these from http://www.lisp.org/HyperSpec/Body/sec_the_streams_dictionary.html
.)

//JT



--
__Pascal Bourguignon__

.



Relevant Pages

  • Re: Strange behaviour of *standard-output* in sbcl
    ... to create a file stream to file named by filespec. ... Options are used as keyword arguments ... I don't see anything in WITH-OPEN-STREAM to suggest that it's supposed ...
    (comp.lang.lisp)
  • Re: CLOS question
    ... on the stream in order to avoid memory leaks - so C-like! ... In addition to what's been said in the other responses, WITH-OPEN-STREAM, ... when you leave a dynamic scope. ...
    (comp.lang.lisp)
  • Re: CLOS question
    ... on the stream in order to avoid memory leaks - so C-like! ... In addition to what's been said in the other responses, WITH-OPEN-STREAM, ...
    (comp.lang.lisp)