8

I'm still learning lisp, so, when I came across this problem, it confused me. I have a simple function where I want to print first and then read the input:

(defun ask()
   (princ '?)
   (read))

So, when I ran this with CLISP, it showed what was expected, it printed ?, and then, on the same line, I could write the input to the read function.

When I ran this with SBCL, it went wrong. First asks me the input and then prints ?. I figured it could be because I'm not making a newline, but I really wanted to know how can I make this work in SBCL in the same line. Also, I wonder why the result in CLISP is right and in SBCL is not. Thank you for your help in advance.

DJM
  • 103
  • 1
  • 4

2 Answers2

15

It works in the proper order for me, but maybe your case can be connected with output buffering, performed by SBCL. You can add (finish-output) after princ to guarantee, that printing will be finished, before read is called.

Vsevolod Dyomkin
  • 9,343
  • 2
  • 31
  • 36
-1

For those stumbling upon this, I have found that the print / read statements seem to get out of order more often for me when running sbcl from inside an emacs shell. If I run my code from inside a gnome terminal, however, it seems to output correctly most of the time.

image showing a print statement being outputted at different times based on emacs vs gnome terminal