annotate lisp/cl/cl-macs.el @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents e121b013d1f0
children f53b5ca2e663
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; cl-macs.el --- Common Lisp extensions for GNU Emacs Lisp (part four)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Dave Gillespie <daveg@synaptics.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Version: 2.02
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; These are extensions to Emacs Lisp that provide a degree of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Common Lisp compatibility, beyond what is already built-in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; in Emacs Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; This package was written by Dave Gillespie; it is a complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; This package works with Emacs 18, Emacs 19, and Lucid Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; Bug reports, comments, and suggestions are welcome!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; This file contains the portions of the Common Lisp extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; package which should be autoloaded, but need only be present
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; if the compiler or interpreter is used---this file is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; necessary for executing compiled code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; See cl.el for Change Log.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (or (memq 'cl-19 features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (error "Tried to load `cl-macs' before `cl'!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; We define these here so that this file can compile without having
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; loaded the cl.el file already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defmacro cl-push (x place) (list 'setq place (list 'cons x place)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defmacro cl-pop (place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (list 'car (list 'prog1 place (list 'setq place (list 'cdr place)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defmacro cl-pop2 (place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (list 'prog1 (list 'car (list 'cdr place))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (list 'setq place (list 'cdr (list 'cdr place)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (put 'cl-push 'edebug-form-spec 'edebug-sexps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (put 'cl-pop 'edebug-form-spec 'edebug-sexps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (put 'cl-pop2 'edebug-form-spec 'edebug-sexps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar cl-emacs-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvar cl-optimize-safety)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvar cl-optimize-speed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; This kludge allows macros which use cl-transform-function-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; to be called at compile-time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (or (fboundp 'defalias) (fset 'defalias 'fset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (or (fboundp 'cl-transform-function-property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defalias 'cl-transform-function-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (function (lambda (n p f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (list 'put (list 'quote n) (list 'quote p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (list 'function (cons 'lambda f)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (car (or features (setq features (list 'cl-kludge))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; Initialization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defvar cl-old-bc-file-form nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; Patch broken Emacs 18 compiler (re top-level macros).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; Emacs 19 compiler doesn't need this patch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; Also, undo broken definition of `eql' that uses same bytecode as `eq'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun cl-compile-time-init ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq cl-old-bc-file-form (symbol-function 'byte-compile-file-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (or (fboundp 'byte-compile-flush-pending) ; Emacs 19 compiler?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defalias 'byte-compile-file-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (lambda (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (setq form (macroexpand form byte-compile-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (if (eq (car-safe form) 'progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (cons 'progn (mapcar 'byte-compile-file-form (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (funcall cl-old-bc-file-form form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (put 'eql 'byte-compile 'cl-byte-compile-compiler-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (run-hooks 'cl-hack-bytecomp-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;; Symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (defvar *gensym-counter*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (defun gensym (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 "Generate a new uninterned symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 The name is made by appending a number to PREFIX, default \"G\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (let ((prefix (if (stringp arg) arg "G"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (num (if (integerp arg) arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (prog1 *gensym-counter*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq *gensym-counter* (1+ *gensym-counter*))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (make-symbol (format "%s%d" prefix num))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defun gentemp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "Generate a new interned symbol with a unique name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 The name is made by appending a number to PREFIX, default \"G\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (let ((prefix (if (stringp arg) arg "G"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (while (intern-soft (setq name (format "%s%d" prefix *gensym-counter*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (setq *gensym-counter* (1+ *gensym-counter*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (intern name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;; Program structure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defmacro defun* (name args &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "(defun* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 Like normal `defun', except ARGLIST allows full Common Lisp conventions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 and BODY is implicitly surrounded by (block NAME ...)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (let* ((res (cl-transform-lambda (cons args body) name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (form (list* 'defun name (cdr res))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (if (car res) (list 'progn (car res) form) form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (defmacro defmacro* (name args &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 "(defmacro* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 Like normal `defmacro', except ARGLIST allows full Common Lisp conventions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 and BODY is implicitly surrounded by (block NAME ...)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (let* ((res (cl-transform-lambda (cons args body) name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (form (list* 'defmacro name (cdr res))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (if (car res) (list 'progn (car res) form) form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defmacro function* (func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "(function* SYMBOL-OR-LAMBDA): introduce a function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 Like normal `function', except that if argument is a lambda form, its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ARGLIST allows full Common Lisp conventions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (if (eq (car-safe func) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (let* ((res (cl-transform-lambda (cdr func) 'cl-none))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (form (list 'function (cons 'lambda (cdr res)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if (car res) (list 'progn (car res) form) form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (list 'function func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defun cl-transform-function-property (func prop form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (let ((res (cl-transform-lambda form func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (append '(progn) (cdr (cdr (car res)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (list (list 'put (list 'quote func) (list 'quote prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (list 'function (cons 'lambda (cdr res))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (defconst lambda-list-keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 '(&optional &rest &key &allow-other-keys &aux &whole &body &environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defvar cl-macro-environment nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defvar bind-block) (defvar bind-defs) (defvar bind-enquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defvar bind-inits) (defvar bind-lets) (defvar bind-forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun cl-transform-lambda (form bind-block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (let* ((args (car form)) (body (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (bind-defs nil) (bind-enquote nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (bind-inits nil) (bind-lets nil) (bind-forms nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (header nil) (simple-args nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (while (or (stringp (car body)) (eq (car-safe (car body)) 'interactive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (cl-push (cl-pop body) header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq args (if (listp args) (copy-list args) (list '&rest args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (let ((p (last args))) (if (cdr p) (setcdr p (list '&rest (cdr p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (if (setq bind-defs (cadr (memq '&cl-defs args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq args (delq '&cl-defs (delq bind-defs args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 bind-defs (cadr bind-defs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (if (setq bind-enquote (memq '&cl-quote args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq args (delq '&cl-quote args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (if (memq '&whole args) (error "&whole not currently implemented"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (let* ((p (memq '&environment args)) (v (cadr p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if p (setq args (nconc (delq (car p) (delq v args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (list '&aux (list v 'cl-macro-environment))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (while (and args (symbolp (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (not (memq (car args) '(nil &rest &body &key &aux)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (not (and (eq (car args) '&optional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (or bind-defs (consp (cadr args))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (cl-push (cl-pop args) simple-args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (or (eq bind-block 'cl-none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq body (list (list* 'block bind-block body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (if (null args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (list* nil (nreverse simple-args) (nconc (nreverse header) body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (if (memq '&optional simple-args) (cl-push '&optional args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (cl-do-arglist args nil (- (length simple-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (memq '&optional simple-args) 1 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (setq bind-lets (nreverse bind-lets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (list* (and bind-inits (list* 'eval-when '(compile load eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (nreverse bind-inits)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (nconc (nreverse simple-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (list '&rest (car (cl-pop bind-lets))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (nconc (nreverse header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (list (nconc (list 'let* bind-lets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (nreverse bind-forms) body)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun cl-do-arglist (args expr &optional num) ; uses bind-*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (if (nlistp args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (if (or (memq args lambda-list-keywords) (not (symbolp args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (error "Invalid argument name: %s" args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (cl-push (list args expr) bind-lets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (setq args (copy-list args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (let ((p (last args))) (if (cdr p) (setcdr p (list '&rest (cdr p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (let ((p (memq '&body args))) (if p (setcar p '&rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (if (memq '&environment args) (error "&environment used incorrectly"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (let ((save-args args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (restarg (memq '&rest args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (safety (if (cl-compiling-file) cl-optimize-safety 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (keys nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (laterarg nil) (exactarg nil) minarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (or num (setq num 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (if (listp (cadr restarg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (setq restarg (gensym "--rest--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq restarg (cadr restarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (cl-push (list restarg expr) bind-lets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (eq (car args) '&whole)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (cl-push (list (cl-pop2 args) restarg) bind-lets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (let ((p args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq minarg restarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (while (and p (not (memq (car p) lambda-list-keywords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (or (eq p args) (setq minarg (list 'cdr minarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq p (cdr p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (memq (car p) '(nil &aux))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq minarg (list '= (list 'length restarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (length (ldiff args p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 exactarg (not (eq args p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (while (and args (not (memq (car args) lambda-list-keywords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (let ((poparg (list (if (or (cdr args) (not exactarg)) 'pop 'car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 restarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (cl-do-arglist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (cl-pop args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (if (or laterarg (= safety 0)) poparg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (list 'if minarg poparg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (list 'signal '(quote wrong-number-of-arguments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (list 'list (and (not (eq bind-block 'cl-none))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (list 'quote bind-block))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (list 'length restarg)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (setq num (1+ num) laterarg t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (while (and (eq (car args) '&optional) (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (while (and args (not (memq (car args) lambda-list-keywords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (let ((arg (cl-pop args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (or (consp arg) (setq arg (list arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (if (cddr arg) (cl-do-arglist (nth 2 arg) (list 'and restarg t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (let ((def (if (cdr arg) (nth 1 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (or (car bind-defs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (nth 1 (assq (car arg) bind-defs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (poparg (list 'pop restarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (and def bind-enquote (setq def (list 'quote def)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (cl-do-arglist (car arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (if def (list 'if restarg poparg def) poparg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (setq num (1+ num))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (if (eq (car args) '&rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (let ((arg (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (if (consp arg) (cl-do-arglist arg restarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (or (eq (car args) '&key) (= safety 0) exactarg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (cl-push (list 'if restarg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (list 'signal '(quote wrong-number-of-arguments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (list 'list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (and (not (eq bind-block 'cl-none))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (list 'quote bind-block))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (list '+ num (list 'length restarg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 bind-forms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (while (and (eq (car args) '&key) (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (while (and args (not (memq (car args) lambda-list-keywords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (let ((arg (cl-pop args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (or (consp arg) (setq arg (list arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (let* ((karg (if (consp (car arg)) (caar arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (intern (format ":%s" (car arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (varg (if (consp (car arg)) (cadar arg) (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (def (if (cdr arg) (cadr arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (or (car bind-defs) (cadr (assq varg bind-defs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (look (list 'memq (list 'quote karg) restarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (and def bind-enquote (setq def (list 'quote def)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (if (cddr arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (let* ((temp (or (nth 2 arg) (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (val (list 'car (list 'cdr temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (cl-do-arglist temp look)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (cl-do-arglist varg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (list 'if temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (list 'prog1 val (list 'setq temp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 def)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (cl-do-arglist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 varg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (list 'car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (list 'cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (if (null def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 look
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (list 'or look
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (if (eq (cl-const-expr-p def) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 'quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (list nil (cl-const-expr-val def)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (list 'list nil def))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (cl-push karg keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (if (= (aref (symbol-name karg) 0) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (progn (set karg karg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (cl-push (list 'setq karg (list 'quote karg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 bind-inits)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq keys (nreverse keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (or (and (eq (car args) '&allow-other-keys) (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (null keys) (= safety 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (let* ((var (gensym "--keys--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (allow '(:allow-other-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (check (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 'while var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 'cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (list (list 'memq (list 'car var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (list 'quote (append keys allow)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (list 'setq var (list 'cdr (list 'cdr var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (list (list 'car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (list 'cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (list 'memq (cons 'quote allow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 restarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (list 'setq var nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (list t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (format "Keyword argument %%s not one of %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (list 'car var)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (cl-push (list 'let (list (list var restarg)) check) bind-forms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (while (and (eq (car args) '&aux) (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (while (and args (not (memq (car args) lambda-list-keywords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (if (consp (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (if (and bind-enquote (cadar args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (cl-do-arglist (caar args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (list 'quote (cadr (cl-pop args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (cl-do-arglist (caar args) (cadr (cl-pop args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (cl-do-arglist (cl-pop args) nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (if args (error "Malformed argument list %s" save-args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (defun cl-arglist-args (args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (if (nlistp args) (list args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (let ((res nil) (kind nil) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (while (consp args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (setq arg (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (if (memq arg lambda-list-keywords) (setq kind arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (if (eq arg '&cl-defs) (cl-pop args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (and (consp arg) kind (setq arg (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (and (consp arg) (cdr arg) (eq kind '&key) (setq arg (cadr arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq res (nconc res (cl-arglist-args arg))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (nconc res (and args (list args))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defmacro destructuring-bind (args expr &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (let* ((bind-lets nil) (bind-forms nil) (bind-inits nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (bind-defs nil) (bind-block 'cl-none))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (cl-do-arglist (or args '(&aux)) expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (append '(progn) bind-inits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (list (nconc (list 'let* (nreverse bind-lets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (nreverse bind-forms) body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 ;;; The `eval-when' form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (defvar cl-not-toplevel nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (defmacro eval-when (when &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 "(eval-when (WHEN...) BODY...): control when BODY is evaluated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 If `compile' is in WHEN, BODY is evaluated when compiled at top-level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 If `load' is in WHEN, BODY is evaluated when loaded after top-level compile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (if (and (fboundp 'cl-compiling-file) (cl-compiling-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (not cl-not-toplevel) (not (boundp 'for-effect))) ; horrible kludge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (let ((comp (or (memq 'compile when) (memq ':compile-toplevel when)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (cl-not-toplevel t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (if (or (memq 'load when) (memq ':load-toplevel when))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if comp (cons 'progn (mapcar 'cl-compile-time-too body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (list* 'if nil nil body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (progn (if comp (eval (cons 'progn body))) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (and (or (memq 'eval when) (memq ':execute when))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (cons 'progn body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (defun cl-compile-time-too (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (or (and (symbolp (car-safe form)) (get (car-safe form) 'byte-hunk-handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (setq form (macroexpand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 form (cons '(eval-when) byte-compile-macro-environment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (cond ((eq (car-safe form) 'progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (cons 'progn (mapcar 'cl-compile-time-too (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ((eq (car-safe form) 'eval-when)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (let ((when (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (if (or (memq 'eval when) (memq ':execute when))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (list* 'eval-when (cons 'compile when) (cddr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (t (eval form) form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (or (and (fboundp 'eval-when-compile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (not (eq (car-safe (symbol-function 'eval-when-compile)) 'autoload)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (eval '(defmacro eval-when-compile (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 "Like `progn', but evaluates the body at compile time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 The result of the body appears to the compiler as a quoted constant."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (list 'quote (eval (cons 'progn body))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (defmacro load-time-value (form &optional read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 "Like `progn', but evaluates the body at load time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 The result of the body appears to the compiler as a quoted constant."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (if (cl-compiling-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (let* ((temp (gentemp "--cl-load-time--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (set (list 'set (list 'quote temp) form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (if (and (fboundp 'byte-compile-file-form-defmumble)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (boundp 'this-kind) (boundp 'that-one))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (fset 'byte-compile-file-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (list 'lambda '(form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (list 'fset '(quote byte-compile-file-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (list 'quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (symbol-function 'byte-compile-file-form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (list 'byte-compile-file-form (list 'quote set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 '(byte-compile-file-form form)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
422 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (print set (symbol-value ;;'outbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 'byte-compile-output-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (list 'symbol-value (list 'quote temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (list 'quote (eval form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;;; Conditional control structures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (defmacro case (expr &rest clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 "(case EXPR CLAUSES...): evals EXPR, chooses from CLAUSES on that value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 Each clause looks like (KEYLIST BODY...). EXPR is evaluated and compared
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 against each key in each KEYLIST; the corresponding BODY is evaluated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 If no clause succeeds, case returns nil. A single atom may be used in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 place of a KEYLIST of one atom. A KEYLIST of `t' or `otherwise' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 allowed only in the final clause, and matches if no other keys match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 Key values are compared by `eql'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (let* ((temp (if (cl-simple-expr-p expr 3) expr (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (head-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (body (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 'cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (cons (cond ((memq (car c) '(t otherwise)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ((eq (car c) 'ecase-error-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (list 'error "ecase failed: %s, %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 temp (list 'quote (reverse head-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ((listp (car c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (setq head-list (append (car c) head-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (list 'member* temp (list 'quote (car c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (if (memq (car c) head-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (error "Duplicate key in case: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (car c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (cl-push (car c) head-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (list 'eql temp (list 'quote (car c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (or (cdr c) '(nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 clauses))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (if (eq temp expr) body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (list 'let (list (list temp expr)) body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (defmacro ecase (expr &rest clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 "(ecase EXPR CLAUSES...): like `case', but error if no case fits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 `otherwise'-clauses are not allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (list* 'case expr (append clauses '((ecase-error-flag)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (defmacro typecase (expr &rest clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 "(typecase EXPR CLAUSES...): evals EXPR, chooses from CLAUSES on that value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 Each clause looks like (TYPE BODY...). EXPR is evaluated and, if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 satisfies TYPE, the corresponding BODY is evaluated. If no clause succeeds,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 typecase returns nil. A TYPE of `t' or `otherwise' is allowed only in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 final clause, and matches if no other keys match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (let* ((temp (if (cl-simple-expr-p expr 3) expr (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (type-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (body (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 'cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (cons (cond ((eq (car c) 'otherwise) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ((eq (car c) 'ecase-error-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (list 'error "etypecase failed: %s, %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 temp (list 'quote (reverse type-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (cl-push (car c) type-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (cl-make-type-test temp (car c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (or (cdr c) '(nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 clauses))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if (eq temp expr) body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (list 'let (list (list temp expr)) body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (defmacro etypecase (expr &rest clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 "(etypecase EXPR CLAUSES...): like `typecase', but error if no case fits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 `otherwise'-clauses are not allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (list* 'typecase expr (append clauses '((ecase-error-flag)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;;; Blocks and exits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (defmacro block (name &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 "(block NAME BODY...): define a lexically-scoped block named NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 NAME may be any symbol. Code inside the BODY forms can call `return-from'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 to jump prematurely out of the block. This differs from `catch' and `throw'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 in two respects: First, the NAME is an unevaluated symbol rather than a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 quoted symbol or other form; and second, NAME is lexically rather than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 dynamically scoped: Only references to it within BODY will work. These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 references may appear inside macro expansions, but not inside functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 called from BODY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (if (cl-safe-expr-p (cons 'progn body)) (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (list 'cl-block-wrapper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (list* 'catch (list 'quote (intern (format "--cl-block-%s--" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (defvar cl-active-block-names nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (put 'cl-block-wrapper 'byte-compile 'cl-byte-compile-block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (defun cl-byte-compile-block (cl-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (if (fboundp 'byte-compile-form-do-effect) ; Check for optimizing compiler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (let* ((cl-entry (cons (nth 1 (nth 1 (nth 1 cl-form))) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (cl-active-block-names (cons cl-entry cl-active-block-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (cl-body (byte-compile-top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (cons 'progn (cddr (nth 1 cl-form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (if (cdr cl-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (byte-compile-form (list 'catch (nth 1 (nth 1 cl-form)) cl-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (byte-compile-form cl-body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (byte-compile-form (nth 1 cl-form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (put 'cl-block-throw 'byte-compile 'cl-byte-compile-throw)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (defun cl-byte-compile-throw (cl-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (let ((cl-found (assq (nth 1 (nth 1 cl-form)) cl-active-block-names)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (if cl-found (setcdr cl-found t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (byte-compile-normal-call (cons 'throw (cdr cl-form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (defmacro return (&optional res)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 "(return [RESULT]): return from the block named nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 This is equivalent to `(return-from nil RESULT)'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (list 'return-from nil res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (defmacro return-from (name &optional res)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 "(return-from NAME [RESULT]): return from the block named NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 This jump out to the innermost enclosing `(block NAME ...)' form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 returning RESULT from that form (or nil if RESULT is omitted).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 This is compatible with Common Lisp, but note that `defun' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 `defmacro' do not create implicit blocks as they do in Common Lisp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (let ((name2 (intern (format "--cl-block-%s--" name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (list 'cl-block-throw (list 'quote name2) res)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;;; The "loop" macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (defvar args) (defvar loop-accum-var) (defvar loop-accum-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (defvar loop-bindings) (defvar loop-body) (defvar loop-destr-temps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (defvar loop-finally) (defvar loop-finish-flag) (defvar loop-first-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defvar loop-initially) (defvar loop-map-form) (defvar loop-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (defvar loop-result) (defvar loop-result-explicit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (defmacro loop (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 "(loop CLAUSE...): The Common Lisp `loop' macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 Valid clauses are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 for VAR from/upfrom/downfrom NUM to/upto/downto/above/below NUM by NUM,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 for VAR in LIST by FUNC, for VAR on LIST by FUNC, for VAR = INIT then EXPR,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 for VAR across ARRAY, repeat NUM, with VAR = INIT, while COND, until COND,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 always COND, never COND, thereis COND, collect EXPR into VAR,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 append EXPR into VAR, nconc EXPR into VAR, sum EXPR into VAR,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 count EXPR into VAR, maximize EXPR into VAR, minimize EXPR into VAR,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 if COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...],
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 unless COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...],
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 do EXPRS..., initially EXPRS..., finally EXPRS..., return EXPR,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 finally return EXPR, named NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list args))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (list 'block nil (list* 'while t args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (let ((loop-name nil) (loop-bindings nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (loop-body nil) (loop-steps nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (loop-result nil) (loop-result-explicit nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (loop-result-var nil) (loop-finish-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (loop-accum-var nil) (loop-accum-vars nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (loop-initially nil) (loop-finally nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (loop-map-form nil) (loop-first-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (loop-destr-temps nil) (loop-symbol-macs nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (setq args (append args '(cl-end-loop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (while (not (eq (car args) 'cl-end-loop)) (cl-parse-loop-clause))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (if loop-finish-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (cl-push (list (list loop-finish-flag t)) loop-bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (if loop-first-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (progn (cl-push (list (list loop-first-flag t)) loop-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (cl-push (list 'setq loop-first-flag nil) loop-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (let* ((epilogue (nconc (nreverse loop-finally)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (list (or loop-result-explicit loop-result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (ands (cl-loop-build-ands (nreverse loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (while-body (nconc (cadr ands) (nreverse loop-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (body (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (nreverse loop-initially)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (list (if loop-map-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (list 'block '--cl-finish--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (subst
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (if (eq (car ands) t) while-body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (cons (list 'or (car ands)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 '(return-from --cl-finish--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 while-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 '--cl-map loop-map-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (list* 'while (car ands) while-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (if loop-finish-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (if (equal epilogue '(nil)) (list loop-result-var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (list (list 'if loop-finish-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (cons 'progn epilogue) loop-result-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 epilogue))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (if loop-result-var (cl-push (list loop-result-var) loop-bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (while loop-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (if (cdar loop-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (setq body (list (cl-loop-let (cl-pop loop-bindings) body t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (let ((lets nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (while (and loop-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (not (cdar loop-bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (cl-push (car (cl-pop loop-bindings)) lets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (setq body (list (cl-loop-let lets body nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (if loop-symbol-macs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (setq body (list (list* 'symbol-macrolet loop-symbol-macs body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (list* 'block loop-name body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (defun cl-parse-loop-clause () ; uses args, loop-*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (let ((word (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (hash-types '(hash-key hash-keys hash-value hash-values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (key-types '(key-code key-codes key-seq key-seqs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 key-binding key-bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ((null args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (error "Malformed `loop' macro"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ((eq word 'named)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (setq loop-name (cl-pop args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 ((eq word 'initially)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (if (memq (car args) '(do doing)) (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (or (consp (car args)) (error "Syntax error on `initially' clause"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (while (consp (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (cl-push (cl-pop args) loop-initially)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ((eq word 'finally)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (if (eq (car args) 'return)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (setq loop-result-explicit (or (cl-pop2 args) '(quote nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (if (memq (car args) '(do doing)) (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (or (consp (car args)) (error "Syntax error on `finally' clause"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (if (and (eq (caar args) 'return) (null loop-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (setq loop-result-explicit (or (nth 1 (cl-pop args)) '(quote nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (while (consp (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (cl-push (cl-pop args) loop-finally)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ((memq word '(for as))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (let ((loop-for-bindings nil) (loop-for-sets nil) (loop-for-steps nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (ands nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (let ((var (or (cl-pop args) (gensym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (setq word (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (if (eq word 'being) (setq word (cl-pop args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (if (memq word '(the each)) (setq word (cl-pop args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (if (memq word '(buffer buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (setq word 'in args (cons '(buffer-list) args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 ((memq word '(from downfrom upfrom to downto upto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 above below by))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (cl-push word args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (if (memq (car args) '(downto above))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (error "Must specify `from' value for downward loop"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (let* ((down (or (eq (car args) 'downfrom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (memq (caddr args) '(downto above))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (excl (or (memq (car args) '(above below))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (memq (caddr args) '(above below))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (start (and (memq (car args) '(from upfrom downfrom))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (end (and (memq (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 '(to upto downto above below))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (step (and (eq (car args) 'by) (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (end-var (and (not (cl-const-expr-p end)) (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (step-var (and (not (cl-const-expr-p step))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (gensym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (and step (numberp step) (<= step 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (error "Loop `by' value is not positive: %s" step))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (cl-push (list var (or start 0)) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (if end-var (cl-push (list end-var end) loop-for-bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (if step-var (cl-push (list step-var step)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 loop-for-bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (if end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (cl-push (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (if down (if excl '> '>=) (if excl '< '<=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 var (or end-var end)) loop-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (cl-push (list var (list (if down '- '+) var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (or step-var step 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 loop-for-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ((memq word '(in in-ref on))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (let* ((on (eq word 'on))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (temp (if (and on (symbolp var)) var (gensym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (cl-push (list temp (cl-pop args)) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (cl-push (list 'consp temp) loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (if (eq word 'in-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (cl-push (list var (list 'car temp)) loop-symbol-macs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (or (eq temp var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (cl-push (list var nil) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (cl-push (list var (if on temp (list 'car temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 loop-for-sets))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (cl-push (list temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if (eq (car args) 'by)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (let ((step (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (if (and (memq (car-safe step)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 '(quote function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 function*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (symbolp (nth 1 step)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (list (nth 1 step) temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (list 'funcall step temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (list 'cdr temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 loop-for-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ((eq word '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (let* ((start (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (then (if (eq (car args) 'then) (cl-pop2 args) start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (cl-push (list var nil) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (if (or ands (eq (car args) 'and))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (cl-push (list var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (list 'if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (or loop-first-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (setq loop-first-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 start var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 loop-for-sets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (cl-push (list var then) loop-for-steps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (cl-push (list var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (if (eq start then) start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (list 'if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (or loop-first-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (setq loop-first-flag (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 start then)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 loop-for-sets))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ((memq word '(across across-ref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (let ((temp-vec (gensym)) (temp-idx (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (cl-push (list temp-vec (cl-pop args)) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (cl-push (list temp-idx -1) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (cl-push (list '< (list 'setq temp-idx (list '1+ temp-idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (list 'length temp-vec)) loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (if (eq word 'across-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (cl-push (list var (list 'aref temp-vec temp-idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 loop-symbol-macs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (cl-push (list var nil) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (cl-push (list var (list 'aref temp-vec temp-idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 loop-for-sets))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ((memq word '(element elements))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (let ((ref (or (memq (car args) '(in-ref of-ref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (and (not (memq (car args) '(in of)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (error "Expected `of'"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (seq (cl-pop2 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (temp-seq (gensym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (temp-idx (if (eq (car args) 'using)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (if (and (= (length (cadr args)) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (eq (caadr args) 'index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (cadr (cl-pop2 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (error "Bad `using' clause"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (gensym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (cl-push (list temp-seq seq) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (cl-push (list temp-idx 0) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (if ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (let ((temp-len (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (cl-push (list temp-len (list 'length temp-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (cl-push (list var (list 'elt temp-seq temp-idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 loop-symbol-macs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (cl-push (list '< temp-idx temp-len) loop-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (cl-push (list var nil) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (cl-push (list 'and temp-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (list 'or (list 'consp temp-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (list '< temp-idx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (list 'length temp-seq))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (cl-push (list var (list 'if (list 'consp temp-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (list 'pop temp-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (list 'aref temp-seq temp-idx)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 loop-for-sets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (cl-push (list temp-idx (list '1+ temp-idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 loop-for-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ((memq word hash-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (or (memq (car args) '(in of)) (error "Expected `of'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (let* ((table (cl-pop2 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (other (if (eq (car args) 'using)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (if (and (= (length (cadr args)) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (memq (caadr args) hash-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (not (eq (caadr args) word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (cadr (cl-pop2 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (error "Bad `using' clause"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (gensym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (if (memq word '(hash-value hash-values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (setq var (prog1 other (setq other var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (setq loop-map-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (list 'maphash (list 'function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (list* 'lambda (list var other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 '--cl-map)) table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ((memq word '(symbol present-symbol external-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 symbols present-symbols external-symbols))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (let ((ob (and (memq (car args) '(in of)) (cl-pop2 args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (setq loop-map-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (list 'mapatoms (list 'function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (list* 'lambda (list var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 '--cl-map)) ob))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ((memq word '(overlay overlays extent extents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (let ((buf nil) (from nil) (to nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (while (memq (car args) '(in of from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (cond ((eq (car args) 'from) (setq from (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ((eq (car args) 'to) (setq to (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (t (setq buf (cl-pop2 args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (setq loop-map-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (list 'cl-map-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (list 'function (list 'lambda (list var (gensym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 '(progn . --cl-map) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 buf from to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 ((memq word '(interval intervals))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (let ((buf nil) (prop nil) (from nil) (to nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (var1 (gensym)) (var2 (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (while (memq (car args) '(in of property from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (cond ((eq (car args) 'from) (setq from (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ((eq (car args) 'to) (setq to (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ((eq (car args) 'property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (setq prop (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (t (setq buf (cl-pop2 args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (if (and (consp var) (symbolp (car var)) (symbolp (cdr var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (setq var1 (car var) var2 (cdr var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (cl-push (list var (list 'cons var1 var2)) loop-for-sets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (setq loop-map-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (list 'cl-map-intervals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (list 'function (list 'lambda (list var1 var2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 '(progn . --cl-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 buf prop from to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ((memq word key-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (or (memq (car args) '(in of)) (error "Expected `of'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (let ((map (cl-pop2 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (other (if (eq (car args) 'using)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (if (and (= (length (cadr args)) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (memq (caadr args) key-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (not (eq (caadr args) word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (cadr (cl-pop2 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (error "Bad `using' clause"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (gensym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (if (memq word '(key-binding key-bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (setq var (prog1 other (setq other var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (setq loop-map-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (list (if (memq word '(key-seq key-seqs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 'cl-map-keymap-recursively 'cl-map-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (list 'function (list* 'lambda (list var other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 '--cl-map)) map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ((memq word '(frame frames screen screens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (let ((temp (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (cl-push (list var (if (eq cl-emacs-type 'lucid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 '(selected-screen) '(selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (cl-push (list temp nil) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (cl-push (list 'prog1 (list 'not (list 'eq var temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (list 'or temp (list 'setq temp var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (cl-push (list var (list (if (eq cl-emacs-type 'lucid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 'next-screen 'next-frame) var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 loop-for-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 ((memq word '(window windows))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (let ((scr (and (memq (car args) '(in of)) (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (temp (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (cl-push (list var (if scr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (list (if (eq cl-emacs-type 'lucid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 'screen-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 'frame-selected-window) scr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 '(selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (cl-push (list temp nil) loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (cl-push (list 'prog1 (list 'not (list 'eq var temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (list 'or temp (list 'setq temp var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (cl-push (list var (list 'next-window var)) loop-for-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (let ((handler (and (symbolp word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (get word 'cl-loop-for-handler))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (funcall handler var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (error "Expected a `for' preposition, found %s" word)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (eq (car args) 'and))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (setq ands t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (if (and ands loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (cl-push (nreverse loop-for-bindings) loop-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (setq loop-bindings (nconc (mapcar 'list loop-for-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 loop-bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (if loop-for-sets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (cl-push (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (cl-loop-let (nreverse loop-for-sets) 'setq ands)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 t) loop-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (if loop-for-steps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (cl-push (cons (if ands 'psetq 'setq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (apply 'append (nreverse loop-for-steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 loop-steps))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 ((eq word 'repeat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (let ((temp (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (cl-push (list (list temp (cl-pop args))) loop-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (cl-push (list '>= (list 'setq temp (list '1- temp)) 0) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ((eq word 'collect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (let ((what (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (var (cl-loop-handle-accum nil 'nreverse)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (if (eq var loop-accum-var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (cl-push (list 'progn (list 'push what var) t) loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (cl-push (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (list 'setq var (list 'nconc var (list 'list what)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 t) loop-body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 ((memq word '(nconc nconcing append appending))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (let ((what (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (var (cl-loop-handle-accum nil 'nreverse)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (cl-push (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (if (eq var loop-accum-var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (list 'nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (list (if (memq word '(nconc nconcing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 'nreverse 'reverse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 what)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (list (if (memq word '(nconc nconcing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 'nconc 'append)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 var what))) t) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 ((memq word '(concat concating))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (let ((what (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (var (cl-loop-handle-accum "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (cl-push (list 'progn (list 'callf 'concat var what) t) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 ((memq word '(vconcat vconcating))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (let ((what (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (var (cl-loop-handle-accum [])))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (cl-push (list 'progn (list 'callf 'vconcat var what) t) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 ((memq word '(sum summing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (let ((what (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (var (cl-loop-handle-accum 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (cl-push (list 'progn (list 'incf var what) t) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ((memq word '(count counting))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (let ((what (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (var (cl-loop-handle-accum 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (cl-push (list 'progn (list 'if what (list 'incf var)) t) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ((memq word '(minimize minimizing maximize maximizing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (let* ((what (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (temp (if (cl-simple-expr-p what) what (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (var (cl-loop-handle-accum nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (func (intern (substring (symbol-name word) 0 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (set (list 'setq var (list 'if var (list func var temp) temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (cl-push (list 'progn (if (eq temp what) set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (list 'let (list (list temp what)) set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 t) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ((eq word 'with)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (let ((bindings nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (while (progn (cl-push (list (cl-pop args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (and (eq (car args) '=) (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (eq (car args) 'and))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (cl-push (nreverse bindings) loop-bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ((eq word 'while)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (cl-push (cl-pop args) loop-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 ((eq word 'until)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (cl-push (list 'not (cl-pop args)) loop-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 ((eq word 'always)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (or loop-finish-flag (setq loop-finish-flag (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (cl-push (list 'setq loop-finish-flag (cl-pop args)) loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (setq loop-result t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 ((eq word 'never)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (or loop-finish-flag (setq loop-finish-flag (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (cl-push (list 'setq loop-finish-flag (list 'not (cl-pop args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 loop-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (setq loop-result t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 ((eq word 'thereis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (or loop-finish-flag (setq loop-finish-flag (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (or loop-result-var (setq loop-result-var (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (cl-push (list 'setq loop-finish-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (list 'not (list 'setq loop-result-var (cl-pop args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 loop-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 ((memq word '(if when unless))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (let* ((cond (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (then (let ((loop-body nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (cl-parse-loop-clause)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (cl-loop-build-ands (nreverse loop-body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (else (let ((loop-body nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (if (eq (car args) 'else)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (progn (cl-pop args) (cl-parse-loop-clause)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (cl-loop-build-ands (nreverse loop-body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (simple (and (eq (car then) t) (eq (car else) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (if (eq (car args) 'end) (cl-pop args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (if (eq word 'unless) (setq then (prog1 else (setq else then))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (let ((form (cons (if simple (cons 'progn (nth 1 then)) (nth 2 then))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (if simple (nth 1 else) (list (nth 2 else))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (if (cl-expr-contains form 'it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (let ((temp (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (cl-push (list temp) loop-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (setq form (list* 'if (list 'setq temp cond)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (subst temp 'it form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (setq form (list* 'if cond form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (cl-push (if simple (list 'progn form t) form) loop-body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ((memq word '(do doing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (let ((body nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (or (consp (car args)) (error "Syntax error on `do' clause"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (while (consp (car args)) (cl-push (cl-pop args) body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (cl-push (cons 'progn (nreverse (cons t body))) loop-body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 ((eq word 'return)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (or loop-finish-flag (setq loop-finish-flag (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (or loop-result-var (setq loop-result-var (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (cl-push (list 'setq loop-result-var (cl-pop args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 loop-finish-flag nil) loop-body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (let ((handler (and (symbolp word) (get word 'cl-loop-handler))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (or handler (error "Expected a loop keyword, found %s" word))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (funcall handler))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (if (eq (car args) 'and)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (progn (cl-pop args) (cl-parse-loop-clause)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (defun cl-loop-let (specs body par) ; uses loop-*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (let ((p specs) (temps nil) (new nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (while (and p (or (symbolp (car-safe (car p))) (null (cadar p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (setq p (cdr p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (and par p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (setq par nil p specs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (while p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (or (cl-const-expr-p (cadar p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (let ((temp (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (cl-push (list temp (cadar p)) temps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (setcar (cdar p) temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (setq p (cdr p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (while specs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (if (and (consp (car specs)) (listp (caar specs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (let* ((spec (caar specs)) (nspecs nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (expr (cadr (cl-pop specs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (temp (cdr (or (assq spec loop-destr-temps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (car (cl-push (cons spec (or (last spec 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 loop-destr-temps))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (cl-push (list temp expr) new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (while (consp spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (cl-push (list (cl-pop spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (and expr (list (if spec 'pop 'car) temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 nspecs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (setq specs (nconc (nreverse nspecs) specs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (cl-push (cl-pop specs) new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (if (eq body 'setq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (let ((set (cons (if par 'psetq 'setq) (apply 'nconc (nreverse new)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (if temps (list 'let* (nreverse temps) set) set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (list* (if par 'let 'let*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (nconc (nreverse temps) (nreverse new)) body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (defun cl-loop-handle-accum (def &optional func) ; uses args, loop-*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (if (eq (car args) 'into)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (let ((var (cl-pop2 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (or (memq var loop-accum-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (progn (cl-push (list (list var def)) loop-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (cl-push var loop-accum-vars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (or loop-accum-var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (cl-push (list (list (setq loop-accum-var (gensym)) def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 loop-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (setq loop-result (if func (list func loop-accum-var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 loop-accum-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 loop-accum-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (defun cl-loop-build-ands (clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (let ((ands nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (body nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (while clauses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (if (and (eq (car-safe (car clauses)) 'progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (eq (car (last (car clauses))) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (if (cdr clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (setq clauses (cons (nconc (butlast (car clauses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (if (eq (car-safe (cadr clauses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 'progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (cdadr clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (list (cadr clauses))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (cddr clauses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (setq body (cdr (butlast (cl-pop clauses)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (cl-push (cl-pop clauses) ands)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (setq ands (or (nreverse ands) (list t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (list (if (cdr ands) (cons 'and ands) (car ands))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (let ((full (if body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (append ands (list (cons 'progn (append body '(t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ands)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (if (cdr full) (cons 'and full) (car full))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 ;;; Other iteration control structures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (defmacro do (steps endtest &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 "The Common Lisp `do' loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 Format is: (do ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (cl-expand-do-loop steps endtest body nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (defmacro do* (steps endtest &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 "The Common Lisp `do*' loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 Format is: (do* ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (cl-expand-do-loop steps endtest body t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (defun cl-expand-do-loop (steps endtest body star)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (list 'block nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (list* (if star 'let* 'let)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (mapcar (function (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (if (consp c) (list (car c) (nth 1 c)) c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 steps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (list* 'while (list 'not (car endtest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (append body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (let ((sets (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (and (consp c) (cdr (cdr c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (list (car c) (nth 2 c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 steps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (setq sets (delq nil sets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (and sets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (list (cons (if (or star (not (cdr sets)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 'setq 'psetq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (apply 'append sets)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (or (cdr endtest) '(nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (defmacro dolist (spec &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 "(dolist (VAR LIST [RESULT]) BODY...): loop over a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 Evaluate BODY with VAR bound to each `car' from LIST, in turn.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 Then evaluate RESULT to get return value, default nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (let ((temp (gensym "--dolist-temp--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (list 'block nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (list* 'let (list (list temp (nth 1 spec)) (car spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (list* 'while temp (list 'setq (car spec) (list 'car temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (append body (list (list 'setq temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (list 'cdr temp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (if (cdr (cdr spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (cons (list 'setq (car spec) nil) (cdr (cdr spec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 '(nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (defmacro dotimes (spec &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 "(dotimes (VAR COUNT [RESULT]) BODY...): loop a certain number of times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 Evaluate BODY with VAR bound to successive integers from 0, inclusive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 to COUNT, exclusive. Then evaluate RESULT to get return value, default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (let ((temp (gensym "--dotimes-temp--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (list 'block nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (list* 'let (list (list temp (nth 1 spec)) (list (car spec) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (list* 'while (list '< (car spec) temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (append body (list (list 'incf (car spec)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (or (cdr (cdr spec)) '(nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (defmacro do-symbols (spec &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 "(dosymbols (VAR [OBARRAY [RESULT]]) BODY...): loop over all symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 Evaluate BODY with VAR bound to each interned symbol, or to each symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 from OBARRAY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 ;; Apparently this doesn't have an implicit block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (list 'block nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (list 'let (list (car spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (list* 'mapatoms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (list 'function (list* 'lambda (list (car spec)) body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (and (cadr spec) (list (cadr spec))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (caddr spec))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (defmacro do-all-symbols (spec &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (list* 'do-symbols (list (car spec) nil (cadr spec)) body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;;; Assignments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (defmacro psetq (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 "(psetq SYM VAL SYM VAL ...): set SYMs to the values VALs in parallel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 This is like `setq', except that all VAL forms are evaluated (in order)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 before assigning any symbols SYM to the corresponding values."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (cons 'psetf args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;;; Binding control structures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (defmacro progv (symbols values &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 "(progv SYMBOLS VALUES BODY...): bind SYMBOLS to VALUES dynamically in BODY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 Each SYMBOL in the first list is bound to the corresponding VALUE in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 second list (or made unbound if VALUES is shorter than SYMBOLS); then the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 BODY forms are executed and their result is returned. This is much like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 a `let' form, except that the list of symbols can be computed at run-time."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (list 'let '((cl-progv-save nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (list 'unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (list* 'progn (list 'cl-progv-before symbols values) body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 '(cl-progv-after))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ;;; This should really have some way to shadow 'byte-compile properties, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (defmacro flet (bindings &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 "(flet ((FUNC ARGLIST BODY...) ...) FORM...): make temporary function defns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 This is an analogue of `let' that operates on the function cell of FUNC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 rather than its value cell. The FORMs are evaluated with the specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 function definitions in place, then the definitions are undone (the FUNCs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 go back to their previous definitions, or lack thereof)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (list* 'letf*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (lambda (x)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1230 (if (or (and (fboundp (car x))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1231 (eq (car-safe (symbol-function (car x))) 'macro))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1232 (cdr (assq (car x) cl-macro-environment)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1233 (error "Use `labels', not `flet', to rebind macro names"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (let ((func (list 'function*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (list 'lambda (cadr x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (list* 'block (car x) (cddr x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (if (and (cl-compiling-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (boundp 'byte-compile-function-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (cl-push (cons (car x) (eval func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 byte-compile-function-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (list (list 'symbol-function (list 'quote (car x))) func))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1245 (defmacro labels (bindings &rest body)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1246 "(labels ((FUNC ARGLIST BODY...) ...) FORM...): make temporary func bindings.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1247 This is like `flet', except the bindings are lexical instead of dynamic.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1248 Unlike `flet', this macro is fully complaint with the Common Lisp standard."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1249 (let ((vars nil) (sets nil) (cl-macro-environment cl-macro-environment))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1250 (while bindings
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1251 (let ((var (gensym)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1252 (cl-push var vars)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1253 (cl-push (list 'function* (cons 'lambda (cdar bindings))) sets)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1254 (cl-push var sets)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1255 (cl-push (list (car (cl-pop bindings)) 'lambda '(&rest cl-labels-args)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1256 (list 'list* '(quote funcall) (list 'quote var)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1257 'cl-labels-args))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1258 cl-macro-environment)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1259 (cl-macroexpand-all (list* 'lexical-let vars (cons (cons 'setq sets) body))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1260 cl-macro-environment)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ;; The following ought to have a better definition for use with newer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 ;; byte compilers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (defmacro macrolet (bindings &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 "(macrolet ((NAME ARGLIST BODY...) ...) FORM...): make temporary macro defns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 This is like `flet', but for macros instead of functions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (if (cdr bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (list 'macrolet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (list (car bindings)) (list* 'macrolet (cdr bindings) body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (if (null bindings) (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (let* ((name (caar bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (res (cl-transform-lambda (cdar bindings) name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (eval (car res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (cl-macroexpand-all (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (cons (list* name 'lambda (cdr res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 cl-macro-environment))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (defmacro symbol-macrolet (bindings &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 "(symbol-macrolet ((NAME EXPANSION) ...) FORM...): make symbol macro defns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 Within the body FORMs, references to the variable NAME will be replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (if (cdr bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (list 'symbol-macrolet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (list (car bindings)) (list* 'symbol-macrolet (cdr bindings) body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (if (null bindings) (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (cl-macroexpand-all (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (cons (list (symbol-name (caar bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (cadar bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 cl-macro-environment)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (defvar cl-closure-vars nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (defmacro lexical-let (bindings &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 "(lexical-let BINDINGS BODY...): like `let', but lexically scoped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 The main visible difference is that lambdas inside BODY will create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 lexical closures as in Common Lisp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (let* ((cl-closure-vars cl-closure-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (vars (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (or (consp x) (setq x (list x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (cl-push (gensym (format "--%s--" (car x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 cl-closure-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (list (car x) (cadr x) (car cl-closure-vars))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (ebody
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (cl-macroexpand-all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (nconc (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (list (symbol-name (car x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (list 'symbol-value (caddr x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 t))) vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (list '(defun . cl-defun-expander))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 cl-macro-environment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (if (not (get (car (last cl-closure-vars)) 'used))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (list 'let (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (list (caddr x) (cadr x)))) vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (sublis (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (cons (caddr x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (list 'quote (caddr x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ebody))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (list 'let (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (list (caddr x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (list 'make-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (format "--%s--" (car x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (apply 'append '(setf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (list (list 'symbol-value (caddr x)) (cadr x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 ebody))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (defmacro lexical-let* (bindings &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 "(lexical-let* BINDINGS BODY...): like `let*', but lexically scoped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 The main visible difference is that lambdas inside BODY will create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 lexical closures as in Common Lisp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (if (null bindings) (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (setq bindings (reverse bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (while bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (setq body (list (list* 'lexical-let (list (cl-pop bindings)) body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (car body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (defun cl-defun-expander (func &rest rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (list 'defalias (list 'quote func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (list 'function (cons 'lambda rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (list 'quote func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;;; Multiple values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (defmacro multiple-value-bind (vars form &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 "(multiple-value-bind (SYM SYM...) FORM BODY): collect multiple return values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 FORM must return a list; the BODY is then executed with the first N elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 of this list bound (`let'-style) to each of the symbols SYM in turn. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 is analogous to the Common Lisp `multiple-value-bind' macro, using lists to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 simulate true multiple return values. For compatibility, (values A B C) is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 a synonym for (list A B C)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (let ((temp (gensym)) (n -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (list* 'let* (cons (list temp form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (lambda (v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (list v (list 'nth (setq n (1+ n)) temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (defmacro multiple-value-setq (vars form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 "(multiple-value-setq (SYM SYM...) FORM): collect multiple return values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 FORM must return a list; the first N elements of this list are stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 each of the symbols SYM in turn. This is analogous to the Common Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 `multiple-value-setq' macro, using lists to simulate true multiple return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 values. For compatibility, (values A B C) is a synonym for (list A B C)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (cond ((null vars) (list 'progn form nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 ((null (cdr vars)) (list 'setq (car vars) (list 'car form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (let* ((temp (gensym)) (n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (list 'let (list (list temp form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (list 'prog1 (list 'setq (cl-pop vars) (list 'car temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (cons 'setq (apply 'nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (lambda (v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (list v (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 'nth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (setq n (1+ n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 vars)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 ;;; Declarations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (defmacro locally (&rest body) (cons 'progn body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (defmacro the (type form) form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (defvar cl-proclaim-history t) ; for future compilers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (defvar cl-declare-stack t) ; for future compilers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (defun cl-do-proclaim (spec hist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (and hist (listp cl-proclaim-history) (cl-push spec cl-proclaim-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (cond ((eq (car-safe spec) 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (if (boundp 'byte-compile-bound-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (setq byte-compile-bound-variables
96
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 70
diff changeset
1402 ;; todo: this should compute correct binding bits vs. 0
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 70
diff changeset
1403 (append (mapcar #'(lambda (v) (cons v 0))
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 70
diff changeset
1404 (cdr spec))
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 70
diff changeset
1405 byte-compile-bound-variables))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 ((eq (car-safe spec) 'inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (while (setq spec (cdr spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (or (memq (get (car spec) 'byte-optimizer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 '(nil byte-compile-inline-expand))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (error "%s already has a byte-optimizer, can't make it inline"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (car spec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (put (car spec) 'byte-optimizer 'byte-compile-inline-expand)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 ((eq (car-safe spec) 'notinline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (while (setq spec (cdr spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (if (eq (get (car spec) 'byte-optimizer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 'byte-compile-inline-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (put (car spec) 'byte-optimizer nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 ((eq (car-safe spec) 'optimize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (let ((speed (assq (nth 1 (assq 'speed (cdr spec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 '((0 nil) (1 t) (2 t) (3 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (safety (assq (nth 1 (assq 'safety (cdr spec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 '((0 t) (1 t) (2 t) (3 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (if speed (setq cl-optimize-speed (car speed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 byte-optimize (nth 1 speed)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (if safety (setq cl-optimize-safety (car safety)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 byte-compile-delete-errors (nth 1 safety)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 ((and (eq (car-safe spec) 'warn) (boundp 'byte-compile-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (if (eq byte-compile-warnings t)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1433 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (setq byte-compile-warnings byte-compile-default-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (while (setq spec (cdr spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (if (consp (car spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (if (eq (cadar spec) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (setq byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (delq (caar spec) byte-compile-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (setq byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (adjoin (caar spec) byte-compile-warnings)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 ;;; Process any proclamations made before cl-macs was loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (defvar cl-proclaims-deferred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (let ((p (reverse cl-proclaims-deferred)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (while p (cl-do-proclaim (cl-pop p) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (setq cl-proclaims-deferred nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (defmacro declare (&rest specs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (if (cl-compiling-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (while specs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (if (listp cl-declare-stack) (cl-push (car specs) cl-declare-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (cl-do-proclaim (cl-pop specs) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 ;;; Generalized variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (defmacro define-setf-method (func args &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 "(define-setf-method NAME ARGLIST BODY...): define a `setf' method.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 This method shows how to handle `setf's to places of the form (NAME ARGS...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 The argument forms ARGS are bound according to ARGLIST, as if NAME were
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 going to be expanded as a macro, then the BODY forms are executed and must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 return a list of five elements: a temporary-variables list, a value-forms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 list, a store-variables list (of length one), a store-form, and an access-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 form. See `defsetf' for a simpler way to define most setf-methods."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (append '(eval-when (compile load eval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (if (stringp (car body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (list (list 'put (list 'quote func) '(quote setf-documentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (cl-pop body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (list (cl-transform-function-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 func 'setf-method (cons args body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (defmacro defsetf (func arg1 &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 "(defsetf NAME FUNC): define a `setf' method.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 This macro is an easy-to-use substitute for `define-setf-method' that works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 well for simple place forms. In the simple `defsetf' form, `setf's of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 the form (setf (NAME ARGS...) VAL) are transformed to function or macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 calls of the form (FUNC ARGS... VAL). Example: (defsetf aref aset).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 Alternate form: (defsetf NAME ARGLIST (STORE) BODY...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 Here, the above `setf' call is expanded by binding the argument forms ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 according to ARGLIST, binding the value form VAL to STORE, then executing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 BODY, which must return a Lisp form that does the necessary `setf' operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 Actually, ARGLIST and STORE may be bound to temporary variables which are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 introduced automatically to preserve proper execution order of the arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 (if (listp arg1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (let* ((largs nil) (largsr nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (temps nil) (tempsr nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (restarg nil) (rest-temps nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (store-var (car (prog1 (car args) (setq args (cdr args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (store-temp (intern (format "--%s--temp--" store-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (lets1 nil) (lets2 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (docstr nil) (p arg1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (if (stringp (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (setq docstr (prog1 (car args) (setq args (cdr args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (while (and p (not (eq (car p) '&aux)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (if (eq (car p) '&rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (setq p (cdr p) restarg (car p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (or (memq (car p) '(&optional &key &allow-other-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (setq largs (cons (if (consp (car p)) (car (car p)) (car p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 temps (cons (intern (format "--%s--temp--" (car largs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 temps))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (setq p (cdr p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (setq largs (nreverse largs) temps (nreverse temps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (if restarg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (setq largsr (append largs (list restarg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 rest-temps (intern (format "--%s--temp--" restarg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 tempsr (append temps (list rest-temps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (setq largsr largs tempsr temps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (let ((p1 largs) (p2 temps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (while p1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (setq lets1 (cons (list (car p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (list 'gensym (format "--%s--" (car p1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 lets1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 lets2 (cons (list (car p1) (car p2)) lets2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 p1 (cdr p1) p2 (cdr p2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (if restarg (setq lets2 (cons (list restarg rest-temps) lets2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (append (list 'define-setf-method func arg1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (and docstr (list docstr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (list 'let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (nreverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (cons (list store-temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (list 'gensym (format "--%s--" store-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (if restarg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (list rest-temps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (list 'mapcar '(quote gensym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 restarg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 lets1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 lets1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (list 'list ; 'values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (cons (if restarg 'list* 'list) tempsr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (cons (if restarg 'list* 'list) largsr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (list 'list store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (cons 'let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (cons (nreverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (cons (list store-var store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 lets2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 (cons (if restarg 'list* 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (cons (list 'quote func) tempsr)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (list 'defsetf func '(&rest args) '(store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (let ((call (list 'cons (list 'quote arg1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 '(append args (list store)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (if (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (list 'list '(quote progn) call 'store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 call)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 ;;; Some standard place types from Common Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (defsetf aref aset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (defsetf car setcar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (defsetf cdr setcdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (defsetf elt (seq n) (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (list 'if (list 'listp seq) (list 'setcar (list 'nthcdr n seq) store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (list 'aset seq n store)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (defsetf get put)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (defsetf get* (x y &optional d) (store) (list 'put x y store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (defsetf gethash (x h &optional d) (store) (list 'cl-puthash x store h))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (defsetf nth (n x) (store) (list 'setcar (list 'nthcdr n x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (defsetf subseq (seq start &optional end) (new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (list 'progn (list 'replace seq new ':start1 start ':end1 end) new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (defsetf symbol-function fset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (defsetf symbol-plist setplist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (defsetf symbol-value set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 ;;; Various car/cdr aliases. Note that `cadr' is handled specially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (defsetf first setcar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (defsetf second (x) (store) (list 'setcar (list 'cdr x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (defsetf third (x) (store) (list 'setcar (list 'cddr x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (defsetf fourth (x) (store) (list 'setcar (list 'cdddr x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (defsetf fifth (x) (store) (list 'setcar (list 'nthcdr 4 x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (defsetf sixth (x) (store) (list 'setcar (list 'nthcdr 5 x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (defsetf seventh (x) (store) (list 'setcar (list 'nthcdr 6 x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (defsetf eighth (x) (store) (list 'setcar (list 'nthcdr 7 x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (defsetf ninth (x) (store) (list 'setcar (list 'nthcdr 8 x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (defsetf tenth (x) (store) (list 'setcar (list 'nthcdr 9 x) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (defsetf rest setcdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 ;;; Some more Emacs-related place types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (defsetf buffer-file-name set-visited-file-name t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (defsetf buffer-modified-p set-buffer-modified-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (defsetf buffer-name rename-buffer t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (defsetf buffer-string () (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (list 'progn '(erase-buffer) (list 'insert store)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (defsetf buffer-substring cl-set-buffer-substring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (defsetf current-buffer set-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (defsetf current-case-table set-case-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (defsetf current-column move-to-column t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (defsetf current-global-map use-global-map t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (defsetf current-input-mode () (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (list 'progn (list 'apply 'set-input-mode store) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (defsetf current-local-map use-local-map t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (defsetf current-window-configuration set-window-configuration t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (defsetf default-file-modes set-default-file-modes t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (defsetf default-value set-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (defsetf documentation-property put)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (defsetf extent-data set-extent-data) ; obsolete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (defsetf extent-face set-extent-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (defsetf extent-priority set-extent-priority)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1606 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (defsetf extent-property set-extent-property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (defsetf extent-end-position (ext) (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (list 'progn (list 'set-extent-endpoints (list 'extent-start-position ext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 store) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (defsetf extent-start-position (ext) (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (list 'progn (list 'set-extent-endpoints store
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (list 'extent-end-position ext)) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (defsetf face-background (f &optional s) (x) (list 'set-face-background f x s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (defsetf face-background-pixmap (f &optional s) (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (list 'set-face-background-pixmap f x s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (defsetf face-font (f &optional s) (x) (list 'set-face-font f x s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (defsetf face-foreground (f &optional s) (x) (list 'set-face-foreground f x s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (defsetf face-underline-p (f &optional s) (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (list 'set-face-underline-p f x s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (defsetf file-modes set-file-modes t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (defsetf frame-parameters modify-frame-parameters t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (defsetf frame-visible-p cl-set-frame-visible-p)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1624 (defsetf frame-properties (&optional f) (p)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1625 `(progn (set-frame-properties ,f ,p) ,p))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1626 (defsetf frame-property (f p &optional d) (v)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1627 `(progn (set-frame-property ,f ,v) ,p))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1628 (defsetf frame-width (&optional f) (v)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1629 `(progn (set-frame-width ,f ,v) ,v))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1630 (defsetf frame-height (&optional f) (v)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1631 `(progn (set-frame-height ,f ,v) ,v))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1632 (defsetf current-frame-configuration set-frame-configuration)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1633
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1634 ;; XEmacs: new stuff
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1635 ;; Consoles
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1636 (defsetf selected-console select-console t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1637 (defsetf selected-device select-device t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1638 (defsetf device-baud-rate (&optional d) (v)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1639 `(set-device-baud-rate ,d ,v))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1640 (defsetf specifier-instance (spec &optional dom def nof) (val)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1641 `(set-specifier ,spec ,val ,dom))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1642
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1643 ;; Annotations
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1644 (defsetf annotation-glyph set-annotation-glyph)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1645 (defsetf annotation-down-glyph set-annotation-down-glyph)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1646 (defsetf annotation-face set-annotation-face)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1647 (defsetf annotation-layout set-annotation-layout)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1648 (defsetf annotation-data set-annotation-data)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1649 (defsetf annotation-action set-annotation-action)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1650 (defsetf annotation-menu set-annotation-menu)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1651 ;; Widget
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1652 (defsetf widget-get widget-put t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1653 (defsetf widget-value widget-value-set t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1654
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1655 ;; Misc
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1656 (defsetf recent-keys-ring-size set-recent-keys-ring-size)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 134
diff changeset
1657
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (defsetf getenv setenv t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (defsetf get-register set-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (defsetf global-key-binding global-set-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (defsetf keymap-parent set-keymap-parent)
171
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 155
diff changeset
1662 (defsetf keymap-name set-keymap-name)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 155
diff changeset
1663 (defsetf keymap-prompt set-keymap-prompt)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 155
diff changeset
1664 (defsetf keymap-default-binding set-keymap-default-binding)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (defsetf local-key-binding local-set-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (defsetf mark set-mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (defsetf mark-marker set-mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (defsetf marker-position set-marker t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (defsetf match-data store-match-data t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (defsetf mouse-position (scr) (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (list 'set-mouse-position scr (list 'car store) (list 'cadr store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (list 'cddr store)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (defsetf overlay-get overlay-put)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (defsetf overlay-start (ov) (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (list 'progn (list 'move-overlay ov store (list 'overlay-end ov)) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (defsetf overlay-end (ov) (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (list 'progn (list 'move-overlay ov (list 'overlay-start ov) store) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (defsetf point goto-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (defsetf point-marker goto-char t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (defsetf point-max () (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (list 'progn (list 'narrow-to-region '(point-min) store) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (defsetf point-min () (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (list 'progn (list 'narrow-to-region store '(point-max)) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (defsetf process-buffer set-process-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (defsetf process-filter set-process-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (defsetf process-sentinel set-process-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (defsetf read-mouse-position (scr) (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (list 'set-mouse-position scr (list 'car store) (list 'cdr store)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (defsetf screen-height set-screen-height t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (defsetf screen-width set-screen-width t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (defsetf selected-window select-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (defsetf selected-screen select-screen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (defsetf selected-frame select-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (defsetf standard-case-table set-standard-case-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (defsetf syntax-table set-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 (defsetf visited-file-modtime set-visited-file-modtime t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 (defsetf window-buffer set-window-buffer t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (defsetf window-display-table set-window-display-table t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (defsetf window-dedicated-p set-window-dedicated-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 (defsetf window-height () (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 (list 'progn (list 'enlarge-window (list '- store '(window-height))) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 (defsetf window-hscroll set-window-hscroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (defsetf window-point set-window-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (defsetf window-start set-window-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 (defsetf window-width () (store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 (list 'progn (list 'enlarge-window (list '- store '(window-width)) t) store))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (defsetf x-get-cutbuffer x-store-cutbuffer t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (defsetf x-get-cut-buffer x-store-cut-buffer t) ; groan.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (defsetf x-get-secondary-selection x-own-secondary-selection t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (defsetf x-get-selection x-own-selection t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 ;;; More complex setf-methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 ;;; These should take &environment arguments, but since full arglists aren't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 ;;; available while compiling cl-macs, we fake it by referring to the global
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 ;;; variable cl-macro-environment directly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (define-setf-method apply (func arg1 &rest rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (or (and (memq (car-safe func) '(quote function function*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (symbolp (car-safe (cdr-safe func))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (error "First arg to apply in setf is not (function SYM): %s" func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (let* ((form (cons (nth 1 func) (cons arg1 rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (method (get-setf-method form cl-macro-environment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (list (car method) (nth 1 method) (nth 2 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (cl-setf-make-apply (nth 3 method) (cadr func) (car method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (cl-setf-make-apply (nth 4 method) (cadr func) (car method)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (defun cl-setf-make-apply (form func temps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 (if (eq (car form) 'progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 (list* 'progn (cl-setf-make-apply (cadr form) func temps) (cddr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 (or (equal (last form) (last temps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (error "%s is not suitable for use with setf-of-apply" func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (list* 'apply (list 'quote (car form)) (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (define-setf-method nthcdr (n place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 (let ((method (get-setf-method place cl-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (n-temp (gensym "--nthcdr-n--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (store-temp (gensym "--nthcdr-store--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (list (cons n-temp (car method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (cons n (nth 1 method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 (list store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (list 'let (list (list (car (nth 2 method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 (list 'cl-set-nthcdr n-temp (nth 4 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 store-temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (nth 3 method) store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (list 'nthcdr n-temp (nth 4 method)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (define-setf-method getf (place tag &optional def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (let ((method (get-setf-method place cl-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (tag-temp (gensym "--getf-tag--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (def-temp (gensym "--getf-def--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (store-temp (gensym "--getf-store--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 (list (append (car method) (list tag-temp def-temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 (append (nth 1 method) (list tag def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (list store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (list 'let (list (list (car (nth 2 method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (list 'cl-set-getf (nth 4 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 tag-temp store-temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (nth 3 method) store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (list 'getf (nth 4 method) tag-temp def-temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (define-setf-method substring (place from &optional to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (let ((method (get-setf-method place cl-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (from-temp (gensym "--substring-from--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 (to-temp (gensym "--substring-to--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (store-temp (gensym "--substring-store--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (list (append (car method) (list from-temp to-temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (append (nth 1 method) (list from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (list store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (list 'let (list (list (car (nth 2 method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (list 'cl-set-substring (nth 4 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 from-temp to-temp store-temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (nth 3 method) store-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (list 'substring (nth 4 method) from-temp to-temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1775 (define-setf-method values (&rest args)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1776 (let ((methods (mapcar #'(lambda (x)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1777 (get-setf-method x cl-macro-environment))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1778 args))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1779 (store-temp (gensym "--values-store--")))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1780 (list (apply 'append (mapcar 'first methods))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1781 (apply 'append (mapcar 'second methods))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1782 (list store-temp)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1783 (cons 'list
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1784 (mapcar #'(lambda (m)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1785 (cl-setf-do-store (cons (car (third m)) (fourth m))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1786 (list 'pop store-temp)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1787 methods))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1788 (cons 'list (mapcar 'fifth methods)))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 96
diff changeset
1789
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 ;;; Getting and optimizing setf-methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (defun get-setf-method (place &optional env)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 "Return a list of five values describing the setf-method for PLACE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 PLACE may be any Lisp form which can appear as the PLACE argument to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 a macro like `setf' or `incf'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (if (symbolp place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (let ((temp (gensym "--setf--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (list nil nil (list temp) (list 'setq place temp) place))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (or (and (symbolp (car place))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (let* ((func (car place))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (name (symbol-name func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (method (get func 'setf-method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (or (and method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 (let ((cl-macro-environment env))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (setq method (apply method (cdr place))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (if (and (consp method) (= (length method) 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (error "Setf-method for %s returns malformed method"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (and (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (string-match "\\`c[ad][ad][ad]?[ad]?r\\'" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (get-setf-method (compiler-macroexpand place)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (and (eq func 'edebug-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (get-setf-method (nth (1- (length place)) place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 env)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (if (eq place (setq place (macroexpand place env)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (if (and (symbolp (car place)) (fboundp (car place))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (symbolp (symbol-function (car place))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (get-setf-method (cons (symbol-function (car place))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (cdr place)) env)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (error "No setf-method known for %s" (car place)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (get-setf-method place env)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (defun cl-setf-do-modify (place opt-expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (let* ((method (get-setf-method place cl-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 (temps (car method)) (values (nth 1 method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (lets nil) (subs nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (optimize (and (not (eq opt-expr 'no-opt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 (or (and (not (eq opt-expr 'unsafe))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (cl-safe-expr-p opt-expr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (cl-setf-simple-store-p (car (nth 2 method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (nth 3 method)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (simple (and optimize (consp place) (cl-simple-exprs-p (cdr place)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (while values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (if (or simple (cl-const-expr-p (car values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (cl-push (cons (cl-pop temps) (cl-pop values)) subs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (cl-push (list (cl-pop temps) (cl-pop values)) lets)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 (list (nreverse lets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 (cons (car (nth 2 method)) (sublis subs (nth 3 method)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (sublis subs (nth 4 method)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (defun cl-setf-do-store (spec val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (let ((sym (car spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (form (cdr spec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (if (or (cl-const-expr-p val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (and (cl-simple-expr-p val) (eq (cl-expr-contains form sym) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (cl-setf-simple-store-p sym form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (subst val sym form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 (list 'let (list (list sym val)) form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (defun cl-setf-simple-store-p (sym form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (and (consp form) (eq (cl-expr-contains form sym) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (eq (nth (1- (length form)) form) sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (symbolp (car form)) (fboundp (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (not (eq (car-safe (symbol-function (car form))) 'macro))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 ;;; The standard modify macros.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (defmacro setf (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 "(setf PLACE VAL PLACE VAL ...): set each PLACE to the value of its VAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 This is a generalized version of `setq'; the PLACEs may be symbolic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 references such as (car x) or (aref x i), as well as plain symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 For example, (setf (cadar x) y) is equivalent to (setcar (cdar x) y).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 The return value is the last VAL in the list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (if (cdr (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (let ((sets nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (while args (cl-push (list 'setf (cl-pop args) (cl-pop args)) sets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (cons 'progn (nreverse sets)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (if (symbolp (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (and args (cons 'setq args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (let* ((method (cl-setf-do-modify (car args) (nth 1 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (store (cl-setf-do-store (nth 1 method) (nth 1 args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (if (car method) (list 'let* (car method) store) store)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (defmacro psetf (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 "(psetf PLACE VAL PLACE VAL ...): set PLACEs to the values VALs in parallel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 This is like `setf', except that all VAL forms are evaluated (in order)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 before assigning any PLACEs to the corresponding values."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 (let ((p args) (simple t) (vars nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 (while p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (if (or (not (symbolp (car p))) (cl-expr-depends-p (nth 1 p) vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (setq simple nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (if (memq (car p) vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (error "Destination duplicated in psetf: %s" (car p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (cl-push (cl-pop p) vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (or p (error "Odd number of arguments to psetf"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (cl-pop p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (if simple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 (list 'progn (cons 'setf args) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (setq args (reverse args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (let ((expr (list 'setf (cadr args) (car args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (while (setq args (cddr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 (setq expr (list 'setf (cadr args) (list 'prog1 (car args) expr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 (list 'progn expr nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (defun cl-do-pop (place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (if (cl-simple-expr-p place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (list 'prog1 (list 'car place) (list 'setf place (list 'cdr place)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (let* ((method (cl-setf-do-modify place t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (temp (gensym "--pop--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (list 'let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (append (car method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (list (list temp (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (list 'prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (list 'car temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (cl-setf-do-store (nth 1 method) (list 'cdr temp)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (defmacro remf (place tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 "(remf PLACE TAG): remove TAG from property list PLACE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 PLACE may be a symbol, or any generalized variable allowed by `setf'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 The form returns true if TAG was found and removed, nil otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (let* ((method (cl-setf-do-modify place t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (tag-temp (and (not (cl-const-expr-p tag)) (gensym "--remf-tag--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (val-temp (and (not (cl-simple-expr-p place))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (gensym "--remf-place--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (ttag (or tag-temp tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (tval (or val-temp (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (list 'let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (append (car method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (and val-temp (list (list val-temp (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (and tag-temp (list (list tag-temp tag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 (list 'if (list 'eq ttag (list 'car tval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (cl-setf-do-store (nth 1 method) (list 'cddr tval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (list 'cl-do-remf tval ttag)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (defmacro shiftf (place &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 "(shiftf PLACE PLACE... VAL): shift left among PLACEs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 Example: (shiftf A B C) sets A to B, B to C, and returns the old A.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 Each PLACE may be a symbol, or any generalized variable allowed by `setf'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 (if (not (memq nil (mapcar 'symbolp (butlast (cons place args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (list* 'prog1 place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (let ((sets nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (cl-push (list 'setq place (car args)) sets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (setq place (cl-pop args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (nreverse sets)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (let* ((places (reverse (cons place args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (form (cl-pop places)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (while places
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (let ((method (cl-setf-do-modify (cl-pop places) 'unsafe)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (setq form (list 'let* (car method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (list 'prog1 (nth 2 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (cl-setf-do-store (nth 1 method) form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (defmacro rotatef (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 "(rotatef PLACE...): rotate left among PLACEs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 Example: (rotatef A B C) sets A to B, B to C, and C to A. It returns nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 Each PLACE may be a symbol, or any generalized variable allowed by `setf'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 (if (not (memq nil (mapcar 'symbolp args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (and (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (let ((sets nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (first (car args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (while (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (setq sets (nconc sets (list (cl-pop args) (car args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (nconc (list 'psetf) sets (list (car args) first))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (let* ((places (reverse args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (temp (gensym "--rotatef--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (form temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (while (cdr places)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (let ((method (cl-setf-do-modify (cl-pop places) 'unsafe)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (setq form (list 'let* (car method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (list 'prog1 (nth 2 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (cl-setf-do-store (nth 1 method) form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (let ((method (cl-setf-do-modify (car places) 'unsafe)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (list 'let* (append (car method) (list (list temp (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (cl-setf-do-store (nth 1 method) form) nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (defmacro letf (bindings &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 "(letf ((PLACE VALUE) ...) BODY...): temporarily bind to PLACEs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 This is the analogue of `let', but with generalized variables (in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 sense of `setf') for the PLACEs. Each PLACE is set to the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 VALUE, then the BODY forms are executed. On exit, either normally or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 because of a `throw' or error, the PLACEs are set back to their original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 values. Note that this macro is *not* available in Common Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 the PLACE is not modified before executing BODY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (if (and (not (cdr bindings)) (cdar bindings) (symbolp (caar bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (list* 'let bindings body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (let ((lets nil) (sets nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (unsets nil) (rev (reverse bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (while rev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (let* ((place (if (symbolp (caar rev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (list 'symbol-value (list 'quote (caar rev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (caar rev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (value (cadar rev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (method (cl-setf-do-modify place 'no-opt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (save (gensym "--letf-save--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 (bound (and (memq (car place) '(symbol-value symbol-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (gensym "--letf-bound--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 (temp (and (not (cl-const-expr-p value)) (cdr bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 (gensym "--letf-val--"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (setq lets (nconc (car method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (if bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (list (list bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (list (if (eq (car place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 'symbol-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 'boundp 'fboundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (nth 1 (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (list save (list 'and bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (list (list save (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (and temp (list (list temp value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 lets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 body (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (list 'unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (cons 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 (if (cdr (car rev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (cons (cl-setf-do-store (nth 1 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (or temp value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (if bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (list 'if bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (cl-setf-do-store (nth 1 method) save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (list (if (eq (car place) 'symbol-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 'makunbound 'fmakunbound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (nth 1 (nth 2 method))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (cl-setf-do-store (nth 1 method) save))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 rev (cdr rev))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (list* 'let* lets body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (defmacro letf* (bindings &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 "(letf* ((PLACE VALUE) ...) BODY...): temporarily bind to PLACEs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 This is the analogue of `let*', but with generalized variables (in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 sense of `setf') for the PLACEs. Each PLACE is set to the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 VALUE, then the BODY forms are executed. On exit, either normally or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 because of a `throw' or error, the PLACEs are set back to their original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 values. Note that this macro is *not* available in Common Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 the PLACE is not modified before executing BODY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 (if (null bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 (setq bindings (reverse bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 (while bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 (setq body (list (list* 'letf (list (cl-pop bindings)) body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (car body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (defmacro callf (func place &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 "(callf FUNC PLACE ARGS...): set PLACE to (FUNC PLACE ARGS...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 FUNC should be an unquoted function name. PLACE may be a symbol,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 or any generalized variable allowed by `setf'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (let* ((method (cl-setf-do-modify place (cons 'list args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (rargs (cons (nth 2 method) args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (list 'let* (car method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (cl-setf-do-store (nth 1 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (if (symbolp func) (cons func rargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (list* 'funcall (list 'function func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 rargs))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (defmacro callf2 (func arg1 place &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 "(callf2 FUNC ARG1 PLACE ARGS...): set PLACE to (FUNC ARG1 PLACE ARGS...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 Like `callf', but PLACE is the second argument of FUNC, not the first."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (if (and (cl-safe-expr-p arg1) (cl-simple-expr-p place) (symbolp func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 (list 'setf place (list* func arg1 place args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (let* ((method (cl-setf-do-modify place (cons 'list args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (temp (and (not (cl-const-expr-p arg1)) (gensym "--arg1--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (rargs (list* (or temp arg1) (nth 2 method) args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (list 'let* (append (and temp (list (list temp arg1))) (car method))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (cl-setf-do-store (nth 1 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (if (symbolp func) (cons func rargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (list* 'funcall (list 'function func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 rargs)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (defmacro define-modify-macro (name arglist func &optional doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 "(define-modify-macro NAME ARGLIST FUNC): define a `setf'-like modify macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 If NAME is called, it combines its PLACE argument with the other arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 from ARGLIST using FUNC: (define-modify-macro incf (&optional (n 1)) +)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (if (memq '&key arglist) (error "&key not allowed in define-modify-macro"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (let ((place (gensym "--place--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (list 'defmacro* name (cons place arglist) doc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 (list* (if (memq '&rest arglist) 'list* 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 '(quote callf) (list 'quote func) place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (cl-arglist-args arglist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 ;;; Structures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (defmacro defstruct (struct &rest descs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 "(defstruct (NAME OPTIONS...) (SLOT SLOT-OPTS...)...): define a struct type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 This macro defines a new Lisp data type called NAME, which contains data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 stored in SLOTs. This defines a `make-NAME' constructor, a `copy-NAME'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (let* ((name (if (consp struct) (car struct) struct))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (opts (cdr-safe struct))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (slots nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (defaults nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (conc-name (concat (symbol-name name) "-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (constructor (intern (format "make-%s" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (constrs nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (copier (intern (format "copy-%s" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (predicate (intern (format "%s-p" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (print-func nil) (print-auto nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (safety (if (cl-compiling-file) cl-optimize-safety 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 (include nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (tag (intern (format "cl-struct-%s" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 (tag-symbol (intern (format "cl-struct-%s-tags" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (include-descs nil)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2100 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (include-tag-symbol nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (side-eff nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (named nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 (forms nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 pred-form pred-check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (if (stringp (car descs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (cl-push (list 'put (list 'quote name) '(quote structure-documentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (cl-pop descs)) forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (setq descs (cons '(cl-tag-slot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (mapcar (function (lambda (x) (if (consp x) x (list x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 descs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (while opts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (let ((opt (if (consp (car opts)) (caar opts) (car opts)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (args (cdr-safe (cl-pop opts))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (cond ((eq opt ':conc-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (if args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (setq conc-name (if (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (symbol-name (car args)) ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 ((eq opt ':constructor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (if (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (cl-push args constrs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (if args (setq constructor (car args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 ((eq opt ':copier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (if args (setq copier (car args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 ((eq opt ':predicate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (if args (setq predicate (car args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 ((eq opt ':include)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (setq include (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 include-descs (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (if (consp x) x (list x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (cdr args))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2134 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 include-tag-symbol (intern (format "cl-struct-%s-tags"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 include))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 ((eq opt ':print-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (setq print-func (car args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 ((eq opt ':type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (setq type (car args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 ((eq opt ':named)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (setq named t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 ((eq opt ':initial-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 (setq descs (nconc (make-list (car args) '(cl-skip-slot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 descs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (error "Slot option %s unrecognized" opt)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (if print-func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (setq print-func (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (list 'funcall (list 'function print-func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 'cl-x 'cl-s 'cl-n) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (or type (and include (not (get include 'cl-struct-print)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 (setq print-auto t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 print-func (and (or (not (or include type)) (null print-func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (list 'princ (format "#S(%s" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 'cl-s))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (if include
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (let ((inc-type (get include 'cl-struct-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (old-descs (get include 'cl-struct-slots)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (or inc-type (error "%s is not a struct name" include))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 (and type (not (eq (car inc-type) type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (error ":type disagrees with :include for %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (while include-descs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (setcar (memq (or (assq (caar include-descs) old-descs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (error "No slot %s in included struct %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 (caar include-descs) include))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 old-descs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (cl-pop include-descs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (setq descs (append old-descs (delq (assq 'cl-tag-slot descs) descs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 type (car inc-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 named (assq 'cl-tag-slot descs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (if (cadr inc-type) (setq tag name named t))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2174 (let ((incl include))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2175 (while incl
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2176 (cl-push (list 'pushnew (list 'quote tag)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2177 (intern (format "cl-struct-%s-tags" incl)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2178 forms)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2179 (setq incl (get incl 'cl-struct-include)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (if type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (or (memq type '(vector list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (error "Illegal :type specifier: %s" type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (if named (setq tag name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (setq type 'vector named 'true)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (or named (setq descs (delq (assq 'cl-tag-slot descs) descs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 (cl-push (list 'defvar tag-symbol) forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (setq pred-form (and named
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (let ((pos (- (length descs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (length (memq (assq 'cl-tag-slot descs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 descs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (if (eq type 'vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (list 'and '(vectorp cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (list '>= '(length cl-x) (length descs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (list 'memq (list 'aref 'cl-x pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 tag-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (if (= pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (list 'memq '(car-safe cl-x) tag-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (list 'and '(consp cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (list 'memq (list 'nth pos 'cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 tag-symbol))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 pred-check (and pred-form (> safety 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (if (and (eq (caadr pred-form) 'vectorp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (= safety 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (cons 'and (cdddr pred-form)) pred-form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (let ((pos 0) (descp descs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (while descp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (let* ((desc (cl-pop descp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (slot (car desc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (if (memq slot '(cl-tag-slot cl-skip-slot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (cl-push nil slots)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (cl-push (and (eq slot 'cl-tag-slot) (list 'quote tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 defaults))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (if (assq slot descp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (error "Duplicate slots named %s in %s" slot name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (let ((accessor (intern (format "%s%s" conc-name slot))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (cl-push slot slots)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (cl-push (nth 1 desc) defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (cl-push (list*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 'defsubst* accessor '(cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (and pred-check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (list (list 'or pred-check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (list 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (format "%s accessing a non-%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 accessor name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 'cl-x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (list (if (eq type 'vector) (list 'aref 'cl-x pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (if (= pos 0) '(car cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (list 'nth pos 'cl-x)))))) forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (cl-push (cons accessor t) side-eff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (cl-push (list 'define-setf-method accessor '(cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (if (cadr (memq ':read-only (cddr desc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (list 'error (format "%s is a read-only slot"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 accessor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (list 'cl-struct-setf-expander 'cl-x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (list 'quote name) (list 'quote accessor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (and pred-check (list 'quote pred-check))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (if print-auto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (nconc print-func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (list (list 'princ (format " %s" slot) 'cl-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (list 'prin1 (list accessor 'cl-x) 'cl-s)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (setq pos (1+ pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (setq slots (nreverse slots)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 defaults (nreverse defaults))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (and predicate pred-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (progn (cl-push (list 'defsubst* predicate '(cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (if (eq (car pred-form) 'and)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (append pred-form '(t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (list 'and pred-form t))) forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (cl-push (cons predicate 'error-free) side-eff)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 (and copier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (progn (cl-push (list 'defun copier '(x) '(copy-sequence x)) forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (cl-push (cons copier t) side-eff)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (if constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (cl-push (list constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (cons '&key (delq nil (copy-sequence slots))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 constrs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (while constrs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (let* ((name (caar constrs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (args (cadr (cl-pop constrs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (anames (cl-arglist-args args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (make (mapcar* (function (lambda (s d) (if (memq s anames) s d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 slots defaults)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (cl-push (list 'defsubst* name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (list* '&cl-defs (list 'quote (cons nil descs)) args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 (cons type make)) forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (if (cl-safe-expr-p (cons 'progn (mapcar 'second descs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (cl-push (cons name t) side-eff))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (if print-auto (nconc print-func (list '(princ ")" cl-s) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (if print-func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (cl-push (list 'push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (list 'function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (list 'lambda '(cl-x cl-s cl-n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (list 'and pred-form print-func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 'custom-print-functions) forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (cl-push (list 'setq tag-symbol (list 'list (list 'quote tag))) forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 (cl-push (list* 'eval-when '(compile load eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (list 'put (list 'quote name) '(quote cl-struct-slots)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 (list 'quote descs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (list 'put (list 'quote name) '(quote cl-struct-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (list 'quote (list type (eq named t))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2286 (list 'put (list 'quote name) '(quote cl-struct-include)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2287 (list 'quote include))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (list 'put (list 'quote name) '(quote cl-struct-print)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 print-auto)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (list 'put (list 'quote (car x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 '(quote side-effect-free)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (list 'quote (cdr x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 side-eff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 (cons 'progn (nreverse (cons (list 'quote name) forms)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 (defun cl-struct-setf-expander (x name accessor pred-form pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (let* ((temp (gensym "--x--")) (store (gensym "--store--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (list (list temp) (list x) (list store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (append '(progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (and pred-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (list (list 'or (subst temp 'cl-x pred-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (list 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 "%s storing a non-%s" accessor name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (list (if (eq (car (get name 'cl-struct-type)) 'vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (list 'aset temp pos store)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (list 'setcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (if (<= pos 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (let ((xx temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (while (>= (setq pos (1- pos)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (setq xx (list 'cdr xx)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 xx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (list 'nthcdr pos temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 store))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (list accessor temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 ;;; Types and assertions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (defmacro deftype (name args &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 "(deftype NAME ARGLIST BODY...): define NAME as a new data type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 The type name can then be used in `typecase', `check-type', etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (list 'eval-when '(compile load eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (cl-transform-function-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 name 'cl-deftype-handler (cons (list* '&cl-defs ''('*) args) body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (defun cl-make-type-test (val type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (if (symbolp type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (cond ((get type 'cl-deftype-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 (cl-make-type-test val (funcall (get type 'cl-deftype-handler))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 ((memq type '(nil t)) type)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 171
diff changeset
2335 ((eq type 'string-char) (list 'characterp val))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 ((eq type 'null) (list 'null val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 ((eq type 'float) (list 'floatp-safe val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 ((eq type 'real) (list 'numberp val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 ((eq type 'fixnum) (list 'integerp val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (let* ((name (symbol-name type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (namep (intern (concat name "p"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (if (fboundp namep) (list namep val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 (list (intern (concat name "-p")) val)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 (cond ((get (car type) 'cl-deftype-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 (cl-make-type-test val (apply (get (car type) 'cl-deftype-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (cdr type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 ((memq (car-safe type) '(integer float real number))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (delq t (list 'and (cl-make-type-test val (car type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (if (memq (cadr type) '(* nil)) t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (if (consp (cadr type)) (list '> val (caadr type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (list '>= val (cadr type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (if (memq (caddr type) '(* nil)) t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (if (consp (caddr type)) (list '< val (caaddr type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (list '<= val (caddr type)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 ((memq (car-safe type) '(and or not))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (cons (car type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (mapcar (function (lambda (x) (cl-make-type-test val x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (cdr type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 ((memq (car-safe type) '(member member*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (list 'and (list 'member* val (list 'quote (cdr type))) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 ((eq (car-safe type) 'satisfies) (list (cadr type) val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 (t (error "Bad type spec: %s" type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (defun typep (val type) ; See compiler macro below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 "Check that OBJECT is of type TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 TYPE is a Common Lisp-style type specifier."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (eval (cl-make-type-test 'val type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 (defmacro check-type (form type &optional string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 "Verify that FORM is of type TYPE; signal an error if not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 STRING is an optional description of the desired type."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (and (or (not (cl-compiling-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (< cl-optimize-speed 3) (= cl-optimize-safety 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (let* ((temp (if (cl-simple-expr-p form 3) form (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (body (list 'or (cl-make-type-test temp type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (list 'signal '(quote wrong-type-argument)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 (list 'list (or string (list 'quote type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 temp (list 'quote form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 (if (eq temp form) (list 'progn body nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (list 'let (list (list temp form)) body nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (defmacro assert (form &optional show-args string &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 "Verify that FORM returns non-nil; signal an error if not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 Second arg SHOW-ARGS means to include arguments of FORM in message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 Other args STRING and ARGS... are arguments to be passed to `error'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 They are not evaluated unless the assertion fails. If STRING is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 omitted, a default message listing FORM itself is used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (and (or (not (cl-compiling-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (< cl-optimize-speed 3) (= cl-optimize-safety 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (let ((sargs (and show-args (delq nil (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (and (not (cl-const-expr-p x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 x))) (cdr form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (list 'or form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (if string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (list* 'error string (append sargs args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (list 'signal '(quote cl-assertion-failed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 (list* 'list (list 'quote form) sargs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (defmacro ignore-errors (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 "Execute FORMS; if an error occurs, return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 Otherwise, return result of last FORM."
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2407 (list 'condition-case nil (cons 'progn body) '(error nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 ;;; Some predicates for analyzing Lisp forms. These are used by various
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 ;;; macro expanders to optimize the results in certain common cases.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (defconst cl-simple-funcs '(car cdr nth aref elt if and or + - 1+ 1- min max
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 car-safe cdr-safe progn prog1 prog2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 (defconst cl-safe-funcs '(* / % length memq list vector vectorp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 < > <= >= = error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 ;;; Check if no side effects, and executes quickly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (defun cl-simple-expr-p (x &optional size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (or size (setq size 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (if (and (consp x) (not (memq (car x) '(quote function function*))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 (and (symbolp (car x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (or (memq (car x) cl-simple-funcs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (get (car x) 'side-effect-free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (setq size (1- size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 (while (and (setq x (cdr x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (setq size (cl-simple-expr-p (car x) size))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (and (null x) (>= size 0) size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (and (> size 0) (1- size))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (defun cl-simple-exprs-p (xs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (while (and xs (cl-simple-expr-p (car xs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (setq xs (cdr xs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (not xs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 ;;; Check if no side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (defun cl-safe-expr-p (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (or (not (and (consp x) (not (memq (car x) '(quote function function*)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 (and (symbolp (car x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (or (memq (car x) cl-simple-funcs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (memq (car x) cl-safe-funcs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 (get (car x) 'side-effect-free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 (while (and (setq x (cdr x)) (cl-safe-expr-p (car x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (null x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 ;;; Check if constant (i.e., no side effects or dependencies).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (defun cl-const-expr-p (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (cond ((consp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 (or (eq (car x) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (and (memq (car x) '(function function*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (or (symbolp (nth 1 x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (and (eq (car-safe (nth 1 x)) 'lambda) 'func)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 ((symbolp x) (and (memq x '(nil t)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (defun cl-const-exprs-p (xs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 (while (and xs (cl-const-expr-p (car xs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (setq xs (cdr xs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 (not xs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 (defun cl-const-expr-val (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (and (eq (cl-const-expr-p x) t) (if (consp x) (nth 1 x) x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (defun cl-expr-access-order (x v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 (if (cl-const-expr-p x) v
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (if (consp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (while (setq x (cdr x)) (setq v (cl-expr-access-order (car x) v)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (if (eq x (car v)) (cdr v) '(t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 ;;; Count number of times X refers to Y. Return NIL for 0 times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (defun cl-expr-contains (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (cond ((equal y x) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 ((and (consp x) (not (memq (car-safe x) '(quote function function*))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (let ((sum 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (while x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 (setq sum (+ sum (or (cl-expr-contains (cl-pop x) y) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (and (> sum 0) sum)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 (defun cl-expr-contains-any (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 (while (and y (not (cl-expr-contains x (car y)))) (cl-pop y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 ;;; Check whether X may depend on any of the symbols in Y.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (defun cl-expr-depends-p (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (and (not (cl-const-expr-p x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (or (not (cl-safe-expr-p x)) (cl-expr-contains-any x y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 ;;; Compiler macros.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 (defmacro define-compiler-macro (func args &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 "(define-compiler-macro FUNC ARGLIST BODY...): Define a compiler-only macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 This is like `defmacro', but macro expansion occurs only if the call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 FUNC is compiled (i.e., not interpreted). Compiler macros should be used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 for optimizing the way calls to FUNC are compiled; the form returned by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 BODY should do the same thing as a call to the normal function called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 FUNC, though possibly more efficiently. Note that, like regular macros,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 compiler macros are expanded repeatedly until no further expansions are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 possible. Unlike regular macros, BODY can decide to \"punt\" and leave the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 original function call alone by declaring an initial `&whole foo' parameter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 and then returning foo."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (let ((p (if (listp args) args (list '&rest args))) (res nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (while (consp p) (cl-push (cl-pop p) res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (setq args (nreverse res)) (setcdr res (and p (list '&rest p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (list 'eval-when '(compile load eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (cl-transform-function-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 func 'cl-compiler-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (cons (if (memq '&whole args) (delq '&whole args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (cons '--cl-whole-arg-- args)) body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 (list 'or (list 'get (list 'quote func) '(quote byte-compile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (list 'put (list 'quote func) '(quote byte-compile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 '(quote cl-byte-compile-compiler-macro)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (defun compiler-macroexpand (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (let ((func (car-safe form)) (handler nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 (while (and (symbolp func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (not (setq handler (get func 'cl-compiler-macro)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (fboundp func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 (or (not (eq (car-safe (symbol-function func)) 'autoload))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (load (nth 1 (symbol-function func)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (setq func (symbol-function func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (and handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 (not (eq form (setq form (apply handler form (cdr form))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (defun cl-byte-compile-compiler-macro (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 (if (eq form (setq form (compiler-macroexpand form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (byte-compile-normal-call form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 (byte-compile-form form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 (defmacro defsubst* (name args &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 "(defsubst* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 Like `defun', except the function is automatically declared `inline',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 ARGLIST allows full Common Lisp conventions, and BODY is implicitly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 surrounded by (block NAME ...)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (let* ((argns (cl-arglist-args args)) (p argns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 (pbody (cons 'progn body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 (unsafe (not (cl-safe-expr-p pbody))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (while (and p (eq (cl-expr-contains args (car p)) 1)) (cl-pop p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (if p nil ; give up if defaults refer to earlier args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (list 'define-compiler-macro name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 (list* '&whole 'cl-whole '&cl-quote args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (list* 'cl-defsubst-expand (list 'quote argns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 (list 'quote (list* 'block name body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 (not (or unsafe (cl-expr-access-order pbody argns)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 (and (memq '&key args) 'cl-whole) unsafe argns)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 (list* 'defun* name args body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 (defun cl-defsubst-expand (argns body simple whole unsafe &rest argvs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (if (and whole (not (cl-safe-expr-p (cons 'progn argvs)))) whole
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 (if (cl-simple-exprs-p argvs) (setq simple t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (let ((lets (delq nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (mapcar* (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (lambda (argn argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (if (or simple (cl-const-expr-p argv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (progn (setq body (subst argv argn body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 (and unsafe (list argn argv)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (list argn argv))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 argns argvs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (if lets (list 'let lets body) body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 ;;; Compile-time optimizations for some functions defined in this package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 ;;; Note that cl.el arranges to force cl-macs to be loaded at compile-time,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 ;;; mainly to make sure these macros will be present.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (put 'eql 'byte-compile nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (define-compiler-macro eql (&whole form a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (cond ((eq (cl-const-expr-p a) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (let ((val (cl-const-expr-val a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (if (and (numberp val) (not (integerp val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (list 'equal a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (list 'eq a b))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 ((eq (cl-const-expr-p b) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 (let ((val (cl-const-expr-val b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (if (and (numberp val) (not (integerp val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (list 'equal a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (list 'eq a b))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 ((cl-simple-expr-p a 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (list 'if (list 'numberp a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (list 'equal a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (list 'eq a b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 ((and (cl-safe-expr-p a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (cl-simple-expr-p b 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (list 'if (list 'numberp b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (list 'equal a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (list 'eq a b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 (t form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (define-compiler-macro member* (&whole form a list &rest keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (let ((test (and (= (length keys) 2) (eq (car keys) ':test)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (cl-const-expr-val (nth 1 keys)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (cond ((eq test 'eq) (list 'memq a list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 ((eq test 'equal) (list 'member a list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 ((or (null keys) (eq test 'eql))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (if (eq (cl-const-expr-p a) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (list (if (floatp-safe (cl-const-expr-val a)) 'member 'memq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 a list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (if (eq (cl-const-expr-p list) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (let ((p (cl-const-expr-val list)) (mb nil) (mq nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (if (not (cdr p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (and p (list 'eql a (list 'quote (car p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (while p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (if (floatp-safe (car p)) (setq mb t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (or (integerp (car p)) (symbolp (car p)) (setq mq t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (setq p (cdr p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (if (not mb) (list 'memq a list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (if (not mq) (list 'member a list) form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (t form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (define-compiler-macro assoc* (&whole form a list &rest keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (let ((test (and (= (length keys) 2) (eq (car keys) ':test)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (cl-const-expr-val (nth 1 keys)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (cond ((eq test 'eq) (list 'assq a list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 ((eq test 'equal) (list 'assoc a list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 ((and (eq (cl-const-expr-p a) t) (or (null keys) (eq test 'eql)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 (if (floatp-safe (cl-const-expr-val a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (list 'assoc a list) (list 'assq a list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (t form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (define-compiler-macro adjoin (&whole form a list &rest keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (if (and (cl-simple-expr-p a) (cl-simple-expr-p list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (not (memq ':key keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (list 'if (list* 'member* a list keys) list (list 'cons a list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 (define-compiler-macro list* (arg &rest others)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (let* ((args (reverse (cons arg others)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (form (car args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (while (setq args (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 (setq form (list 'cons (car args) form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 (define-compiler-macro get* (sym prop &optional def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (if def
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 (list 'getf (list 'symbol-plist sym) prop def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (list 'get sym prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (define-compiler-macro typep (&whole form val type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 (if (cl-const-expr-p type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (let ((res (cl-make-type-test val (cl-const-expr-val type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 (if (or (memq (cl-expr-contains res val) '(nil 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (cl-simple-expr-p val)) res
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (let ((temp (gensym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (list 'let (list (list temp val)) (subst temp val res)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (lambda (y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (put (car y) 'side-effect-free t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (put (car y) 'byte-compile 'cl-byte-compile-compiler-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (put (car y) 'cl-compiler-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (list 'lambda '(w x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (if (symbolp (cadr y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (list 'list (list 'quote (cadr y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (list 'list (list 'quote (caddr y)) 'x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (cons 'list (cdr y)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 '((first 'car x) (second 'cadr x) (third 'caddr x) (fourth 'cadddr x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (fifth 'nth 4 x) (sixth 'nth 5 x) (seventh 'nth 6 x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (eighth 'nth 7 x) (ninth 'nth 8 x) (tenth 'nth 9 x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (rest 'cdr x) (endp 'null x) (plusp '> x 0) (minusp '< x 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (caar car car) (cadr car cdr) (cdar cdr car) (cddr cdr cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (caaar car caar) (caadr car cadr) (cadar car cdar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (caddr car cddr) (cdaar cdr caar) (cdadr cdr cadr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (cddar cdr cdar) (cdddr cdr cddr) (caaaar car caaar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (caaadr car caadr) (caadar car cadar) (caaddr car caddr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (cadaar car cdaar) (cadadr car cdadr) (caddar car cddar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (cadddr car cdddr) (cdaaar cdr caaar) (cdaadr cdr caadr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (cdadar cdr cadar) (cdaddr cdr caddr) (cddaar cdr cdaar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (cddadr cdr cdadr) (cdddar cdr cddar) (cddddr cdr cdddr) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 ;;; Things that are inline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 (proclaim '(inline floatp-safe acons map concatenate notany notevery
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2683 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 cl-set-elt revappend nreconc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 ;;; Things that are side-effect-free.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (mapcar (function (lambda (x) (put x 'side-effect-free t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 '(oddp evenp abs expt signum last butlast ldiff pairlis gcd lcm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 isqrt floor* ceiling* truncate* round* mod* rem* subseq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 list-length get* getf gethash hash-table-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 ;;; Things that are side-effect-and-error-free.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 (mapcar (function (lambda (x) (put x 'side-effect-free 'error-free)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 '(eql floatp-safe list* subst acons equalp random-state-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 copy-tree sublis hash-table-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 (run-hooks 'cl-macs-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 ;;; cl-macs.el ends here