This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Body of `begin' is not evaluated in left-to-right order?


On Sun, 2006-01-15 at 19:54 +0200, Kaloian Doganov wrote:
> (define (sleep-example)
> 		(begin (display "before\n") (sleep 3) (display "after\n")))
> 
> The obvious goal is to write a procedure that displays a line, then
> waits for some time (3 seconds) and displays another line.  When I
> evaluate `(sleep-example)' in Kawa, it first waits for 3 seconds, and
> then prints the both lines immediately one after another.  The behaviour
> looks just like if the body of `sleep-example' was:
>    
> (begin (sleep 3) (display "before\n") (display "after\n")))
> 
> The same example evaluated in Guile works as expected - "before" is
> displayed at once, then "after" is displayed 3 seconds later.  Am I
> missing something, or this is bug in Kawa?

The current output port is buffered.  Guile detects whether an output
port is a terminal when opening; if so, it sets "line buffering" mode.
You can't portably rely on this feature anyway, so see the force-output
function to do what you want.

You see it when returning to the REPL because it is usual practice to
force-output before waiting for input; indeed, that's the only way you'd
see the prompt.

-- 
Stephen Compall
http://scompall.nocandysw.com/blog


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]