Skip to content

Commit 2a6bbde

Browse files
committed
Fixed Y-OR-N-P and YES-OR-NO-P
1 parent bcb7244 commit 2a6bbde

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

Sys/misc-features.lisp

+35-27
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,43 @@
6868
;;; Common Lisp Y-OR-N-P function
6969
;;;
7070
(defun y-or-n-p (&optional format-string &rest arguments)
71-
(let ((stream *query-io*))
72-
(if format-string
73-
(progn
74-
(fresh-line stream)
75-
(apply #'format stream format-string arguments)))
76-
(format stream "(Y/N)~%")
77-
(do ((response-char))
78-
(nil nil)
79-
(setq response-char (char-upcase (read-char stream)))
80-
(cond
81-
((not (graphic-char-p response-char)))
82-
((eq response-char #\Y) (return-from y-or-n-p t))
83-
((eq response-char #\N) (return-from y-or-n-p nil))
84-
(t (format stream "(Y/N)~%"))))))
71+
(let ((stream *query-io*))
72+
(if format-string
73+
(progn
74+
(fresh-line stream)
75+
(apply #'format stream format-string arguments)))
76+
(format stream "(Y/N)~%")
77+
(do ((response-char))
78+
(nil nil)
79+
(setq response-char (char-upcase (read-char stream)))
80+
;; remove newline character when reading from console input
81+
(let ((ch (peek-char nil stream nil 'Eof nil)))
82+
(when (char= ch #\Newline)
83+
(read-char stream nil nil nil)))
84+
(cond
85+
((not (graphic-char-p response-char)))
86+
((eq response-char #\Y) (return-from y-or-n-p t))
87+
((eq response-char #\N) (return-from y-or-n-p nil))
88+
(t (format stream "(Y/N)~%"))))))
8589

8690
(defun yes-or-no-p (&optional format-string &rest arguments)
87-
(let ((stream *query-io*))
88-
(if format-string
89-
(progn
90-
(fresh-line stream)
91-
(apply #'format stream format-string arguments)))
92-
(format stream "(Yes/No)~%")
93-
(do ((response))
94-
(nil nil)
95-
(setq response (read stream))
96-
(cond
97-
((string-equal response "YES")(return-from yes-or-no-p t))
98-
((string-equal response "NO") (return-from yes-or-no-p nil))
99-
(t (format stream "(Yes/No)~%"))))))
91+
(let ((stream *query-io*))
92+
(if format-string
93+
(progn
94+
(fresh-line stream)
95+
(apply #'format stream format-string arguments)))
96+
(format stream "(Yes/No)~%")
97+
(do ((response))
98+
(nil nil)
99+
;; remove newline character when reading from console input
100+
(setq response (read stream))
101+
(let ((ch (peek-char nil stream nil 'Eof nil)))
102+
(when (char= ch #\Newline)
103+
(read-char stream nil nil nil)))
104+
(cond
105+
((string-equal response "YES")(return-from yes-or-no-p t))
106+
((string-equal response "NO") (return-from yes-or-no-p nil))
107+
(t (format stream "(Yes/No)~%"))))))
100108

101109
;;;
102110
;;; Corman Lisp WEAK-POINTER-OBJ function.

0 commit comments

Comments
 (0)