Skip to content

Commit

Permalink
Fixed Y-OR-N-P and YES-OR-NO-P
Browse files Browse the repository at this point in the history
  • Loading branch information
arbv committed Jan 2, 2019
1 parent bcb7244 commit 2a6bbde
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions Sys/misc-features.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,43 @@
;;; Common Lisp Y-OR-N-P function
;;;
(defun y-or-n-p (&optional format-string &rest arguments)
(let ((stream *query-io*))
(if format-string
(progn
(fresh-line stream)
(apply #'format stream format-string arguments)))
(format stream "(Y/N)~%")
(do ((response-char))
(nil nil)
(setq response-char (char-upcase (read-char stream)))
(cond
((not (graphic-char-p response-char)))
((eq response-char #\Y) (return-from y-or-n-p t))
((eq response-char #\N) (return-from y-or-n-p nil))
(t (format stream "(Y/N)~%"))))))
(let ((stream *query-io*))
(if format-string
(progn
(fresh-line stream)
(apply #'format stream format-string arguments)))
(format stream "(Y/N)~%")
(do ((response-char))
(nil nil)
(setq response-char (char-upcase (read-char stream)))
;; remove newline character when reading from console input
(let ((ch (peek-char nil stream nil 'Eof nil)))
(when (char= ch #\Newline)
(read-char stream nil nil nil)))
(cond
((not (graphic-char-p response-char)))
((eq response-char #\Y) (return-from y-or-n-p t))
((eq response-char #\N) (return-from y-or-n-p nil))
(t (format stream "(Y/N)~%"))))))

(defun yes-or-no-p (&optional format-string &rest arguments)
(let ((stream *query-io*))
(if format-string
(progn
(fresh-line stream)
(apply #'format stream format-string arguments)))
(format stream "(Yes/No)~%")
(do ((response))
(nil nil)
(setq response (read stream))
(cond
((string-equal response "YES")(return-from yes-or-no-p t))
((string-equal response "NO") (return-from yes-or-no-p nil))
(t (format stream "(Yes/No)~%"))))))
(let ((stream *query-io*))
(if format-string
(progn
(fresh-line stream)
(apply #'format stream format-string arguments)))
(format stream "(Yes/No)~%")
(do ((response))
(nil nil)
;; remove newline character when reading from console input
(setq response (read stream))
(let ((ch (peek-char nil stream nil 'Eof nil)))
(when (char= ch #\Newline)
(read-char stream nil nil nil)))
(cond
((string-equal response "YES")(return-from yes-or-no-p t))
((string-equal response "NO") (return-from yes-or-no-p nil))
(t (format stream "(Yes/No)~%"))))))

;;;
;;; Corman Lisp WEAK-POINTER-OBJ function.
Expand Down

0 comments on commit 2a6bbde

Please sign in to comment.