-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 31-May-07, at 6:26 PM, Adrien Pierard wrote:
Here is the code :
(let ((o (open-output-file "/tmp/flushed-data"))) (display "whirl" o) (display "\n" o))
I thought that when the gambit process cleanly finishes, it would flush the port, though it didn't. I had to append a (close-output-port o) in order to have my data dumped.
You have to call (close-output-port o), otherwise the runtime system does not know that you are done with port "o". All buffering is done at the Scheme level, so your calls to "display" are merely filling some internal Scheme buffers (Scheme strings and u8vectors). The OS is not aware of these buffers. It is when you do a (force-output- port o) or (close-output-port o) or when the internal buffer is full that the data is sent to the OS.
If you dislike this, you can always disable the buffering, or add a finalizer that closes the port, for example:
(define open-output-file (let ((orig-open-output-file open-output-file)) (lambda (filename) (let ((port (orig-open-output-file filename))) (make-will port close-output-port) port))))
(let ((o (open-output-file "out"))) (display "foo" o) (display "bar\n" o))
(##gc) ;; GC will call finalizer
Marc