common lisp - Output prompts are on top of each other -


i reading book practical common lisp. typed simple cd database shown in chapter 3. see below. when run (add-cds) program result prompt containing 2 prompts on top of each other (more precisely, 1 prompt after another, on same line):

(add-cds) => title: artist: 

why doing this? program should give me title: prompt first , artist: prompt after i've typed in value title: followed newline. pretty sure typed in program faithfully. how fix this?

(defvar *db* nil)  (defun make-cd (title artist rating ripped)   (list :title title :artist artist :rating rating :ripped ripped))  (defun add-record (cd) (push cd *db*))  (defun prompt-read (prompt)   (format *query-io* "~a: " prompt)   (force-output *query-io*)   (read-line *query-io*))  (defun prompt-for-cd ()   (make-cd     (prompt-read "title")     (prompt-read "artist")     (or (parse-integer (prompt-read "rating") :junk-allowed t) 0)     (y-or-n-p "ripped [y/n]")))  (defun add-cds ()   (loop (add-record (prompt-for-cd))       (if (not (y-or-n-p "another? [y/n]: ")) (return)))) 

what's happening newline after (add-cds) being left in input stream (because repl stops reading sees matching close parenthesis), first read-line reading blank line , returning immediately. call clear-input before calling read-line ignore , wait new input.

(defun prompt-read (prompt)   (format *query-io* "~a: " prompt)   (force-output *query-io*)   (clear-input *query-io*)   (read-line *query-io*)) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -