Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBCL Switches print and read order (lisp)

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.

like image 880
DJM Avatar asked Dec 02 '11 17:12

DJM


1 Answers

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.

like image 184
Vsevolod Dyomkin Avatar answered Nov 09 '22 19:11

Vsevolod Dyomkin