(make-autoload): Add usage info to docstring.
[bpt/emacs.git] / lisp / emacs-lisp / cl-macs.el
index def328d..7026ece 100644 (file)
@@ -1,4 +1,4 @@
-;; cl-macs.el --- Common Lisp extensions for GNU Emacs Lisp (part four)
+;;; cl-macs.el --- Common Lisp macros -*-byte-compile-dynamic: t;-*-
 
 ;; Copyright (C) 1993 Free Software Foundation, Inc.
 
@@ -10,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 1, or (at your option)
+;; the Free Software Foundation; either version 2, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -19,8 +19,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
@@ -31,8 +32,6 @@
 ;; This package was written by Dave Gillespie; it is a complete
 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
 ;;
-;; This package works with Emacs 18, Emacs 19, and Lucid Emacs 19.
-;;
 ;; Bug reports, comments, and suggestions are welcome!
 
 ;; This file contains the portions of the Common Lisp extensions
@@ -62,7 +61,6 @@
 (put 'cl-pop 'edebug-form-spec 'edebug-sexps)
 (put 'cl-pop2 'edebug-form-spec 'edebug-sexps)
 
-(defvar cl-emacs-type)
 (defvar cl-optimize-safety)
 (defvar cl-optimize-speed)
 
@@ -72,7 +70,6 @@
 
 (require
  (progn
-   (or (fboundp 'defalias) (fset 'defalias 'fset))
    (or (fboundp 'cl-transform-function-property)
        (defalias 'cl-transform-function-property
         (function (lambda (n p f)
 
 (defvar cl-old-bc-file-form nil)
 
-;; Patch broken Emacs 18 compiler (re top-level macros).
-;; Emacs 19 compiler doesn't need this patch.
-;; Also, undo broken definition of `eql' that uses same bytecode as `eq'.
 (defun cl-compile-time-init ()
-  (setq cl-old-bc-file-form (symbol-function 'byte-compile-file-form))
-  (or (fboundp 'byte-compile-flush-pending)   ; Emacs 19 compiler?
-      (defalias 'byte-compile-file-form
-       (function
-        (lambda (form)
-          (setq form (macroexpand form byte-compile-macro-environment))
-          (if (eq (car-safe form) 'progn)
-              (cons 'progn (mapcar 'byte-compile-file-form (cdr form)))
-            (funcall cl-old-bc-file-form form))))))
-  (put 'eql 'byte-compile 'cl-byte-compile-compiler-macro)
   (run-hooks 'cl-hack-bytecomp-hook))
 
 
@@ -143,7 +127,7 @@ and BODY is implicitly surrounded by (block NAME ...)."
     (if (car res) (list 'progn (car res) form) form)))
 
 (defmacro function* (func)
-  "(function* SYMBOL-OR-LAMBDA): introduce a function.
+  "Introduce a function.
 Like normal `function', except that if argument is a lambda form, its
 ARGLIST allows full Common Lisp conventions."
   (if (eq (car-safe func) 'lambda)
@@ -301,11 +285,7 @@ ARGLIST allows full Common Lisp conventions."
                                          'quote
                                          (list nil (cl-const-expr-val def)))
                                       (list 'list nil def))))))))
-             (cl-push karg keys)
-             (if (= (aref (symbol-name karg) 0) ?:)
-                 (progn (set karg karg)
-                        (cl-push (list 'setq karg (list 'quote karg))
-                                 bind-inits)))))))
+             (cl-push karg keys)))))
       (setq keys (nreverse keys))
       (or (and (eq (car args) '&allow-other-keys) (cl-pop args))
          (null keys) (= safety 0)
@@ -372,13 +352,13 @@ If `load' is in WHEN, BODY is evaluated when loaded after top-level compile.
 If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level."
   (if (and (fboundp 'cl-compiling-file) (cl-compiling-file)
           (not cl-not-toplevel) (not (boundp 'for-effect)))  ; horrible kludge
-      (let ((comp (or (memq 'compile when) (memq ':compile-toplevel when)))
+      (let ((comp (or (memq 'compile when) (memq :compile-toplevel when)))
            (cl-not-toplevel t))
-       (if (or (memq 'load when) (memq ':load-toplevel when))
+       (if (or (memq 'load when) (memq :load-toplevel when))
            (if comp (cons 'progn (mapcar 'cl-compile-time-too body))
              (list* 'if nil nil body))
          (progn (if comp (eval (cons 'progn body))) nil)))
-    (and (or (memq 'eval when) (memq ':execute when))
+    (and (or (memq 'eval when) (memq :execute when))
         (cons 'progn body))))
 
 (defun cl-compile-time-too (form)
@@ -389,18 +369,11 @@ If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level."
         (cons 'progn (mapcar 'cl-compile-time-too (cdr form))))
        ((eq (car-safe form) 'eval-when)
         (let ((when (nth 1 form)))
-          (if (or (memq 'eval when) (memq ':execute when))
+          (if (or (memq 'eval when) (memq :execute when))
               (list* 'eval-when (cons 'compile when) (cddr form))
             form)))
        (t (eval form) form)))
 
-(or (and (fboundp 'eval-when-compile)
-        (not (eq (car-safe (symbol-function 'eval-when-compile)) 'autoload)))
-    (eval '(defmacro eval-when-compile (&rest body)
-            "Like `progn', but evaluates the body at compile time.
-The result of the body appears to the compiler as a quoted constant."
-            (list 'quote (eval (cons 'progn body))))))
-
 (defmacro load-time-value (form &optional read-only)
   "Like `progn', but evaluates the body at load time.
 The result of the body appears to the compiler as a quoted constant."
@@ -424,7 +397,7 @@ The result of the body appears to the compiler as a quoted constant."
 ;;; Conditional control structures.
 
 (defmacro case (expr &rest clauses)
-  "(case EXPR CLAUSES...): evals EXPR, chooses from CLAUSES on that value.
+  "Eval EXPR and choose from CLAUSES on that value.
 Each clause looks like (KEYLIST BODY...).  EXPR is evaluated and compared
 against each key in each KEYLIST; the corresponding BODY is evaluated.
 If no clause succeeds, case returns nil.  A single atom may be used in
@@ -457,12 +430,12 @@ Key values are compared by `eql'."
       (list 'let (list (list temp expr)) body))))
 
 (defmacro ecase (expr &rest clauses)
-  "(ecase EXPR CLAUSES...): like `case', but error if no case fits.
+  "Like `case', but error if no case fits.
 `otherwise'-clauses are not allowed."
   (list* 'case expr (append clauses '((ecase-error-flag)))))
 
 (defmacro typecase (expr &rest clauses)
-  "(typecase EXPR CLAUSES...): evals EXPR, chooses from CLAUSES on that value.
+  "Evals EXPR, chooses from CLAUSES on that value.
 Each clause looks like (TYPE BODY...).  EXPR is evaluated and, if it
 satisfies TYPE, the corresponding BODY is evaluated.  If no clause succeeds,
 typecase returns nil.  A TYPE of `t' or `otherwise' is allowed only in the
@@ -487,7 +460,7 @@ final clause, and matches if no other keys match."
       (list 'let (list (list temp expr)) body))))
 
 (defmacro etypecase (expr &rest clauses)
-  "(etypecase EXPR CLAUSES...): like `typecase', but error if no case fits.
+  "Like `typecase', but error if no case fits.
 `otherwise'-clauses are not allowed."
   (list* 'typecase expr (append clauses '((ecase-error-flag)))))
 
@@ -495,7 +468,7 @@ final clause, and matches if no other keys match."
 ;;; Blocks and exits.
 
 (defmacro block (name &rest body)
-  "(block NAME BODY...): define a lexically-scoped block named NAME.
+  "Define a lexically-scoped block named NAME.
 NAME may be any symbol.  Code inside the BODY forms can call `return-from'
 to jump prematurely out of the block.  This differs from `catch' and `throw'
 in two respects:  First, the NAME is an unevaluated symbol rather than a
@@ -529,19 +502,19 @@ called from BODY."
     (if cl-found (setcdr cl-found t)))
   (byte-compile-normal-call (cons 'throw (cdr cl-form))))
 
-(defmacro return (&optional res)
-  "(return [RESULT]): return from the block named nil.
+(defmacro return (&optional result)
+  "Return from the block named nil.
 This is equivalent to `(return-from nil RESULT)'."
-  (list 'return-from nil res))
+  (list 'return-from nil result))
 
-(defmacro return-from (name &optional res)
-  "(return-from NAME [RESULT]): return from the block named NAME.
+(defmacro return-from (name &optional result)
+  "Return from the block named NAME.
 This jump out to the innermost enclosing `(block NAME ...)' form,
 returning RESULT from that form (or nil if RESULT is omitted).
 This is compatible with Common Lisp, but note that `defun' and
 `defmacro' do not create implicit blocks as they do in Common Lisp."
   (let ((name2 (intern (format "--cl-block-%s--" name))))
-    (list 'cl-block-throw (list 'quote name2) res)))
+    (list 'cl-block-throw (list 'quote name2) result)))
 
 
 ;;; The "loop" macro.
@@ -858,24 +831,20 @@ Valid clauses are:
 
               ((memq word '(frame frames screen screens))
                (let ((temp (gensym)))
-                 (cl-push (list var (if (eq cl-emacs-type 'lucid)
-                                        '(selected-screen) '(selected-frame)))
+                 (cl-push (list var  '(selected-frame))
                           loop-for-bindings)
                  (cl-push (list temp nil) loop-for-bindings)
                  (cl-push (list 'prog1 (list 'not (list 'eq var temp))
                                 (list 'or temp (list 'setq temp var)))
                           loop-body)
-                 (cl-push (list var (list (if (eq cl-emacs-type 'lucid)
-                                              'next-screen 'next-frame) var))
+                 (cl-push (list var (list 'next-frame var))
                           loop-for-steps)))
 
               ((memq word '(window windows))
                (let ((scr (and (memq (car args) '(in of)) (cl-pop2 args)))
                      (temp (gensym)))
                  (cl-push (list var (if scr
-                                        (list (if (eq cl-emacs-type 'lucid)
-                                                  'screen-selected-window
-                                                'frame-selected-window) scr)
+                                        (list 'frame-selected-window scr)
                                       '(selected-window)))
                           loop-for-bindings)
                  (cl-push (list temp nil) loop-for-bindings)
@@ -911,7 +880,7 @@ Valid clauses are:
        (cl-push (list (list temp (cl-pop args))) loop-bindings)
        (cl-push (list '>= (list 'setq temp (list '1- temp)) 0) loop-body)))
 
-     ((eq word 'collect)
+     ((memq word '(collect collecting))
       (let ((what (cl-pop args))
            (var (cl-loop-handle-accum nil 'nreverse)))
        (if (eq var loop-accum-var)
@@ -1199,7 +1168,7 @@ before assigning any symbols SYM to the corresponding values."
 ;;; Binding control structures.
 
 (defmacro progv (symbols values &rest body)
-  "(progv SYMBOLS VALUES BODY...): bind SYMBOLS to VALUES dynamically in BODY.
+  "Bind SYMBOLS to VALUES dynamically in BODY.
 The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists.
 Each SYMBOL in the first list is bound to the corresponding VALUE in the
 second list (or made unbound if VALUES is shorter than SYMBOLS); then the
@@ -1221,6 +1190,10 @@ go back to their previous definitions, or lack thereof)."
         (mapcar
          (function
           (lambda (x)
+            (if (or (and (fboundp (car x))
+                         (eq (car-safe (symbol-function (car x))) 'macro))
+                    (cdr (assq (car x) cl-macro-environment)))
+                (error "Use `labels', not `flet', to rebind macro names"))
             (let ((func (list 'function*
                               (list 'lambda (cadr x)
                                     (list* 'block (car x) (cddr x))))))
@@ -1232,7 +1205,22 @@ go back to their previous definitions, or lack thereof)."
          bindings)
         body))
 
-(defmacro labels (&rest args) (cons 'flet args))
+(defmacro labels (bindings &rest body)
+  "(labels ((FUNC ARGLIST BODY...) ...) FORM...): make temporary func bindings.
+This is like `flet', except the bindings are lexical instead of dynamic.
+Unlike `flet', this macro is fully complaint with the Common Lisp standard."
+  (let ((vars nil) (sets nil) (cl-macro-environment cl-macro-environment))
+    (while bindings
+      (let ((var (gensym)))
+       (cl-push var vars)
+       (cl-push (list 'function* (cons 'lambda (cdar bindings))) sets)
+       (cl-push var sets)
+       (cl-push (list (car (cl-pop bindings)) 'lambda '(&rest cl-labels-args)
+                      (list 'list* '(quote funcall) (list 'quote var)
+                            'cl-labels-args))
+                cl-macro-environment)))
+    (cl-macroexpand-all (list* 'lexical-let vars (cons (cons 'setq sets) body))
+                       cl-macro-environment)))
 
 ;; The following ought to have a better definition for use with newer
 ;; byte compilers.
@@ -1265,7 +1253,7 @@ by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...)."
 
 (defvar cl-closure-vars nil)
 (defmacro lexical-let (bindings &rest body)
-  "(lexical-let BINDINGS BODY...): like `let', but lexically scoped.
+  "Like `let', but lexically scoped.
 The main visible difference is that lambdas inside BODY will create
 lexical closures as in Common Lisp."
   (let* ((cl-closure-vars cl-closure-vars)
@@ -1274,6 +1262,7 @@ lexical closures as in Common Lisp."
                          (or (consp x) (setq x (list x)))
                          (cl-push (gensym (format "--%s--" (car x)))
                                   cl-closure-vars)
+                         (set (car cl-closure-vars) [bad-lexical-ref])
                          (list (car x) (cadr x) (car cl-closure-vars))))
                       bindings))
         (ebody 
@@ -1306,7 +1295,7 @@ lexical closures as in Common Lisp."
            ebody))))
 
 (defmacro lexical-let* (bindings &rest body)
-  "(lexical-let* BINDINGS BODY...): like `let*', but lexically scoped.
+  "Like `let*', but lexically scoped.
 The main visible difference is that lambdas inside BODY will create
 lexical closures as in Common Lisp."
   (if (null bindings) (cons 'progn body)
@@ -1443,6 +1432,7 @@ form.  See `defsetf' for a simpler way to define most setf-methods."
                          (cl-pop body))))
          (list (cl-transform-function-property
                 func 'setf-method (cons args body)))))
+(defalias 'define-setf-expander 'define-setf-method)
 
 (defmacro defsetf (func arg1 &rest args)
   "(defsetf NAME FUNC): define a `setf' method.
@@ -1527,6 +1517,10 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 (defsetf aref aset)
 (defsetf car setcar)
 (defsetf cdr setcdr)
+(defsetf caar (x) (val) (list 'setcar (list 'car x) val))
+(defsetf cadr (x) (val) (list 'setcar (list 'cdr x) val))
+(defsetf cdar (x) (val) (list 'setcdr (list 'car x) val))
+(defsetf cddr (x) (val) (list 'setcdr (list 'cdr x) val))
 (defsetf elt (seq n) (store)
   (list 'if (list 'listp seq) (list 'setcar (list 'nthcdr n seq) store)
        (list 'aset seq n store)))
@@ -1535,7 +1529,7 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 (defsetf gethash (x h &optional d) (store) (list 'cl-puthash x store h))
 (defsetf nth (n x) (store) (list 'setcar (list 'nthcdr n x) store))
 (defsetf subseq (seq start &optional end) (new)
-  (list 'progn (list 'replace seq new ':start1 start ':end1 end) new))
+  (list 'progn (list 'replace seq new :start1 start :end1 end) new))
 (defsetf symbol-function fset)
 (defsetf symbol-plist setplist)
 (defsetf symbol-value set)
@@ -1555,7 +1549,9 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 
 ;;; Some more Emacs-related place types.
 (defsetf buffer-file-name set-visited-file-name t)
-(defsetf buffer-modified-p set-buffer-modified-p t)
+(defsetf buffer-modified-p (&optional buf) (flag)
+  (list 'with-current-buffer buf
+       (list 'set-buffer-modified-p flag)))
 (defsetf buffer-name rename-buffer t)
 (defsetf buffer-string () (store)
   (list 'progn '(erase-buffer) (list 'insert store)))
@@ -1592,6 +1588,7 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 (defsetf frame-parameters modify-frame-parameters t)
 (defsetf frame-visible-p cl-set-frame-visible-p)
 (defsetf frame-width set-screen-width t)
+(defsetf frame-parameter set-frame-parameter)
 (defsetf getenv setenv t)
 (defsetf get-register set-register)
 (defsetf global-key-binding global-set-key)
@@ -1600,7 +1597,7 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 (defsetf mark set-mark t)
 (defsetf mark-marker set-mark t)
 (defsetf marker-position set-marker t)
-(defsetf match-data store-match-data t)
+(defsetf match-data set-match-data t)
 (defsetf mouse-position (scr) (store)
   (list 'set-mouse-position scr (list 'car store) (list 'cadr store)
        (list 'cddr store)))
@@ -1726,7 +1723,8 @@ a macro like `setf' or `incf'."
                            method
                          (error "Setf-method for %s returns malformed method"
                                 func)))
-                  (and (string-match "\\`c[ad][ad][ad]?[ad]?r\\'" name)
+                  (and (save-match-data
+                         (string-match "\\`c[ad][ad][ad]?[ad]?r\\'" name))
                        (get-setf-method (compiler-macroexpand place)))
                   (and (eq func 'edebug-after)
                        (get-setf-method (nth (1- (length place)) place)
@@ -1823,7 +1821,7 @@ before assigning any PLACEs to the corresponding values."
                  (cl-setf-do-store (nth 1 method) (list 'cdr temp)))))))
 
 (defmacro remf (place tag)
-  "(remf PLACE TAG): remove TAG from property list PLACE.
+  "Remove TAG from property list PLACE.
 PLACE may be a symbol, or any generalized variable allowed by `setf'.
 The form returns true if TAG was found and removed, nil otherwise."
   (let* ((method (cl-setf-do-modify place t))
@@ -1846,21 +1844,14 @@ The form returns true if TAG was found and removed, nil otherwise."
   "(shiftf PLACE PLACE... VAL): shift left among PLACEs.
 Example: (shiftf A B C) sets A to B, B to C, and returns the old A.
 Each PLACE may be a symbol, or any generalized variable allowed by `setf'."
-  (if (not (memq nil (mapcar 'symbolp (butlast (cons place args)))))
-      (list* 'prog1 place
-            (let ((sets nil))
-              (while args
-                (cl-push (list 'setq place (car args)) sets)
-                (setq place (cl-pop args)))
-              (nreverse sets)))
-    (let* ((places (reverse (cons place args)))
-          (form (cl-pop places)))
-      (while places
-       (let ((method (cl-setf-do-modify (cl-pop places) 'unsafe)))
-         (setq form (list 'let* (car method)
-                          (list 'prog1 (nth 2 method)
-                                (cl-setf-do-store (nth 1 method) form))))))
-      form)))
+  (cond
+   ((null args) place)
+   ((symbolp place) `(prog1 ,place (setq ,place (shiftf ,@args))))
+   (t
+    (let ((method (cl-setf-do-modify place 'unsafe)))
+      `(let* ,(car method)
+        (prog1 ,(nth 2 method)
+          ,(cl-setf-do-store (nth 1 method) `(shiftf ,@args))))))))
 
 (defmacro rotatef (&rest args)
   "(rotatef PLACE...): rotate left among PLACEs.
@@ -1982,7 +1973,7 @@ Like `callf', but PLACE is the second argument of FUNC, not the first."
                                       rargs)))))))
 
 (defmacro define-modify-macro (name arglist func &optional doc)
-  "(define-modify-macro NAME ARGLIST FUNC): define a `setf'-like modify macro.
+  "Define a `setf'-like modify macro.
 If NAME is called, it combines its PLACE argument with the other arguments
 from ARGLIST using FUNC: (define-modify-macro incf (&optional (n 1)) +)"
   (if (memq '&key arglist) (error "&key not allowed in define-modify-macro"))
@@ -2015,7 +2006,6 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
         (tag (intern (format "cl-struct-%s" name)))
         (tag-symbol (intern (format "cl-struct-%s-tags" name)))
         (include-descs nil)
-        (include-tag-symbol nil)
         (side-eff nil)
         (type nil)
         (named nil)
@@ -2030,33 +2020,31 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
     (while opts
       (let ((opt (if (consp (car opts)) (caar opts) (car opts)))
            (args (cdr-safe (cl-pop opts))))
-       (cond ((eq opt ':conc-name)
+       (cond ((eq opt :conc-name)
               (if args
                   (setq conc-name (if (car args)
                                       (symbol-name (car args)) ""))))
-             ((eq opt ':constructor)
+             ((eq opt :constructor)
               (if (cdr args)
                   (cl-push args constrs)
                 (if args (setq constructor (car args)))))
-             ((eq opt ':copier)
+             ((eq opt :copier)
               (if args (setq copier (car args))))
-             ((eq opt ':predicate)
+             ((eq opt :predicate)
               (if args (setq predicate (car args))))
-             ((eq opt ':include)
+             ((eq opt :include)
               (setq include (car args)
                     include-descs (mapcar (function
                                            (lambda (x)
                                              (if (consp x) x (list x))))
-                                          (cdr args))
-                    include-tag-symbol (intern (format "cl-struct-%s-tags"
-                                                       include))))
-             ((eq opt ':print-function)
+                                          (cdr args))))
+             ((eq opt :print-function)
               (setq print-func (car args)))
-             ((eq opt ':type)
+             ((eq opt :type)
               (setq type (car args)))
-             ((eq opt ':named)
+             ((eq opt :named)
               (setq named t))
-             ((eq opt ':initial-offset)
+             ((eq opt :initial-offset)
               (setq descs (nconc (make-list (car args) '(cl-skip-slot))
                                  descs)))
              (t
@@ -2087,8 +2075,12 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
                type (car inc-type)
                named (assq 'cl-tag-slot descs))
          (if (cadr inc-type) (setq tag name named t))
-         (cl-push (list 'pushnew (list 'quote tag) include-tag-symbol)
-                  forms))
+         (let ((incl include))
+           (while incl
+             (cl-push (list 'pushnew (list 'quote tag)
+                            (intern (format "cl-struct-%s-tags" incl)))
+                      forms)
+             (setq incl (get incl 'cl-struct-include)))))
       (if type
          (progn
            (or (memq type '(vector list))
@@ -2143,7 +2135,7 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
                                   (list 'nth pos 'cl-x)))))) forms)
              (cl-push (cons accessor t) side-eff)
              (cl-push (list 'define-setf-method accessor '(cl-x)
-                            (if (cadr (memq ':read-only (cddr desc)))
+                            (if (cadr (memq :read-only (cddr desc)))
                                 (list 'error (format "%s is a read-only slot"
                                                      accessor))
                               (list 'cl-struct-setf-expander 'cl-x
@@ -2195,6 +2187,8 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
                          (list 'quote descs))
                    (list 'put (list 'quote name) '(quote cl-struct-type)
                          (list 'quote (list type (eq named t))))
+                   (list 'put (list 'quote name) '(quote cl-struct-include)
+                         (list 'quote include))
                    (list 'put (list 'quote name) '(quote cl-struct-print)
                          print-auto)
                    (mapcar (function (lambda (x)
@@ -2230,23 +2224,24 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
 
 ;;; Types and assertions.
 
-(defmacro deftype (name args &rest body)
-  "(deftype NAME ARGLIST BODY...): define NAME as a new data type.
+(defmacro deftype (name arglist &rest body)
+  "Define NAME as a new data type.
 The type name can then be used in `typecase', `check-type', etc."
   (list 'eval-when '(compile load eval)
        (cl-transform-function-property
-        name 'cl-deftype-handler (cons (list* '&cl-defs ''('*) args) body))))
+        name 'cl-deftype-handler (cons (list* '&cl-defs ''('*) arglist) body))))
 
 (defun cl-make-type-test (val type)
-  (if (memq type '(character string-char)) (setq type '(integer 0 255)))
   (if (symbolp type)
       (cond ((get type 'cl-deftype-handler)
             (cl-make-type-test val (funcall (get type 'cl-deftype-handler))))
            ((memq type '(nil t)) type)
-           ((eq type 'null) (list 'null val))
-           ((eq type 'float) (list 'floatp-safe val))
-           ((eq type 'real) (list 'numberp val))
-           ((eq type 'fixnum) (list 'integerp val))
+           ((eq type 'null) `(null ,val))
+           ((eq type 'float) `(floatp-safe ,val))
+           ((eq type 'real) `(numberp ,val))
+           ((eq type 'fixnum) `(integerp ,val))
+           ;; FIXME: Should `character' accept things like ?\C-\M-a ?  -stef
+           ((memq type '(character string-char)) `(char-valid-p ,val))
            (t
             (let* ((name (symbol-name type))
                    (namep (intern (concat name "p"))))
@@ -2255,21 +2250,21 @@ The type name can then be used in `typecase', `check-type', etc."
     (cond ((get (car type) 'cl-deftype-handler)
           (cl-make-type-test val (apply (get (car type) 'cl-deftype-handler)
                                         (cdr type))))
-         ((memq (car-safe type) '(integer float real number))
-          (delq t (list 'and (cl-make-type-test val (car type))
+         ((memq (car type) '(integer float real number))
+          (delq t (and (cl-make-type-test val (car type))
                         (if (memq (cadr type) '(* nil)) t
                           (if (consp (cadr type)) (list '> val (caadr type))
                             (list '>= val (cadr type))))
                         (if (memq (caddr type) '(* nil)) t
                           (if (consp (caddr type)) (list '< val (caaddr type))
                             (list '<= val (caddr type)))))))
-         ((memq (car-safe type) '(and or not))
+         ((memq (car type) '(and or not))
           (cons (car type)
                 (mapcar (function (lambda (x) (cl-make-type-test val x)))
                         (cdr type))))
-         ((memq (car-safe type) '(member member*))
+         ((memq (car type) '(member member*))
           (list 'and (list 'member* val (list 'quote (cdr type))) t))
-         ((eq (car-safe type) 'satisfies) (list (cadr type) val))
+         ((eq (car type) 'satisfies) (list (cadr type) val))
          (t (error "Bad type spec: %s" type)))))
 
 (defun typep (val type)   ; See compiler macro below.
@@ -2314,8 +2309,7 @@ omitted, a default message listing FORM itself is used."
 (defmacro ignore-errors (&rest body)
   "Execute FORMS; if an error occurs, return nil.
 Otherwise, return result of last FORM."
-  (let ((err (gensym)))
-    (list 'condition-case err (cons 'progn body) '(error nil))))
+  `(condition-case nil (progn ,@body) (error nil)))
 
 
 ;;; Some predicates for analyzing Lisp forms.  These are used by various
@@ -2382,7 +2376,7 @@ Otherwise, return result of last FORM."
          v)
       (if (eq x (car v)) (cdr v) '(t)))))
 
-;;; Count number of times X refers to Y.  Return NIL for 0 times.
+;;; Count number of times X refers to Y.  Return nil for 0 times.
 (defun cl-expr-contains (x y)
   (cond ((equal y x) 1)
        ((and (consp x) (not (memq (car-safe x) '(quote function function*))))
@@ -2405,7 +2399,7 @@ Otherwise, return result of last FORM."
 ;;; Compiler macros.
 
 (defmacro define-compiler-macro (func args &rest body)
-  "(define-compiler-macro FUNC ARGLIST BODY...): Define a compiler-only macro.
+  "Define a compiler-only macro.
 This is like `defmacro', but macro expansion occurs only if the call to
 FUNC is compiled (i.e., not interpreted).  Compiler macros should be used
 for optimizing the way calls to FUNC are compiled; the form returned by
@@ -2415,9 +2409,9 @@ compiler macros are expanded repeatedly until no further expansions are
 possible.  Unlike regular macros, BODY can decide to \"punt\" and leave the
 original function call alone by declaring an initial `&whole foo' parameter
 and then returning foo."
-  (let ((p (if (listp args) args (list '&rest args))) (res nil))
+  (let ((p args) (res nil))
     (while (consp p) (cl-push (cl-pop p) res))
-    (setq args (nreverse res)) (setcdr res (and p (list '&rest p))))
+    (setq args (nconc (nreverse res) (and p (list '&rest p)))))
   (list 'eval-when '(compile load eval)
        (cl-transform-function-property
         func 'cl-compiler-macro
@@ -2506,7 +2500,7 @@ surrounded by (block NAME ...)."
        (t form)))
 
 (define-compiler-macro member* (&whole form a list &rest keys)
-  (let ((test (and (= (length keys) 2) (eq (car keys) ':test)
+  (let ((test (and (= (length keys) 2) (eq (car keys) :test)
                   (cl-const-expr-val (nth 1 keys)))))
     (cond ((eq test 'eq) (list 'memq a list))
          ((eq test 'equal) (list 'member a list))
@@ -2528,7 +2522,7 @@ surrounded by (block NAME ...)."
          (t form))))
 
 (define-compiler-macro assoc* (&whole form a list &rest keys)
-  (let ((test (and (= (length keys) 2) (eq (car keys) ':test)
+  (let ((test (and (= (length keys) 2) (eq (car keys) :test)
                   (cl-const-expr-val (nth 1 keys)))))
     (cond ((eq test 'eq) (list 'assq a list))
          ((eq test 'equal) (list 'assoc a list))
@@ -2539,7 +2533,7 @@ surrounded by (block NAME ...)."
 
 (define-compiler-macro adjoin (&whole form a list &rest keys)
   (if (and (cl-simple-expr-p a) (cl-simple-expr-p list)
-          (not (memq ':key keys)))
+          (not (memq :key keys)))
       (list 'if (list* 'member* a list keys) list (list 'cons a list))
     form))
 
@@ -2579,7 +2573,6 @@ surrounded by (block NAME ...)."
          (fifth 'nth 4 x) (sixth 'nth 5 x) (seventh 'nth 6 x)
          (eighth 'nth 7 x) (ninth 'nth 8 x) (tenth 'nth 9 x)
          (rest 'cdr x) (endp 'null x) (plusp '> x 0) (minusp '< x 0)
-         (caar car car) (cadr car cdr) (cdar cdr car) (cddr cdr cdr)
          (caaar car caar) (caadr car cadr) (cadar car cdar)
          (caddr car cddr) (cdaar cdr caar) (cdadr cdr cadr)
          (cddar cdr cdar) (cdddr cdr cddr) (caaaar car caaar)
@@ -2595,14 +2588,14 @@ surrounded by (block NAME ...)."
 
 ;;; Things that are side-effect-free.
 (mapcar (function (lambda (x) (put x 'side-effect-free t)))
-       '(oddp evenp abs expt signum last butlast ldiff pairlis gcd lcm
+       '(oddp evenp signum last butlast ldiff pairlis gcd lcm
          isqrt floor* ceiling* truncate* round* mod* rem* subseq
-         list-length get* getf gethash hash-table-count))
+         list-length get* getf))
 
 ;;; Things that are side-effect-and-error-free.
 (mapcar (function (lambda (x) (put x 'side-effect-free 'error-free)))
        '(eql floatp-safe list* subst acons equalp random-state-p
-         copy-tree sublis hash-table-p))
+         copy-tree sublis))
 
 
 (run-hooks 'cl-macs-load-hook)