commit a2ab249055550a7ab7eeeb330796e587a3a37387 parent 4094cc228cc3a9f3e79e6eaae47808050abb01a3 Author: Yuval Langer <yuvallangerontheroad@gmail.com> Date: Fri, 6 Oct 2023 01:18:52 +0300 Convert another function into using `cl-loop`. Diffstat:
M | super-duper-yes-or-no.el | | | 65 | ++++++++++++++++++++++++++++++++++++++++------------------------- |
1 file changed, 40 insertions(+), 25 deletions(-)
diff --git a/super-duper-yes-or-no.el b/super-duper-yes-or-no.el @@ -170,35 +170,50 @@ 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)) - (while (< (length our-shuffled-positions) - number-of-chars-to-toggle) - (let* ((wanted-position-index (random (length our-positions))) - (wanted-position (nth wanted-position-index - our-positions)) - (position-char (aref input-string - wanted-position))) - (when (or (and (>= position-char - (string-to-char "a")) - (<= position-char - (string-to-char "z"))) - (and (>= position-char - (string-to-char "A")) - (<= position-char - (string-to-char "Z")))) - (setq our-shuffled-positions - (cons wanted-position - our-shuffled-positions)) - (setq our-positions (delq wanted-position - our-positions))))) + (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 (and (>= position-char + (string-to-char "a")) + (<= position-char + (string-to-char "z"))) + (and (>= position-char + (string-to-char "A")) + (<= position-char + (string-to-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)) (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))))) + collect + (if (member + input-string-position + our-shuffled-positions) + (sd--toggle-char-case input-char) + input-char))))) (defun sd--string-only-uppercase (input-string) "Return INPUT-STRING with only the uppercase chars."