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 0b87b3cf9d87c35d0afc5a0ec9bbe074f7b39bf6
parent f771436804e76f958821eff6dc07840e66348d27
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Sat,  7 Oct 2023 06:05:07 +0300

Swallow the cl-loop koolaid.

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

diff --git a/super-duper-yes-or-no.el b/super-duper-yes-or-no.el @@ -91,32 +91,41 @@ stay unchanged.") "Make a list of words, WANTED-NUMBER-OF-WORDS long. Used in the `super-duper-yes-or-no-yes-or-no-words-p' function." - (let ((wordlist-size (seq-length sd-words))) - (cl-loop - for random-word-index = - (random wordlist-size) + (cl-loop + with wordlist-size = + (seq-length sd-words) + + for random-word-index = + (random wordlist-size) - for random-word = - (aref sd-words - random-word-index) + for random-word = + (aref sd-words + random-word-index) - repeat wanted-number-of-words + repeat wanted-number-of-words - collect random-word))) + collect random-word)) (defun sd--make-random-yes-or-no-input-pair (number-of-words) "Make two different word lists, each NUMBER-OF-WORDS long. Used in super-duper-yes-or-no-words-p function." - (let ((yes-input (sd--make-random-input-string number-of-words))) - (named-let loop - ((no-input (sd--make-random-input-string number-of-words))) - (cond - ((equal yes-input - no-input) - (loop (sd--make-random-input-string number-of-words))) - (t (list yes-input - no-input)))))) + (cl-loop + with yes-input = + (sd--make-random-input-string + number-of-words) + + for no-input = + (sd--make-random-input-string + number-of-words) + + while + (equal yes-input + no-input) + + finally return + (list yes-input + no-input))) (defun sd--list-intersperse (input-list intersperser) "Return INPUT-LIST interspersed with INTERSPERSER. @@ -204,50 +213,56 @@ NUMBERS-OF-CHARS-TO-TOGGLE MUST be less or equal to the number of English ASCII chars in INPUT-STRING - other chars do not count in the toggle count AND they are not toggled." (let* ((input-length (length input-string)) - (our-positions (number-sequence 0 (1- input-length))) - (our-shuffled-positions nil)) - (cl-loop - for wanted-position-index = - (random (length our-positions)) - - for wanted-position = - (nth wanted-position-index - our-positions) - - for position-char = - (aref input-string - wanted-position) - - when - (or (<= ?a - position-char - ?z) - (<= ?A - position-char - ?Z)) - - do - (progn - (setq our-shuffled-positions - (cons wanted-position - our-shuffled-positions)) - (setq our-positions - (delq wanted-position - our-positions))) - - while - (< (length our-shuffled-positions) - number-of-chars-to-toggle)) + (our-shuffled-positions + (cl-loop + with our-positions = + (number-sequence 0 (1- input-length)) + + for wanted-position-index = + (random (length our-positions)) + + for wanted-position = + (nth wanted-position-index + our-positions) + + for position-char = + (aref input-string + wanted-position) + + when + (or (<= ?a + position-char + ?z) + (<= ?A + position-char + ?Z)) + + do + (setq our-positions + (delq wanted-position + our-positions)) + + repeat number-of-chars-to-toggle + + collect wanted-position))) (concat - (cl-loop for input-char in (string-to-list input-string) - for input-string-position in (number-sequence 0 (1- input-length)) - collect - (if (member - input-string-position - our-shuffled-positions) - (sd--toggle-char-case input-char) - input-char))))) + (cl-loop + for input-char + across input-string + + for input-string-position + in (number-sequence 0 + (1- input-length)) + + collect + (if (member + input-string-position + our-shuffled-positions) + (sd--toggle-char-case input-char) + input-char))))) + +(sd--randomly-toggle-string-case "abc" 2) (defun sd--string-only-uppercase (input-string) "Return INPUT-STRING with only the uppercase chars."