This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Body of `begin' is not evaluated in left-to-right order?
- From: Stephen Compall <s11 at member dot fsf dot org>
- To: Kaloian Doganov <kaloian at doganov dot org>
- Cc: kawa at sourceware dot org
- Date: Sun, 15 Jan 2006 12:35:37 -0600
- Subject: Re: Body of `begin' is not evaluated in left-to-right order?
- References: <E1EyC56-0004lT-6l@localhost.localdomain>
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