PRINT function does not display anything prior to a READ function call

Bug #1700317 reported by A.S. Dhillon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Invalid
Undecided
Unassigned

Bug Description

Possible Issue: PRINT function does not display anything prior to a READ function call and variable assignment

Environment: 64-bit SBCL 1.3.15 running under 64-bit Windows 10 (version 1607) on my Dell XPS laptop (Intel Core i7-2720QM CPU, 8GB Ram).

I pass the following source file to SBCL using either --script or --load at the command line, and the PRINT function does not display anything prior to a read function call and variable assignment.

However, if I type something and press enter, then the PRINT function displays the missing text string on the same line as the hello-you function output.

--------------------------------------------------------
;;; Source file: lisp-tutorial_v1.cl

(print "What's your name?") ;; Does not work under SBCL! Works under Clozure CL.

(defvar *name* (read))

(defun hello-you (*name*)
  (format t "Hello ~a! ~%" *name*))

(setq *print-case* :capitalize)

(hello-you *name*)

(quit)
---------------------------------------------------------

Example1: There's a blank line where I would expect the text "What's your name?" printed before entering John.

C:\src\00.lisp>sbcl --script "lisp-tutorial_v1.cl"

John
"What's your name?" Hello John!

C:\src\00.lisp>

---------------------------------------------------------

Example2: The same issue occurs when using --load rather than --script.

C:\src\00.lisp>sbcl --noinform --load "lisp-tutorial_v1.cl"

Jane
"What's your name?" Hello Jane!

C:\src\00.lisp>

-----------------------------------------------------------

Example3: The PRINT function works under Clozure CL without any issue.

C:\src\00.lisp>wx86cl64 -l "lisp-tutorial_v1.cl"

"What's your name?" John
Hello John!

C:\src\00.lisp>

-------------------------------------------------------------

Revision history for this message
Stas Boukarev (stassats) wrote :

Use FINISH-OUTPUT.

Changed in sbcl:
status: New → Invalid
Revision history for this message
A.S. Dhillon (ninejaguar) wrote :

Thank you for clarifying. I had not realized that SBCL on Windows always requires an extra step to flush the buffered output stream with the FINISH-OUTPUT function or FORCE-OUTPUT function when printing to the command line/shell. Whereas, Clozure CL and CLISP work as commonly expected when printing to a command line/shell, and do not require an extra step to flush the buffer.

This works as a workaround in SBCL on Windows per your suggestion, and it works with Clozure CL as well although it is not required:

;;; Source file: lisp-tutorial_v1.cl
(setq *print-case* :capitalize)

;; Print does not work in SBCL without flushing the buffered output stream.
;; Print does work in Clozure CL and CLISP without explicitly flushing the output stream buffer.
(print "What's your name?")

(FINISH-OUTPUT) ;; explicitly flushes the buffered output stream, even if empty.

(defvar *name* (read))

(defun hello-you (newName)
  (format t "Hello ~a! ~%" newName))

(hello-you *name*)

(quit)

-------------------------------------------

Example1: Using FINISH-OUTPUT after PRINT flushes the SBCL's buffered output stream.

C:\src\00.lisp>sbcl --script lisp-tutorial_v1.cl

"What's your name?" John
Hello John!

C:\src\00.lisp>

--------------------------------------------

Example2: Using FINISH-OUTPUT after PRINT to flush an empty output stream buffer does not cause an error in Clozure CL, although it is redundant.

C:\src\00.lisp>wx86cl64 -l lisp-tutorial_v1.cl

"What's your name?" Jane
Hello Jane!

C:\src\00.lisp>

Revision history for this message
Attila Lendvai (attila-lendvai) wrote :

it's not a workaround, you cannot expect unbuffered output, not even if sometimes, somewhere, it works without finish-output.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.