Star Sapphire Common LISP Home

Download Star Saphire
Index

LISP: Y-OR-N-P

C: L_YOrNp

min args: 0

max args: -1

[F][CLTL 22]

SYNOPSIS:

y-or-n-p &optional format-string &rest arguments

DESCRIPTION:

The y-or-n-p and yes-or-no-p functions provide a convenient and consistent interface for asking questions of the user. Questions are printed and the answers are read through direct bios calls under DOS and via Message Box under Windows and thus may not show up in dribble output.

The y-or-n-p predicate is for asking the user a question whose answer is either "yes" or "no." It types out a message (if supplied), and waits for the user to type the character 'y', 'n', 'Y' or 'N'. It is not necessary to type a carriage return. The message is reprinted until one of the four valid responses is typed. y-or-n-p returns t if the answer was "yes" or nil if the answer was "no."

If the format-string argument is supplied and not nil, then a fresh-line operation is performed; a message is then printed as if the format-string and arguments were given to format. Otherwise it is assumed that any message has already been printed by other means. If you want a question mark at the end of the message, you must put it there yourself; y-or-n-p will not add it. However, the message should not contain an explanatory note such as (Y or N), because the nature of the interface provided for y-or-n-p by a given implementation might not involve typing a character on a keyboard; y-or-n-p will provide such a note if appropriate.

Here are some examples of the use of y-or-n-p:

(y-or-n-p "Copy or Move file?")

(y-or-n-p "Floppy drive ~c: is not ready. Retry?" drive-letter)

y-or-n-p should only be used for questions that the user knows are coming or in situations where the user is known to be waiting for a response of some kind. If the user is unlikely to anticipate the question, or if the consequences of the answer might be grave and irreparable, then y-or-n-p should not be used because the user might type ahead and thereby accidentally answer the question. For such questions as "Shall I delete all of your files?" it is better to use yes-or-no-p.

LISP: YES-OR-NO-P

C: L_YesOrNop

min args: 0

max args: -1

[F][CLTL 22]

SYNOPSIS:

yes-or-no-p &optional format-string &rest arguments

DESCRIPTION:

This predicate, like y-or-n-p, is for asking the user a question whose answer is either "Yes" or "No." It types out a message (if supplied), attracts the user's attention (for example, by ringing the terminal's bell), and reads a reply. The user must type "yes" or "no" followed by a carriage return. If this response is not received, the message is repeated.

If the format-string argument is supplied and not nil, then a fresh-line operation is performed; a message is then printed as if the format-string and arguments were given to format. Otherwise it is assumed that any message has already been printed by other means. If you want a question mark at the end of the message, you must put it there yourself; yes-or-no-p will not add it. However, the message should not contain an explanatory note such as (Yes or No) because the nature of the interface provided for yes-or-no-p by a given implementation might not involve typing the reply on a keyboard; yes-or-no-p will provide such a note if appropriate.

To allow the user to answer a yes-or-no question with a single character, use y-or-n-p. yes-or-no-p should be used for unanticipated or momentous questions; this is why it attracts attention and why it requires a multiple-action sequence to answer it.