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