LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   weard sbcl read function behaviour (https://www.linuxquestions.org/questions/programming-9/weard-sbcl-read-function-behaviour-713762/)

satori@sanitarium 03-23-2009 06:43 AM

weard sbcl read function behaviour
 
I just started learning common lisp and I'm following Graham's ANSI Common Lisp book using sbcl, emacs and slime.
A problem arises with the read function in sbcl. The code is:

(defun ask ()
(format t "enter something")
(setq x (read))
(format t "you entered ~a" x))

In sbcl after calling ask the prompt just sits there until i enter something and then returns entersomethingyouentered ENTEREDVALUE.
In clisp everything works fine, so is this just some funny sbcl implementation problem or am I doing something wrong?

taylor_venable 03-23-2009 07:11 AM

It's getting buffered. Data accumulates in the *STANDARD-OUTPUT* stream (well, streams in general if buffered) until there's reasonably enough to bother to call the I/O functions to actually display it or send it to a file or socket or wherever it's going. It's an efficiency thing; if you write out single bytes there's no reason to actually write it within the system until you've built up quite a bit of output. In C for example this also occurs and you use fflush(). In Common Lisp you use (FINISH-OUTPUT stream) to trigger a flush and then wait for it to finish before continuing. The value of stream here is *STANDARD-OUTPUT* because that's where (FORMAT T ...) goes.


All times are GMT -5. The time now is 12:34 AM.