Page 1 of 1

buffering of (print)

Posted: Wed Mar 12, 2008 10:11 am
by Dmi
Hi, Lutz!

Just discover that

Code: Select all

(while true (print ".") (sleep 1000))
started in command prompt shows all the output only after execution is finished.
Often this is not useful.
If this is a new behavior, then something like (flush), or, better, the output buffer configuration for particular handle, like in perl, will be a good addition.

Posted: Wed Mar 12, 2008 11:38 am
by Lutz
On Unix Mac OS X you can import fflush()

Code: Select all

> (import "libc.dylib" "fflush")
fflush <948F88C7>
> (while true (print ".") (fflush 0) (sleep 200))
................................................^Creceived SIGINT - in function sleep
(c)ontinue, (d)ebug, e(x)it, (r)eset:r
> 
The SIGINT was caused by hitting Ctrl-C. The above is on Mac OS X. On Linux you would use: libc.so. On Win32 something else?

ps: output is also forced with line-feeds

Posted: Wed Mar 12, 2008 12:30 pm
by Dmi
Thanks.

Posted: Wed Mar 12, 2008 1:16 pm
by Lutz
... and you can also use 'write-buffer' on stdout and don't need to flush:

Code: Select all

> (while true (write-buffer 0 ".") (sleep 200))
..................^Creceived SIGINT - in function sleep
(c)ontinue, (d)ebug, e(x)it, (r)eset:x
~> 

Posted: Wed Mar 12, 2008 2:05 pm
by Dmi
oh! write-buffer is sufficient! thanks again!