commit 3872bce6229b14d09f5ca1e5809ca5f18ee77892
parent 69a032ea8cf3b2ac7cb87eb72b53b9d140f824a6
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date: Fri, 6 Oct 2023 21:54:54 +0300
Replace while loop with cl-loop. Fell in love with cl-loop.
Diffstat:
1 file changed, 42 insertions(+), 33 deletions(-)
diff --git a/super-duper-yes-or-no.el b/super-duper-yes-or-no.el
@@ -58,7 +58,7 @@
(defun sd--randint (minimum maximum)
"Return an integer between MINIMUM (inclusive) and MAXIMUM (exclusive)."
-
+
(+ minimum
(random (- maximum
minimum))))
@@ -120,38 +120,47 @@ Will result with:
"Ask user a yes or no question.
Display in minibuffer PROMPT followed by two sequences of words, one for yes and the other for no."
- (let* ((wanted-yes-or-no (sd--make-random-yes-or-no-input-pair
- sd-number-of-words))
- (wanted-yes (car wanted-yes-or-no))
- (wanted-no (cadr wanted-yes-or-no))
- (wanted-yes-string (apply 'concat
- (sd--list-intersperse wanted-yes
- " ")))
- (wanted-no-string (apply 'concat
- (sd--list-intersperse wanted-no
- " ")))
- (user-input
- (read-from-minibuffer
- (concat prompt
- "(Enter \""
- wanted-yes-string
- "\" for yes, \""
- wanted-no-string
- "\" for no) "))))
- (while (not (or (equal user-input
- wanted-yes-string)
- (equal user-input
- wanted-no-string)))
- (setq user-input
- (read-from-minibuffer
- (concat prompt
- "(Enter \""
- wanted-yes-string
- "\" for yes, \""
- wanted-no-string
- "\" for no) "))))
- (equal user-input
- wanted-yes-string)))
+ (cl-loop
+ for wanted-yes-or-no =
+ (super-duper-yes-or-no--make-random-yes-or-no-input-pair
+ super-duper-yes-or-no-number-of-words)
+
+ for wanted-yes =
+ (car wanted-yes-or-no)
+
+ for wanted-no =
+ (cadr wanted-yes-or-no)
+
+ for wanted-yes-string =
+ (apply 'concat
+ (super-duper-yes-or-no--list-intersperse
+ wanted-yes
+ " "))
+
+ for wanted-no-string =
+ (apply 'concat
+ (super-duper-yes-or-no--list-intersperse
+ wanted-no
+ " "))
+
+ for user-input =
+ (read-from-minibuffer
+ (concat prompt
+ "(Enter \""
+ wanted-yes-string
+ "\" for yes, \""
+ wanted-no-string
+ "\" for no) "))
+
+ while
+ (not (or (equal user-input
+ wanted-yes-string)
+ (equal user-input
+ wanted-no-string)))
+
+ finally return
+ (equal user-input
+ wanted-yes-string)))
(defun sd--toggle-char-case (our-char)
(cond