emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master c5f319e 3/3: Replace more nested ifs with cond


From: Mark Oteiza
Subject: [Emacs-diffs] master c5f319e 3/3: Replace more nested ifs with cond
Date: Sat, 8 Apr 2017 11:37:02 -0400 (EDT)

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

    Replace more nested ifs with cond
    
    This is a continuation of d526047 "Replace more nested ifs with cond".
    * lisp/play/dunnet.el (dun-firstword, dun-firstwordl, dun-cat): Use
    when and cond where appropriate.
---
 lisp/play/dunnet.el | 51 +++++++++++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 28 deletions(-)

diff --git a/lisp/play/dunnet.el b/lisp/play/dunnet.el
index 8f013bb..6acdf36 100644
--- a/lisp/play/dunnet.el
+++ b/lisp/play/dunnet.el
@@ -2199,16 +2199,14 @@ for a moment, then straighten yourself up.\n")
 ;;; Get the first non-ignored word from a list.
 
 (defun dun-firstword (list)
-  (if (not (car list))
-      nil
-    (while (and list (member (intern (car list)) dun-ignore))
+  (when (car list)
+    (while (and list (memq (intern (car list)) dun-ignore))
       (setq list (cdr list)))
     (car list)))
 
 (defun dun-firstwordl (list)
-  (if (not (car list))
-      nil
-    (while (and list (member (intern (car list)) dun-ignore))
+  (when (car list)
+    (while (and list (memq (intern (car list)) dun-ignore))
       (setq list (cdr list)))
     list))
 
@@ -2820,28 +2818,25 @@ drwxr-xr-x  3 root     staff          2048 Jan 1 1970 
..")
   (setq dun-badcd t))
 
 (defun dun-cat (args)
-  (let (doto checklist)
-    (if (not (setq args (car args)))
-       (dun-mprincl "Usage: cat <ascii-file-name>")
-      (if (string-match "/" args)
-         (dun-mprincl "cat: only files in current directory allowed.")
-       (if (and (> dun-cdroom 0) (string= args "description"))
-           (dun-mprincl (car (nth dun-cdroom dun-rooms)))
-         (if (setq doto (string-match "\\.o" args))
-             (progn
-               (if (= dun-cdroom -10)
-                   (setq checklist dun-inventory)
-                 (setq checklist (nth dun-cdroom dun-room-objects)))
-               (if (not (member (cdr
-                                 (assq (intern
-                                        (substring args 0 doto))
-                                       dun-objnames))
-                                checklist))
-                   (dun-mprincl "File not found.")
-                 (dun-mprincl "Ascii files only.")))
-           (if (assq (intern args) dun-unix-verbs)
-               (dun-mprincl "Ascii files only.")
-             (dun-mprincl "File not found."))))))))
+  (cond
+   ((null (setq args (car args)))
+    (dun-mprincl "Usage: cat <ascii-file-name>"))
+   ((string-match-p "/" args)
+    (dun-mprincl "cat: only files in current directory allowed."))
+   ((and (> dun-cdroom 0) (string= args "description"))
+    (dun-mprincl (car (nth dun-cdroom dun-rooms))))
+   ((string-match "\\.o" args)
+    (let ((doto (match-beginning 0)) checklist)
+      (if (= dun-cdroom -10)
+          (setq checklist dun-inventory)
+        (setq checklist (nth dun-cdroom dun-room-objects)))
+      (if (member (cdr (assq (intern (substring args 0 doto)) dun-objnames))
+                  checklist)
+          (dun-mprincl "Ascii files only.")
+        (dun-mprincl "File not found."))))
+   ((assq (intern args) dun-unix-verbs)
+    (dun-mprincl "Ascii files only."))
+   (t (dun-mprincl "File not found."))))
 
 (defun dun-rlogin-endgame ()
   (if (not (= (dun-score nil) 90))



reply via email to

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