emacs-super-duper-yes-or-no

Replace the yes-or-no function with an even more demanding yes or no prompt, rather than with y-or-n.
Log | Files | Refs | LICENSE

commit b2e6f66fc262d185a9e0a1501f8d099f50248ecb
parent a2b536689499a4a388b6da5ef77be724b6b54c9c
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Thu,  5 Oct 2023 02:48:23 +0300

Add an arithmetic problem yes-or-no function and an arithmetic problem template.

Diffstat:
Msuper-duper-yes-or-no.el | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+), 0 deletions(-)

diff --git a/super-duper-yes-or-no.el b/super-duper-yes-or-no.el @@ -52,6 +52,10 @@ (defvar sd-arithmetic-problem-maximum 10) +(defvar sd--arithmetic-problem-template + '(+ (* 0 0) + (* 0 0))) + (defun sd--randint (minimum maximum) "Returns an integer between MINIMUM (inclusive) and MAXIMUM (exclusive)." @@ -260,6 +264,61 @@ (t (cons (car arithmetic-expression-template) (sd--make-arithmetic-problem-arguments (cdr arithmetic-expression-template)))))) +(defun sd--yes-or-no-arithmetic-problem-p (prompt) + (interactive) + + (let* ((wanted-yes-prompt + (sd--make-arithmetic-problem + sd--arithmetic-problem-template)) + (wanted-no-prompt + (sd--make-arithmetic-problem + sd--arithmetic-problem-template)) + (wanted-input-yes + (eval wanted-yes-prompt)) + (wanted-input-no + (eval wanted-no-prompt))) + (while (= wanted-input-yes + wanted-input-no) + (setq wanted-yes-prompt + (sd--make-arithmetic-problem + sd--arithmetic-problem-template)) + (setq wanted-no-prompt + (sd--make-arithmetic-problem + sd--arithmetic-problem-template)) + (setq wanted-input-yes + (eval wanted-yes-prompt)) + (setq wanted-input-no + (eval wanted-no-prompt))) + (let ((user-input + (string-to-number + (read-from-minibuffer + (concat prompt + "Please answer " + (format "%S" wanted-yes-prompt) + " for \"yes\" and " + (format "%S" wanted-no-prompt) + " for \"no\": "))))) + (while (not (or (= user-input + wanted-input-yes) + (= user-input + wanted-input-no))) + (setq user-input + (string-to-number + (read-from-minibuffer + (concat prompt + "Please answer " + wanted-yes-prompt + " for \"yes\" and " + wanted-no-prompt + " for \"no\": "))))) + (cond + ((= user-input + wanted-input-yes) + t) + ((= user-input + wanted-input-no) + nil))))) + ;; Local Variables: ;; read-symbol-shorthands: (("sd-" . "super-duper-yes-or-no-")) ;; End: