buffering of (print)

Notices and updates
Locked
Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

buffering of (print)

Post 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.
WBR, Dmi

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Thanks.
WBR, Dmi

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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
~> 

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

oh! write-buffer is sufficient! thanks again!
WBR, Dmi

Locked