newLISP Fan Club

Forum => newLISP newS => Topic started by: Dmi on March 12, 2008, 03:11:51 AM

Title: buffering of (print)
Post by: Dmi on March 12, 2008, 03:11:51 AM
Hi, Lutz!



Just discover that
(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.
Title:
Post by: Lutz on March 12, 2008, 04:38:31 AM
On Unix Mac OS X you can import fflush()


> (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
Title:
Post by: Dmi on March 12, 2008, 05:30:05 AM
Thanks.
Title:
Post by: Lutz on March 12, 2008, 06:16:19 AM
... and you can also use 'write-buffer' on stdout and don't need to flush:


> (while true (write-buffer 0 ".") (sleep 200))
..................^Creceived SIGINT - in function sleep
(c)ontinue, (d)ebug, e(x)it, (r)eset:x
~>
Title:
Post by: Dmi on March 12, 2008, 07:05:58 AM
oh! write-buffer is sufficient! thanks again!