emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 34d69ed: Simpler filter implementation


From: Mark Oteiza
Subject: [Emacs-diffs] master 34d69ed: Simpler filter implementation
Date: Sun, 19 Mar 2017 22:29:47 -0400 (EDT)

branch: master
commit 34d69ed7355572b905bf16ab84024b7056cffe85
Author: Mark Oteiza <address@hidden>
Commit: Mark Oteiza <address@hidden>

    Simpler filter implementation
    
    * lisp/play/dunnet.el (dun-endgame-question): Get or set
    dun-endgame-questions one time only.  Use dolist and an index to
    prune the list.
---
 lisp/play/dunnet.el | 39 +++++++++++++++++----------------------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/lisp/play/dunnet.el b/lisp/play/dunnet.el
index 6779462..8f013bb 100644
--- a/lisp/play/dunnet.el
+++ b/lisp/play/dunnet.el
@@ -2106,28 +2106,23 @@ for a moment, then straighten yourself up.\n")
        (dun-mprincl "That answer is incorrect.")))))
 
 (defun dun-endgame-question ()
-(if (not dun-endgame-questions)
-    (progn
-      (dun-mprincl "Your question is:")
-      (dun-mprincl "No more questions, just do ‘answer foo’.")
-      (setq dun-correct-answer '("foo")))
-  (let (which i newques)
-    (setq i 0)
-    (setq newques nil)
-    (setq which (random (length dun-endgame-questions)))
-    (dun-mprincl "Your question is:")
-    (dun-mprincl (setq dun-endgame-question (car
-                                            (nth which
-                                                 dun-endgame-questions))))
-    (setq dun-correct-answer (cdr (nth which dun-endgame-questions)))
-    (while (< i which)
-      (setq newques (append newques (list (nth i dun-endgame-questions))))
-      (setq i (1+ i)))
-    (setq i (1+ which))
-    (while (< i (length dun-endgame-questions))
-      (setq newques (append newques (list (nth i dun-endgame-questions))))
-      (setq i (1+ i)))
-    (setq dun-endgame-questions newques))))
+  (let ((questions dun-endgame-questions))
+    (if (null questions)
+        (progn
+          (dun-mprincl "Your question is:")
+          (dun-mprincl "No more questions, just do ‘answer foo’.")
+          (setq dun-correct-answer '("foo")))
+      (let* ((which (random (length questions)))
+             (question (nth which questions)))
+        (dun-mprincl "Your question is:")
+        (dun-mprincl (setq dun-endgame-question (car question)))
+        (setq dun-correct-answer (cdr question))
+        (let ((i 0) res)
+          (dolist (q questions)
+            (when (/= i which)
+              (push q res))
+            (setq i (1+ i)))
+          (setq dun-endgame-questions (nreverse res)))))))
 
 (defun dun-power (_args)
   (if (not (= dun-current-room pc-area))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]