diff lisp/play/life.el @ 923:9f3cc03dae67

entered into RCS
author Jim Blandy <jimb@redhat.com>
date Tue, 04 Aug 1992 04:15:43 +0000
parents 20674ae6bf52
children 2c7997f249eb
line wrap: on
line diff
--- a/lisp/play/life.el	Tue Aug 04 04:09:07 1992 +0000
+++ b/lisp/play/life.el	Tue Aug 04 04:15:43 1992 +0000
@@ -54,34 +54,29 @@
 ;; because the compiler will convert them to constants, which should
 ;; eval faster than symbols.
 ;;
-;; The (require) wrapping forces the compiler to eval these macros at
-;; compile time.  This would not be necessary if we did not use macros
-;; inside of macros, which the compiler doesn't seem to check for.
-;;
 ;; Don't change any of the life-* macro constants unless you thoroughly
 ;; understand the `life-grim-reaper' function.
-(require
- (progn
-   (defmacro life-life-char () ?@)
-   (defmacro life-death-char () (1+ (life-life-char)))
-   (defmacro life-birth-char () 3)
-   (defmacro life-void-char () ?\ )
+
+(defmacro life-life-char () ?@)
+(defmacro life-death-char () (1+ (life-life-char)))
+(defmacro life-birth-char () 3)
+(defmacro life-void-char () ?\ )
 
-   (defmacro life-life-string () (char-to-string (life-life-char)))
-   (defmacro life-death-string () (char-to-string (life-death-char)))
-   (defmacro life-birth-string () (char-to-string (life-birth-char)))
-   (defmacro life-void-string () (char-to-string (life-void-char)))
-   (defmacro life-not-void-regexp () (concat "[^" (life-void-string) "\n]"))
+(defmacro life-life-string () (char-to-string (life-life-char)))
+(defmacro life-death-string () (char-to-string (life-death-char)))
+(defmacro life-birth-string () (char-to-string (life-birth-char)))
+(defmacro life-void-string () (char-to-string (life-void-char)))
+(defmacro life-not-void-regexp () (concat "[^" (life-void-string) "\n]"))
 
-   ;; try to optimize the (goto-char (point-min)) & (goto-char (point-max))
-   ;; idioms.  This depends on goto-char's not griping if we underrshoot
-   ;; or overshoot beginning or end of buffer.
-   (defmacro goto-beginning-of-buffer () '(goto-char 1))
-   (defmacro maxint () (lsh (lsh (lognot 0) 1) -1))
-   (defmacro goto-end-of-buffer () '(goto-char (maxint)))
+;; try to optimize the (goto-char (point-min)) & (goto-char (point-max))
+;; idioms.  This depends on goto-char's not griping if we underrshoot
+;; or overshoot beginning or end of buffer.
+(defmacro goto-beginning-of-buffer () '(goto-char 1))
+(defmacro maxint () (lsh (lsh (lognot 0) 1) -1))
+(defmacro goto-end-of-buffer () '(goto-char (maxint)))
 
-   (defmacro increment (variable) (list 'setq variable (list '1+ variable)))
-   'life))
+(defmacro increment (variable) (list 'setq variable (list '1+ variable)))
+
 
 ;; list of numbers that tell how many characters to move to get to
 ;; each of a cell's eight neighbors.
@@ -98,6 +93,7 @@
 
 (defun abs (n) (if (< n 0) (- n) n))
 
+;;;###autoload
 (defun life (&optional sleeptime)
   "Run Conway's Life simulation.
 The starting pattern is randomly selected.  Prefix arg (optional first
@@ -107,12 +103,13 @@
   (or sleeptime (setq sleeptime 1))
   (life-setup)
   (life-display-generation sleeptime)
-  (while t
-    (let ((inhibit-quit t))
-      (life-grim-reaper)
-      (life-expand-plane-if-needed)
-      (life-increment-generation)
-      (life-display-generation sleeptime))))
+  (catch 'life-exit
+    (while t
+      (let ((inhibit-quit t))
+	(life-grim-reaper)
+	(life-expand-plane-if-needed)
+	(life-increment-generation)
+	(life-display-generation sleeptime)))))
 
 (fset 'life-mode 'life)
 (put 'life-mode 'mode-class 'special)
@@ -267,7 +264,10 @@
 (defun life-display-generation (sleeptime)
   (goto-char life-window-start)
   (recenter 0)
-  (sit-for sleeptime))
+  
+  ;; Redisplay; if the user has hit a key, exit the loop.
+  (or (eq t (sit-for sleeptime))
+      (throw 'life-exit nil)))
 
 (defun life-extinct-quit ()
   (life-display-generation 0)