diff options
author | Colin Okay <colin@cicadas.surf> | 2022-07-21 16:07:18 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-07-21 16:09:32 -0500 |
commit | 6908fb40dfecc925047ac8fd434f89257e1bd4e9 (patch) | |
tree | 7eb2177803ac294aa07e89974075436785684acd | |
parent | bd4832ba7f6652d0f95cd792d2f2c206375ae566 (diff) |
[replace] permute-list with permute
-rw-r--r-- | init-el.org | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/init-el.org b/init-el.org index 103dc5a..d7b48e9 100644 --- a/init-el.org +++ b/init-el.org @@ -1966,13 +1966,15 @@ messages echo to the echo area. (setq lifecoach-index 0) (setq permuted-lifecoach-messages nil) -(defun permute-list (ls) - "Will not work properly if there are duplicates in LS, as the - returned list will not have any duplicates" - (when ls - (let ((nth - (nth (random (length ls)) ls))) - (cons nth (permute-list (delete nth ls)))))) +(defun permute (seq) + (let ((len (length seq))) + (if (zerop len) + seq + (let ((idx + (random len))) + (append (subseq seq idx (1+ idx)) + (permute (append (subseq seq 0 idx) + (subseq seq (1+ idx))))))))) (defun lifecoach-message () (setq lifecoach-index @@ -1987,7 +1989,7 @@ messages echo to the echo area. (when lifecoach-idle-timer (cancel-timer lifecoach-idle-timer)) (setq - permuted-lifecoach-messages (permute-list (copy-seq lifecoach-messages)) + permuted-lifecoach-messages (permute (copy-seq lifecoach-messages)) lifecoach-idle-timer (run-with-idle-timer 30 t #'lifecoach-message))) (defun lifecoach-stop () |