Mercurial > emacs
annotate lisp/emacs-lisp/cl-extra.el @ 28600:f3497be4e865
*** empty log message ***
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sat, 15 Apr 2000 11:33:45 +0000 |
parents | 69dea80bbb87 |
children | 0569ba69aa2b |
rev | line source |
---|---|
16057
a74507d555ba
Turn on byte-compile-dynamic.
Richard M. Stallman <rms@gnu.org>
parents:
15029
diff
changeset
|
1 ;;; cl-extra.el --- Common Lisp features, part 2 -*-byte-compile-dynamic: t;-*- |
4355 | 2 |
3 ;; Copyright (C) 1993 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Dave Gillespie <daveg@synaptics.com> | |
6 ;; Keywords: extensions | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12244 | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
4355 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
4355 | 24 |
7942 | 25 ;;; Commentary: |
4355 | 26 |
27 ;; These are extensions to Emacs Lisp that provide a degree of | |
28 ;; Common Lisp compatibility, beyond what is already built-in | |
29 ;; in Emacs Lisp. | |
30 ;; | |
31 ;; This package was written by Dave Gillespie; it is a complete | |
32 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
33 ;; | |
34 ;; Bug reports, comments, and suggestions are welcome! | |
35 | |
36 ;; This file contains portions of the Common Lisp extensions | |
37 ;; package which are autoloaded since they are relatively obscure. | |
38 | |
7942 | 39 ;;; Code: |
4355 | 40 |
41 (or (memq 'cl-19 features) | |
42 (error "Tried to load `cl-extra' before `cl'!")) | |
43 | |
44 | |
45 ;;; We define these here so that this file can compile without having | |
46 ;;; loaded the cl.el file already. | |
47 | |
48 (defmacro cl-push (x place) (list 'setq place (list 'cons x place))) | |
49 (defmacro cl-pop (place) | |
50 (list 'car (list 'prog1 place (list 'setq place (list 'cdr place))))) | |
51 | |
52 ;;; Type coercion. | |
53 | |
54 (defun coerce (x type) | |
55 "Coerce OBJECT to type TYPE. | |
56 TYPE is a Common Lisp type specifier." | |
57 (cond ((eq type 'list) (if (listp x) x (append x nil))) | |
58 ((eq type 'vector) (if (vectorp x) x (vconcat x))) | |
59 ((eq type 'string) (if (stringp x) x (concat x))) | |
60 ((eq type 'array) (if (arrayp x) x (vconcat x))) | |
61 ((and (eq type 'character) (stringp x) (= (length x) 1)) (aref x 0)) | |
62 ((and (eq type 'character) (symbolp x)) (coerce (symbol-name x) type)) | |
63 ((eq type 'float) (float x)) | |
64 ((typep x type) x) | |
65 (t (error "Can't coerce %s to type %s" x type)))) | |
66 | |
67 | |
68 ;;; Predicates. | |
69 | |
70 (defun equalp (x y) | |
71 "T if two Lisp objects have similar structures and contents. | |
72 This is like `equal', except that it accepts numerically equal | |
73 numbers of different types (float vs. integer), and also compares | |
74 strings case-insensitively." | |
75 (cond ((eq x y) t) | |
76 ((stringp x) | |
77 (and (stringp y) (= (length x) (length y)) | |
14794
c3a2cabb73ef
(equalp): Use string-equal on strings.
Erik Naggum <erik@naggum.no>
parents:
14762
diff
changeset
|
78 (or (string-equal x y) |
c3a2cabb73ef
(equalp): Use string-equal on strings.
Erik Naggum <erik@naggum.no>
parents:
14762
diff
changeset
|
79 (string-equal (downcase x) (downcase y))))) ; lazy but simple! |
4355 | 80 ((numberp x) |
81 (and (numberp y) (= x y))) | |
82 ((consp x) | |
14762
624d5547a6d6
(equalp): Correctly compare last elt of two lists.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
83 (while (and (consp x) (consp y) (equalp (car x) (car y))) |
624d5547a6d6
(equalp): Correctly compare last elt of two lists.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
84 (setq x (cdr x) y (cdr y))) |
4355 | 85 (and (not (consp x)) (equalp x y))) |
86 ((vectorp x) | |
87 (and (vectorp y) (= (length x) (length y)) | |
88 (let ((i (length x))) | |
89 (while (and (>= (setq i (1- i)) 0) | |
90 (equalp (aref x i) (aref y i)))) | |
91 (< i 0)))) | |
92 (t (equal x y)))) | |
93 | |
94 | |
95 ;;; Control structures. | |
96 | |
97 (defun cl-mapcar-many (cl-func cl-seqs) | |
98 (if (cdr (cdr cl-seqs)) | |
99 (let* ((cl-res nil) | |
100 (cl-n (apply 'min (mapcar 'length cl-seqs))) | |
101 (cl-i 0) | |
102 (cl-args (copy-sequence cl-seqs)) | |
103 cl-p1 cl-p2) | |
104 (setq cl-seqs (copy-sequence cl-seqs)) | |
105 (while (< cl-i cl-n) | |
106 (setq cl-p1 cl-seqs cl-p2 cl-args) | |
107 (while cl-p1 | |
108 (setcar cl-p2 | |
109 (if (consp (car cl-p1)) | |
110 (prog1 (car (car cl-p1)) | |
111 (setcar cl-p1 (cdr (car cl-p1)))) | |
112 (aref (car cl-p1) cl-i))) | |
113 (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2))) | |
114 (cl-push (apply cl-func cl-args) cl-res) | |
115 (setq cl-i (1+ cl-i))) | |
116 (nreverse cl-res)) | |
117 (let ((cl-res nil) | |
118 (cl-x (car cl-seqs)) | |
119 (cl-y (nth 1 cl-seqs))) | |
120 (let ((cl-n (min (length cl-x) (length cl-y))) | |
121 (cl-i -1)) | |
122 (while (< (setq cl-i (1+ cl-i)) cl-n) | |
123 (cl-push (funcall cl-func | |
124 (if (consp cl-x) (cl-pop cl-x) (aref cl-x cl-i)) | |
125 (if (consp cl-y) (cl-pop cl-y) (aref cl-y cl-i))) | |
126 cl-res))) | |
127 (nreverse cl-res)))) | |
128 | |
129 (defun map (cl-type cl-func cl-seq &rest cl-rest) | |
130 "Map a function across one or more sequences, returning a sequence. | |
131 TYPE is the sequence type to return, FUNC is the function, and SEQS | |
132 are the argument sequences." | |
133 (let ((cl-res (apply 'mapcar* cl-func cl-seq cl-rest))) | |
134 (and cl-type (coerce cl-res cl-type)))) | |
135 | |
136 (defun maplist (cl-func cl-list &rest cl-rest) | |
137 "Map FUNC to each sublist of LIST or LISTS. | |
138 Like `mapcar', except applies to lists and their cdr's rather than to | |
139 the elements themselves." | |
140 (if cl-rest | |
141 (let ((cl-res nil) | |
142 (cl-args (cons cl-list (copy-sequence cl-rest))) | |
143 cl-p) | |
144 (while (not (memq nil cl-args)) | |
145 (cl-push (apply cl-func cl-args) cl-res) | |
146 (setq cl-p cl-args) | |
147 (while cl-p (setcar cl-p (cdr (cl-pop cl-p)) ))) | |
148 (nreverse cl-res)) | |
149 (let ((cl-res nil)) | |
150 (while cl-list | |
151 (cl-push (funcall cl-func cl-list) cl-res) | |
152 (setq cl-list (cdr cl-list))) | |
153 (nreverse cl-res)))) | |
154 | |
28565 | 155 (defvar cl-old-mapc (symbol-function 'mapc)) |
156 | |
4355 | 157 (defun mapc (cl-func cl-seq &rest cl-rest) |
158 "Like `mapcar', but does not accumulate values returned by the function." | |
159 (if cl-rest | |
28565 | 160 (progn (apply 'map nil cl-func cl-seq cl-rest) |
161 cl-seq) | |
162 (funcall #'cl-old-mapc cl-func cl-seq))) | |
4355 | 163 |
164 (defun mapl (cl-func cl-list &rest cl-rest) | |
165 "Like `maplist', but does not accumulate values returned by the function." | |
166 (if cl-rest | |
167 (apply 'maplist cl-func cl-list cl-rest) | |
168 (let ((cl-p cl-list)) | |
169 (while cl-p (funcall cl-func cl-p) (setq cl-p (cdr cl-p))))) | |
170 cl-list) | |
171 | |
172 (defun mapcan (cl-func cl-seq &rest cl-rest) | |
173 "Like `mapcar', but nconc's together the values returned by the function." | |
174 (apply 'nconc (apply 'mapcar* cl-func cl-seq cl-rest))) | |
175 | |
176 (defun mapcon (cl-func cl-list &rest cl-rest) | |
177 "Like `maplist', but nconc's together the values returned by the function." | |
178 (apply 'nconc (apply 'maplist cl-func cl-list cl-rest))) | |
179 | |
180 (defun some (cl-pred cl-seq &rest cl-rest) | |
181 "Return true if PREDICATE is true of any element of SEQ or SEQs. | |
182 If so, return the true (non-nil) value returned by PREDICATE." | |
183 (if (or cl-rest (nlistp cl-seq)) | |
184 (catch 'cl-some | |
185 (apply 'map nil | |
186 (function (lambda (&rest cl-x) | |
187 (let ((cl-res (apply cl-pred cl-x))) | |
188 (if cl-res (throw 'cl-some cl-res))))) | |
189 cl-seq cl-rest) nil) | |
190 (let ((cl-x nil)) | |
191 (while (and cl-seq (not (setq cl-x (funcall cl-pred (cl-pop cl-seq)))))) | |
192 cl-x))) | |
193 | |
194 (defun every (cl-pred cl-seq &rest cl-rest) | |
195 "Return true if PREDICATE is true of every element of SEQ or SEQs." | |
196 (if (or cl-rest (nlistp cl-seq)) | |
197 (catch 'cl-every | |
198 (apply 'map nil | |
199 (function (lambda (&rest cl-x) | |
200 (or (apply cl-pred cl-x) (throw 'cl-every nil)))) | |
201 cl-seq cl-rest) t) | |
202 (while (and cl-seq (funcall cl-pred (car cl-seq))) | |
203 (setq cl-seq (cdr cl-seq))) | |
204 (null cl-seq))) | |
205 | |
206 (defun notany (cl-pred cl-seq &rest cl-rest) | |
207 "Return true if PREDICATE is false of every element of SEQ or SEQs." | |
208 (not (apply 'some cl-pred cl-seq cl-rest))) | |
209 | |
210 (defun notevery (cl-pred cl-seq &rest cl-rest) | |
211 "Return true if PREDICATE is false of some element of SEQ or SEQs." | |
212 (not (apply 'every cl-pred cl-seq cl-rest))) | |
213 | |
214 ;;; Support for `loop'. | |
215 (defun cl-map-keymap (cl-func cl-map) | |
216 (while (symbolp cl-map) (setq cl-map (symbol-function cl-map))) | |
27123 | 217 (if (listp cl-map) |
218 (let ((cl-p cl-map)) | |
219 (while (consp (setq cl-p (cdr cl-p))) | |
220 (cond ((consp (car cl-p)) | |
221 (funcall cl-func (car (car cl-p)) (cdr (car cl-p)))) | |
222 ((vectorp (car cl-p)) | |
223 (cl-map-keymap cl-func (car cl-p))) | |
224 ((eq (car cl-p) 'keymap) | |
225 (setq cl-p nil))))) | |
226 (let ((cl-i -1)) | |
227 (while (< (setq cl-i (1+ cl-i)) (length cl-map)) | |
228 (if (aref cl-map cl-i) | |
229 (funcall cl-func cl-i (aref cl-map cl-i))))))) | |
4355 | 230 |
231 (defun cl-map-keymap-recursively (cl-func-rec cl-map &optional cl-base) | |
232 (or cl-base | |
27123 | 233 (setq cl-base (copy-sequence [0]))) |
4355 | 234 (cl-map-keymap |
235 (function | |
236 (lambda (cl-key cl-bind) | |
237 (aset cl-base (1- (length cl-base)) cl-key) | |
238 (if (keymapp cl-bind) | |
239 (cl-map-keymap-recursively | |
240 cl-func-rec cl-bind | |
27123 | 241 (vconcat cl-base (list 0))) |
4355 | 242 (funcall cl-func-rec cl-base cl-bind)))) |
243 cl-map)) | |
244 | |
245 (defun cl-map-intervals (cl-func &optional cl-what cl-prop cl-start cl-end) | |
246 (or cl-what (setq cl-what (current-buffer))) | |
247 (if (bufferp cl-what) | |
248 (let (cl-mark cl-mark2 (cl-next t) cl-next2) | |
28565 | 249 (with-current-buffer cl-what |
4355 | 250 (setq cl-mark (copy-marker (or cl-start (point-min)))) |
251 (setq cl-mark2 (and cl-end (copy-marker cl-end)))) | |
252 (while (and cl-next (or (not cl-mark2) (< cl-mark cl-mark2))) | |
28565 | 253 (setq cl-next (if cl-prop (next-single-property-change |
254 cl-mark cl-prop cl-what) | |
255 (next-property-change cl-mark cl-what)) | |
256 cl-next2 (or cl-next (with-current-buffer cl-what | |
257 (point-max)))) | |
4355 | 258 (funcall cl-func (prog1 (marker-position cl-mark) |
259 (set-marker cl-mark cl-next2)) | |
260 (if cl-mark2 (min cl-next2 cl-mark2) cl-next2))) | |
261 (set-marker cl-mark nil) (if cl-mark2 (set-marker cl-mark2 nil))) | |
262 (or cl-start (setq cl-start 0)) | |
263 (or cl-end (setq cl-end (length cl-what))) | |
264 (while (< cl-start cl-end) | |
28565 | 265 (let ((cl-next (or (if cl-prop (next-single-property-change |
266 cl-start cl-prop cl-what) | |
267 (next-property-change cl-start cl-what)) | |
4355 | 268 cl-end))) |
269 (funcall cl-func cl-start (min cl-next cl-end)) | |
270 (setq cl-start cl-next))))) | |
271 | |
272 (defun cl-map-overlays (cl-func &optional cl-buffer cl-start cl-end cl-arg) | |
273 (or cl-buffer (setq cl-buffer (current-buffer))) | |
274 (if (fboundp 'overlay-lists) | |
275 | |
276 ;; This is the preferred algorithm, though overlay-lists is undocumented. | |
277 (let (cl-ovl) | |
28565 | 278 (with-current-buffer cl-buffer |
4355 | 279 (setq cl-ovl (overlay-lists)) |
280 (if cl-start (setq cl-start (copy-marker cl-start))) | |
281 (if cl-end (setq cl-end (copy-marker cl-end)))) | |
282 (setq cl-ovl (nconc (car cl-ovl) (cdr cl-ovl))) | |
283 (while (and cl-ovl | |
284 (or (not (overlay-start (car cl-ovl))) | |
285 (and cl-end (>= (overlay-start (car cl-ovl)) cl-end)) | |
286 (and cl-start (<= (overlay-end (car cl-ovl)) cl-start)) | |
287 (not (funcall cl-func (car cl-ovl) cl-arg)))) | |
288 (setq cl-ovl (cdr cl-ovl))) | |
289 (if cl-start (set-marker cl-start nil)) | |
290 (if cl-end (set-marker cl-end nil))) | |
291 | |
292 ;; This alternate algorithm fails to find zero-length overlays. | |
28565 | 293 (let ((cl-mark (with-current-buffer cl-buffer |
294 (copy-marker (or cl-start (point-min))))) | |
295 (cl-mark2 (and cl-end (with-current-buffer cl-buffer | |
296 (copy-marker cl-end)))) | |
4355 | 297 cl-pos cl-ovl) |
298 (while (save-excursion | |
299 (and (setq cl-pos (marker-position cl-mark)) | |
300 (< cl-pos (or cl-mark2 (point-max))) | |
301 (progn | |
302 (set-buffer cl-buffer) | |
303 (setq cl-ovl (overlays-at cl-pos)) | |
304 (set-marker cl-mark (next-overlay-change cl-pos))))) | |
305 (while (and cl-ovl | |
306 (or (/= (overlay-start (car cl-ovl)) cl-pos) | |
307 (not (and (funcall cl-func (car cl-ovl) cl-arg) | |
308 (set-marker cl-mark nil))))) | |
309 (setq cl-ovl (cdr cl-ovl)))) | |
310 (set-marker cl-mark nil) (if cl-mark2 (set-marker cl-mark2 nil))))) | |
311 | |
312 ;;; Support for `setf'. | |
313 (defun cl-set-frame-visible-p (frame val) | |
314 (cond ((null val) (make-frame-invisible frame)) | |
315 ((eq val 'icon) (iconify-frame frame)) | |
316 (t (make-frame-visible frame))) | |
317 val) | |
318 | |
319 ;;; Support for `progv'. | |
320 (defvar cl-progv-save) | |
321 (defun cl-progv-before (syms values) | |
322 (while syms | |
323 (cl-push (if (boundp (car syms)) | |
324 (cons (car syms) (symbol-value (car syms))) | |
325 (car syms)) cl-progv-save) | |
326 (if values | |
327 (set (cl-pop syms) (cl-pop values)) | |
328 (makunbound (cl-pop syms))))) | |
329 | |
330 (defun cl-progv-after () | |
331 (while cl-progv-save | |
332 (if (consp (car cl-progv-save)) | |
333 (set (car (car cl-progv-save)) (cdr (car cl-progv-save))) | |
334 (makunbound (car cl-progv-save))) | |
335 (cl-pop cl-progv-save))) | |
336 | |
337 | |
338 ;;; Numbers. | |
339 | |
340 (defun gcd (&rest args) | |
341 "Return the greatest common divisor of the arguments." | |
342 (let ((a (abs (or (cl-pop args) 0)))) | |
343 (while args | |
344 (let ((b (abs (cl-pop args)))) | |
345 (while (> b 0) (setq b (% a (setq a b)))))) | |
346 a)) | |
347 | |
348 (defun lcm (&rest args) | |
349 "Return the least common multiple of the arguments." | |
350 (if (memq 0 args) | |
351 0 | |
352 (let ((a (abs (or (cl-pop args) 1)))) | |
353 (while args | |
354 (let ((b (abs (cl-pop args)))) | |
355 (setq a (* (/ a (gcd a b)) b)))) | |
356 a))) | |
357 | |
358 (defun isqrt (a) | |
359 "Return the integer square root of the argument." | |
360 (if (and (integerp a) (> a 0)) | |
15029
ba44a899c055
(isqrt): Support expanded range of Lisp integers.
Richard M. Stallman <rms@gnu.org>
parents:
14794
diff
changeset
|
361 (let ((g (cond ((<= a 100) 10) ((<= a 10000) 100) |
ba44a899c055
(isqrt): Support expanded range of Lisp integers.
Richard M. Stallman <rms@gnu.org>
parents:
14794
diff
changeset
|
362 ((<= a 1000000) 1000) (t a))) |
4355 | 363 g2) |
364 (while (< (setq g2 (/ (+ g (/ a g)) 2)) g) | |
365 (setq g g2)) | |
366 g) | |
367 (if (eq a 0) 0 (signal 'arith-error nil)))) | |
368 | |
369 (defun floor* (x &optional y) | |
370 "Return a list of the floor of X and the fractional part of X. | |
371 With two arguments, return floor and remainder of their quotient." | |
4517
45e3868140f1
(floor*): Use `floor' instead of doing most the work ourselves.
Paul Eggert <eggert@twinsun.com>
parents:
4355
diff
changeset
|
372 (let ((q (floor x y))) |
45e3868140f1
(floor*): Use `floor' instead of doing most the work ourselves.
Paul Eggert <eggert@twinsun.com>
parents:
4355
diff
changeset
|
373 (list q (- x (if y (* y q) q))))) |
4355 | 374 |
375 (defun ceiling* (x &optional y) | |
376 "Return a list of the ceiling of X and the fractional part of X. | |
377 With two arguments, return ceiling and remainder of their quotient." | |
378 (let ((res (floor* x y))) | |
379 (if (= (car (cdr res)) 0) res | |
380 (list (1+ (car res)) (- (car (cdr res)) (or y 1)))))) | |
381 | |
382 (defun truncate* (x &optional y) | |
383 "Return a list of the integer part of X and the fractional part of X. | |
384 With two arguments, return truncation and remainder of their quotient." | |
385 (if (eq (>= x 0) (or (null y) (>= y 0))) | |
386 (floor* x y) (ceiling* x y))) | |
387 | |
388 (defun round* (x &optional y) | |
389 "Return a list of X rounded to the nearest integer and the remainder. | |
390 With two arguments, return rounding and remainder of their quotient." | |
391 (if y | |
392 (if (and (integerp x) (integerp y)) | |
393 (let* ((hy (/ y 2)) | |
394 (res (floor* (+ x hy) y))) | |
395 (if (and (= (car (cdr res)) 0) | |
396 (= (+ hy hy) y) | |
397 (/= (% (car res) 2) 0)) | |
398 (list (1- (car res)) hy) | |
399 (list (car res) (- (car (cdr res)) hy)))) | |
400 (let ((q (round (/ x y)))) | |
401 (list q (- x (* q y))))) | |
402 (if (integerp x) (list x 0) | |
403 (let ((q (round x))) | |
404 (list q (- x q)))))) | |
405 | |
406 (defun mod* (x y) | |
407 "The remainder of X divided by Y, with the same sign as Y." | |
408 (nth 1 (floor* x y))) | |
409 | |
410 (defun rem* (x y) | |
411 "The remainder of X divided by Y, with the same sign as X." | |
412 (nth 1 (truncate* x y))) | |
413 | |
414 (defun signum (a) | |
415 "Return 1 if A is positive, -1 if negative, 0 if zero." | |
416 (cond ((> a 0) 1) ((< a 0) -1) (t 0))) | |
417 | |
418 | |
419 ;; Random numbers. | |
420 | |
421 (defvar *random-state*) | |
422 (defun random* (lim &optional state) | |
423 "Return a random nonnegative number less than LIM, an integer or float. | |
424 Optional second arg STATE is a random-state object." | |
425 (or state (setq state *random-state*)) | |
426 ;; Inspired by "ran3" from Numerical Recipes. Additive congruential method. | |
427 (let ((vec (aref state 3))) | |
428 (if (integerp vec) | |
429 (let ((i 0) (j (- 1357335 (% (abs vec) 1357333))) (k 1) ii) | |
430 (aset state 3 (setq vec (make-vector 55 nil))) | |
431 (aset vec 0 j) | |
432 (while (> (setq i (% (+ i 21) 55)) 0) | |
433 (aset vec i (setq j (prog1 k (setq k (- j k)))))) | |
434 (while (< (setq i (1+ i)) 200) (random* 2 state)))) | |
435 (let* ((i (aset state 1 (% (1+ (aref state 1)) 55))) | |
436 (j (aset state 2 (% (1+ (aref state 2)) 55))) | |
437 (n (logand 8388607 (aset vec i (- (aref vec i) (aref vec j)))))) | |
438 (if (integerp lim) | |
439 (if (<= lim 512) (% n lim) | |
440 (if (> lim 8388607) (setq n (+ (lsh n 9) (random* 512 state)))) | |
441 (let ((mask 1023)) | |
442 (while (< mask (1- lim)) (setq mask (1+ (+ mask mask)))) | |
443 (if (< (setq n (logand n mask)) lim) n (random* lim state)))) | |
444 (* (/ n '8388608e0) lim))))) | |
445 | |
446 (defun make-random-state (&optional state) | |
447 "Return a copy of random-state STATE, or of `*random-state*' if omitted. | |
448 If STATE is t, return a new state object seeded from the time of day." | |
449 (cond ((null state) (make-random-state *random-state*)) | |
450 ((vectorp state) (cl-copy-tree state t)) | |
451 ((integerp state) (vector 'cl-random-state-tag -1 30 state)) | |
452 (t (make-random-state (cl-random-time))))) | |
453 | |
454 (defun random-state-p (object) | |
455 "Return t if OBJECT is a random-state object." | |
456 (and (vectorp object) (= (length object) 4) | |
457 (eq (aref object 0) 'cl-random-state-tag))) | |
458 | |
459 | |
460 ;; Implementation limits. | |
461 | |
462 (defun cl-finite-do (func a b) | |
463 (condition-case err | |
464 (let ((res (funcall func a b))) ; check for IEEE infinity | |
465 (and (numberp res) (/= res (/ res 2)) res)) | |
466 (arith-error nil))) | |
467 | |
468 (defvar most-positive-float) | |
469 (defvar most-negative-float) | |
470 (defvar least-positive-float) | |
471 (defvar least-negative-float) | |
472 (defvar least-positive-normalized-float) | |
473 (defvar least-negative-normalized-float) | |
474 (defvar float-epsilon) | |
475 (defvar float-negative-epsilon) | |
476 | |
477 (defun cl-float-limits () | |
478 (or most-positive-float (not (numberp '2e1)) | |
479 (let ((x '2e0) y z) | |
480 ;; Find maximum exponent (first two loops are optimizations) | |
481 (while (cl-finite-do '* x x) (setq x (* x x))) | |
482 (while (cl-finite-do '* x (/ x 2)) (setq x (* x (/ x 2)))) | |
483 (while (cl-finite-do '+ x x) (setq x (+ x x))) | |
484 (setq z x y (/ x 2)) | |
485 ;; Now fill in 1's in the mantissa. | |
486 (while (and (cl-finite-do '+ x y) (/= (+ x y) x)) | |
487 (setq x (+ x y) y (/ y 2))) | |
488 (setq most-positive-float x | |
489 most-negative-float (- x)) | |
490 ;; Divide down until mantissa starts rounding. | |
491 (setq x (/ x z) y (/ 16 z) x (* x y)) | |
492 (while (condition-case err (and (= x (* (/ x 2) 2)) (> (/ y 2) 0)) | |
493 (arith-error nil)) | |
494 (setq x (/ x 2) y (/ y 2))) | |
495 (setq least-positive-normalized-float y | |
496 least-negative-normalized-float (- y)) | |
497 ;; Divide down until value underflows to zero. | |
498 (setq x (/ 1 z) y x) | |
499 (while (condition-case err (> (/ x 2) 0) (arith-error nil)) | |
500 (setq x (/ x 2))) | |
501 (setq least-positive-float x | |
502 least-negative-float (- x)) | |
503 (setq x '1e0) | |
504 (while (/= (+ '1e0 x) '1e0) (setq x (/ x 2))) | |
505 (setq float-epsilon (* x 2)) | |
506 (setq x '1e0) | |
507 (while (/= (- '1e0 x) '1e0) (setq x (/ x 2))) | |
508 (setq float-negative-epsilon (* x 2)))) | |
509 nil) | |
510 | |
511 | |
512 ;;; Sequence functions. | |
513 | |
514 (defun subseq (seq start &optional end) | |
515 "Return the subsequence of SEQ from START to END. | |
516 If END is omitted, it defaults to the length of the sequence. | |
517 If START or END is negative, it counts from the end." | |
518 (if (stringp seq) (substring seq start end) | |
519 (let (len) | |
520 (and end (< end 0) (setq end (+ end (setq len (length seq))))) | |
521 (if (< start 0) (setq start (+ start (or len (setq len (length seq)))))) | |
522 (cond ((listp seq) | |
523 (if (> start 0) (setq seq (nthcdr start seq))) | |
524 (if end | |
525 (let ((res nil)) | |
526 (while (>= (setq end (1- end)) start) | |
527 (cl-push (cl-pop seq) res)) | |
528 (nreverse res)) | |
529 (copy-sequence seq))) | |
530 (t | |
531 (or end (setq end (or len (length seq)))) | |
532 (let ((res (make-vector (max (- end start) 0) nil)) | |
533 (i 0)) | |
534 (while (< start end) | |
535 (aset res i (aref seq start)) | |
536 (setq i (1+ i) start (1+ start))) | |
537 res)))))) | |
538 | |
539 (defun concatenate (type &rest seqs) | |
540 "Concatenate, into a sequence of type TYPE, the argument SEQUENCES." | |
541 (cond ((eq type 'vector) (apply 'vconcat seqs)) | |
542 ((eq type 'string) (apply 'concat seqs)) | |
543 ((eq type 'list) (apply 'append (append seqs '(nil)))) | |
544 (t (error "Not a sequence type name: %s" type)))) | |
545 | |
546 | |
547 ;;; List functions. | |
548 | |
549 (defun revappend (x y) | |
550 "Equivalent to (append (reverse X) Y)." | |
551 (nconc (reverse x) y)) | |
552 | |
553 (defun nreconc (x y) | |
554 "Equivalent to (nconc (nreverse X) Y)." | |
555 (nconc (nreverse x) y)) | |
556 | |
557 (defun list-length (x) | |
558 "Return the length of a list. Return nil if list is circular." | |
559 (let ((n 0) (fast x) (slow x)) | |
560 (while (and (cdr fast) (not (and (eq fast slow) (> n 0)))) | |
561 (setq n (+ n 2) fast (cdr (cdr fast)) slow (cdr slow))) | |
562 (if fast (if (cdr fast) nil (1+ n)) n))) | |
563 | |
564 (defun tailp (sublist list) | |
565 "Return true if SUBLIST is a tail of LIST." | |
566 (while (and (consp list) (not (eq sublist list))) | |
567 (setq list (cdr list))) | |
568 (if (numberp sublist) (equal sublist list) (eq sublist list))) | |
569 | |
570 (defun cl-copy-tree (tree &optional vecp) | |
571 "Make a copy of TREE. | |
572 If TREE is a cons cell, this recursively copies both its car and its cdr. | |
13970 | 573 Contrast to copy-sequence, which copies only along the cdrs. With second |
4355 | 574 argument VECP, this copies vectors as well as conses." |
575 (if (consp tree) | |
576 (let ((p (setq tree (copy-list tree)))) | |
577 (while (consp p) | |
578 (if (or (consp (car p)) (and vecp (vectorp (car p)))) | |
579 (setcar p (cl-copy-tree (car p) vecp))) | |
580 (or (listp (cdr p)) (setcdr p (cl-copy-tree (cdr p) vecp))) | |
581 (cl-pop p))) | |
582 (if (and vecp (vectorp tree)) | |
583 (let ((i (length (setq tree (copy-sequence tree))))) | |
584 (while (>= (setq i (1- i)) 0) | |
585 (aset tree i (cl-copy-tree (aref tree i) vecp)))))) | |
586 tree) | |
28565 | 587 (defalias 'copy-tree 'cl-copy-tree) |
4355 | 588 |
589 | |
590 ;;; Property lists. | |
591 | |
592 (defun get* (sym tag &optional def) ; See compiler macro in cl-macs.el | |
593 "Return the value of SYMBOL's PROPNAME property, or DEFAULT if none." | |
594 (or (get sym tag) | |
595 (and def | |
596 (let ((plist (symbol-plist sym))) | |
597 (while (and plist (not (eq (car plist) tag))) | |
598 (setq plist (cdr (cdr plist)))) | |
599 (if plist (car (cdr plist)) def))))) | |
600 | |
601 (defun getf (plist tag &optional def) | |
602 "Search PROPLIST for property PROPNAME; return its value or DEFAULT. | |
603 PROPLIST is a list of the sort returned by `symbol-plist'." | |
604 (setplist '--cl-getf-symbol-- plist) | |
605 (or (get '--cl-getf-symbol-- tag) | |
24826 | 606 ;; Originally we called get* here, |
607 ;; but that fails, because get* has a compiler macro | |
608 ;; definition that uses getf! | |
609 (when def | |
610 (while (and plist (not (eq (car plist) tag))) | |
611 (setq plist (cdr (cdr plist)))) | |
612 (if plist (car (cdr plist)) def)))) | |
4355 | 613 |
614 (defun cl-set-getf (plist tag val) | |
615 (let ((p plist)) | |
616 (while (and p (not (eq (car p) tag))) (setq p (cdr (cdr p)))) | |
617 (if p (progn (setcar (cdr p) val) plist) (list* tag val plist)))) | |
618 | |
619 (defun cl-do-remf (plist tag) | |
620 (let ((p (cdr plist))) | |
621 (while (and (cdr p) (not (eq (car (cdr p)) tag))) (setq p (cdr (cdr p)))) | |
622 (and (cdr p) (progn (setcdr p (cdr (cdr (cdr p)))) t)))) | |
623 | |
624 (defun cl-remprop (sym tag) | |
625 "Remove from SYMBOL's plist the property PROP and its value." | |
626 (let ((plist (symbol-plist sym))) | |
627 (if (and plist (eq tag (car plist))) | |
628 (progn (setplist sym (cdr (cdr plist))) t) | |
629 (cl-do-remf plist tag)))) | |
28565 | 630 (defalias 'remprop 'cl-remprop) |
4355 | 631 |
632 | |
633 | |
634 ;;; Hash tables. | |
635 | |
24988
3bfd67af61d0
(cl-make-hash-table): Renamed from make-hash-table.
Gerd Moellmann <gerd@gnu.org>
parents:
24826
diff
changeset
|
636 (defun cl-make-hash-table (&rest cl-keys) |
4355 | 637 "Make an empty Common Lisp-style hash-table. |
638 Keywords supported: :test :size | |
639 The Common Lisp keywords :rehash-size and :rehash-threshold are ignored." | |
28565 | 640 (let ((cl-test (or (car (cdr (memq :test cl-keys))) 'eql)) |
641 (cl-size (or (car (cdr (memq :size cl-keys))) 20))) | |
27197
3e34f4e0b1c2
(cl-make-hash-table): Use make-hash-table.
Dave Love <fx@gnu.org>
parents:
27123
diff
changeset
|
642 (make-hash-table :size cl-size :test cl-size))) |
4355 | 643 |
24988
3bfd67af61d0
(cl-make-hash-table): Renamed from make-hash-table.
Gerd Moellmann <gerd@gnu.org>
parents:
24826
diff
changeset
|
644 (defun cl-hash-table-p (x) |
4355 | 645 "Return t if OBJECT is a hash table." |
27197
3e34f4e0b1c2
(cl-make-hash-table): Use make-hash-table.
Dave Love <fx@gnu.org>
parents:
27123
diff
changeset
|
646 (or (hash-table-p x) |
3e34f4e0b1c2
(cl-make-hash-table): Use make-hash-table.
Dave Love <fx@gnu.org>
parents:
27123
diff
changeset
|
647 (eq (car-safe x) 'cl-hash-table-tag))) |
4355 | 648 |
649 (defun cl-not-hash-table (x &optional y &rest z) | |
27123 | 650 (signal 'wrong-type-argument (list 'cl-hash-table-p (or y x)))) |
4355 | 651 |
652 (defun cl-hash-lookup (key table) | |
653 (or (eq (car-safe table) 'cl-hash-table-tag) (cl-not-hash-table table)) | |
654 (let* ((array (nth 2 table)) (test (car (cdr table))) (str key) sym) | |
655 (if (symbolp array) (setq str nil sym (symbol-value array)) | |
656 (while (or (consp str) (and (vectorp str) (> (length str) 0))) | |
657 (setq str (elt str 0))) | |
658 (cond ((stringp str) (if (eq test 'equalp) (setq str (downcase str)))) | |
659 ((symbolp str) (setq str (symbol-name str))) | |
660 ((and (numberp str) (> str -8000000) (< str 8000000)) | |
661 (or (integerp str) (setq str (truncate str))) | |
662 (setq str (aref ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" | |
663 "11" "12" "13" "14" "15"] (logand str 15)))) | |
664 (t (setq str "*"))) | |
665 (setq sym (symbol-value (intern-soft str array)))) | |
666 (list (and sym (cond ((or (eq test 'eq) | |
667 (and (eq test 'eql) (not (numberp key)))) | |
668 (assq key sym)) | |
669 ((memq test '(eql equal)) (assoc key sym)) | |
28565 | 670 (t (assoc* key sym :test test)))) |
4355 | 671 sym str))) |
672 | |
673 (defun cl-gethash (key table &optional def) | |
674 "Look up KEY in HASH-TABLE; return corresponding value, or DEFAULT." | |
675 (if (consp table) | |
676 (let ((found (cl-hash-lookup key table))) | |
677 (if (car found) (cdr (car found)) def)) | |
27588
567639571c84
(cl-builtin-gethash, cl-builtin-remhash, cl-builtin-clrhash)
Dave Love <fx@gnu.org>
parents:
27197
diff
changeset
|
678 (gethash key table def))) |
4355 | 679 |
680 (defun cl-puthash (key val table) | |
681 (if (consp table) | |
682 (let ((found (cl-hash-lookup key table))) | |
683 (if (car found) (setcdr (car found) val) | |
684 (if (nth 2 found) | |
685 (progn | |
686 (if (> (nth 3 table) (* (length (nth 2 table)) 3)) | |
687 (let ((new-table (make-vector (nth 3 table) 0))) | |
688 (mapatoms (function | |
689 (lambda (sym) | |
690 (set (intern (symbol-name sym) new-table) | |
691 (symbol-value sym)))) | |
692 (nth 2 table)) | |
693 (setcar (cdr (cdr table)) new-table))) | |
694 (set (intern (nth 2 found) (nth 2 table)) | |
695 (cons (cons key val) (nth 1 found)))) | |
696 (set (nth 2 table) (cons (cons key val) (nth 1 found)))) | |
697 (setcar (cdr (cdr (cdr table))) (1+ (nth 3 table))))) | |
698 (funcall 'puthash key val table)) val) | |
699 | |
700 (defun cl-remhash (key table) | |
701 "Remove KEY from HASH-TABLE." | |
702 (if (consp table) | |
703 (let ((found (cl-hash-lookup key table))) | |
704 (and (car found) | |
705 (let ((del (delq (car found) (nth 1 found)))) | |
706 (setcar (cdr (cdr (cdr table))) (1- (nth 3 table))) | |
707 (if (nth 2 found) (set (intern (nth 2 found) (nth 2 table)) del) | |
708 (set (nth 2 table) del)) t))) | |
27588
567639571c84
(cl-builtin-gethash, cl-builtin-remhash, cl-builtin-clrhash)
Dave Love <fx@gnu.org>
parents:
27197
diff
changeset
|
709 (prog1 (not (eq (gethash key table '--cl--) '--cl--)) |
567639571c84
(cl-builtin-gethash, cl-builtin-remhash, cl-builtin-clrhash)
Dave Love <fx@gnu.org>
parents:
27197
diff
changeset
|
710 (remhash key table)))) |
4355 | 711 |
712 (defun cl-clrhash (table) | |
713 "Clear HASH-TABLE." | |
714 (if (consp table) | |
715 (progn | |
27123 | 716 (or (cl-hash-table-p table) (cl-not-hash-table table)) |
4355 | 717 (if (symbolp (nth 2 table)) (set (nth 2 table) nil) |
718 (setcar (cdr (cdr table)) (make-vector (length (nth 2 table)) 0))) | |
719 (setcar (cdr (cdr (cdr table))) 0)) | |
27588
567639571c84
(cl-builtin-gethash, cl-builtin-remhash, cl-builtin-clrhash)
Dave Love <fx@gnu.org>
parents:
27197
diff
changeset
|
720 (clrhash table)) |
4355 | 721 nil) |
722 | |
723 (defun cl-maphash (cl-func cl-table) | |
724 "Call FUNCTION on keys and values from HASH-TABLE." | |
27123 | 725 (or (cl-hash-table-p cl-table) (cl-not-hash-table cl-table)) |
4355 | 726 (if (consp cl-table) |
727 (mapatoms (function (lambda (cl-x) | |
728 (setq cl-x (symbol-value cl-x)) | |
729 (while cl-x | |
730 (funcall cl-func (car (car cl-x)) | |
731 (cdr (car cl-x))) | |
732 (setq cl-x (cdr cl-x))))) | |
733 (if (symbolp (nth 2 cl-table)) | |
734 (vector (nth 2 cl-table)) (nth 2 cl-table))) | |
27588
567639571c84
(cl-builtin-gethash, cl-builtin-remhash, cl-builtin-clrhash)
Dave Love <fx@gnu.org>
parents:
27197
diff
changeset
|
735 (maphash cl-func cl-table))) |
4355 | 736 |
24988
3bfd67af61d0
(cl-make-hash-table): Renamed from make-hash-table.
Gerd Moellmann <gerd@gnu.org>
parents:
24826
diff
changeset
|
737 (defun cl-hash-table-count (table) |
4355 | 738 "Return the number of entries in HASH-TABLE." |
27123 | 739 (or (cl-hash-table-p table) (cl-not-hash-table table)) |
27197
3e34f4e0b1c2
(cl-make-hash-table): Use make-hash-table.
Dave Love <fx@gnu.org>
parents:
27123
diff
changeset
|
740 (if (consp table) |
3e34f4e0b1c2
(cl-make-hash-table): Use make-hash-table.
Dave Love <fx@gnu.org>
parents:
27123
diff
changeset
|
741 (nth 3 table) |
3e34f4e0b1c2
(cl-make-hash-table): Use make-hash-table.
Dave Love <fx@gnu.org>
parents:
27123
diff
changeset
|
742 (hash-table-count table))) |
4355 | 743 |
744 | |
745 ;;; Some debugging aids. | |
746 | |
747 (defun cl-prettyprint (form) | |
748 "Insert a pretty-printed rendition of a Lisp FORM in current buffer." | |
749 (let ((pt (point)) last) | |
750 (insert "\n" (prin1-to-string form) "\n") | |
751 (setq last (point)) | |
752 (goto-char (1+ pt)) | |
753 (while (search-forward "(quote " last t) | |
754 (delete-backward-char 7) | |
755 (insert "'") | |
756 (forward-sexp) | |
757 (delete-char 1)) | |
758 (goto-char (1+ pt)) | |
759 (cl-do-prettyprint))) | |
760 | |
761 (defun cl-do-prettyprint () | |
762 (skip-chars-forward " ") | |
763 (if (looking-at "(") | |
764 (let ((skip (or (looking-at "((") (looking-at "(prog") | |
765 (looking-at "(unwind-protect ") | |
766 (looking-at "(function (") | |
767 (looking-at "(cl-block-wrapper "))) | |
768 (two (or (looking-at "(defun ") (looking-at "(defmacro "))) | |
769 (let (or (looking-at "(let\\*? ") (looking-at "(while "))) | |
770 (set (looking-at "(p?set[qf] "))) | |
771 (if (or skip let | |
772 (progn | |
773 (forward-sexp) | |
774 (and (>= (current-column) 78) (progn (backward-sexp) t)))) | |
775 (let ((nl t)) | |
776 (forward-char 1) | |
777 (cl-do-prettyprint) | |
778 (or skip (looking-at ")") (cl-do-prettyprint)) | |
779 (or (not two) (looking-at ")") (cl-do-prettyprint)) | |
780 (while (not (looking-at ")")) | |
781 (if set (setq nl (not nl))) | |
782 (if nl (insert "\n")) | |
783 (lisp-indent-line) | |
784 (cl-do-prettyprint)) | |
785 (forward-char 1)))) | |
786 (forward-sexp))) | |
787 | |
788 (defvar cl-macroexpand-cmacs nil) | |
789 (defvar cl-closure-vars nil) | |
790 | |
791 (defun cl-macroexpand-all (form &optional env) | |
792 "Expand all macro calls through a Lisp FORM. | |
793 This also does some trivial optimizations to make the form prettier." | |
794 (while (or (not (eq form (setq form (macroexpand form env)))) | |
795 (and cl-macroexpand-cmacs | |
796 (not (eq form (setq form (compiler-macroexpand form))))))) | |
797 (cond ((not (consp form)) form) | |
798 ((memq (car form) '(let let*)) | |
799 (if (null (nth 1 form)) | |
800 (cl-macroexpand-all (cons 'progn (cddr form)) env) | |
801 (let ((letf nil) (res nil) (lets (cadr form))) | |
802 (while lets | |
803 (cl-push (if (consp (car lets)) | |
804 (let ((exp (cl-macroexpand-all (caar lets) env))) | |
805 (or (symbolp exp) (setq letf t)) | |
806 (cons exp (cl-macroexpand-body (cdar lets) env))) | |
807 (let ((exp (cl-macroexpand-all (car lets) env))) | |
808 (if (symbolp exp) exp | |
809 (setq letf t) (list exp nil)))) res) | |
810 (setq lets (cdr lets))) | |
811 (list* (if letf (if (eq (car form) 'let) 'letf 'letf*) (car form)) | |
812 (nreverse res) (cl-macroexpand-body (cddr form) env))))) | |
813 ((eq (car form) 'cond) | |
814 (cons (car form) | |
815 (mapcar (function (lambda (x) (cl-macroexpand-body x env))) | |
816 (cdr form)))) | |
817 ((eq (car form) 'condition-case) | |
818 (list* (car form) (nth 1 form) (cl-macroexpand-all (nth 2 form) env) | |
819 (mapcar (function | |
820 (lambda (x) | |
821 (cons (car x) (cl-macroexpand-body (cdr x) env)))) | |
822 (cdddr form)))) | |
823 ((memq (car form) '(quote function)) | |
824 (if (eq (car-safe (nth 1 form)) 'lambda) | |
825 (let ((body (cl-macroexpand-body (cddadr form) env))) | |
826 (if (and cl-closure-vars (eq (car form) 'function) | |
827 (cl-expr-contains-any body cl-closure-vars)) | |
828 (let* ((new (mapcar 'gensym cl-closure-vars)) | |
829 (sub (pairlis cl-closure-vars new)) (decls nil)) | |
830 (while (or (stringp (car body)) | |
831 (eq (car-safe (car body)) 'interactive)) | |
832 (cl-push (list 'quote (cl-pop body)) decls)) | |
833 (put (car (last cl-closure-vars)) 'used t) | |
834 (append | |
835 (list 'list '(quote lambda) '(quote (&rest --cl-rest--))) | |
836 (sublis sub (nreverse decls)) | |
837 (list | |
838 (list* 'list '(quote apply) | |
839 (list 'list '(quote quote) | |
840 (list 'function | |
841 (list* 'lambda | |
842 (append new (cadadr form)) | |
843 (sublis sub body)))) | |
844 (nconc (mapcar (function | |
845 (lambda (x) | |
846 (list 'list '(quote quote) x))) | |
847 cl-closure-vars) | |
848 '((quote --cl-rest--))))))) | |
849 (list (car form) (list* 'lambda (cadadr form) body)))) | |
15029
ba44a899c055
(isqrt): Support expanded range of Lisp integers.
Richard M. Stallman <rms@gnu.org>
parents:
14794
diff
changeset
|
850 (let ((found (assq (cadr form) env))) |
ba44a899c055
(isqrt): Support expanded range of Lisp integers.
Richard M. Stallman <rms@gnu.org>
parents:
14794
diff
changeset
|
851 (if (eq (cadr (caddr found)) 'cl-labels-args) |
ba44a899c055
(isqrt): Support expanded range of Lisp integers.
Richard M. Stallman <rms@gnu.org>
parents:
14794
diff
changeset
|
852 (cl-macroexpand-all (cadr (caddr (cadddr found))) env) |
ba44a899c055
(isqrt): Support expanded range of Lisp integers.
Richard M. Stallman <rms@gnu.org>
parents:
14794
diff
changeset
|
853 form)))) |
4355 | 854 ((memq (car form) '(defun defmacro)) |
855 (list* (car form) (nth 1 form) (cl-macroexpand-body (cddr form) env))) | |
856 ((and (eq (car form) 'progn) (not (cddr form))) | |
857 (cl-macroexpand-all (nth 1 form) env)) | |
858 ((eq (car form) 'setq) | |
859 (let* ((args (cl-macroexpand-body (cdr form) env)) (p args)) | |
860 (while (and p (symbolp (car p))) (setq p (cddr p))) | |
861 (if p (cl-macroexpand-all (cons 'setf args)) (cons 'setq args)))) | |
862 (t (cons (car form) (cl-macroexpand-body (cdr form) env))))) | |
863 | |
864 (defun cl-macroexpand-body (body &optional env) | |
865 (mapcar (function (lambda (x) (cl-macroexpand-all x env))) body)) | |
866 | |
867 (defun cl-prettyexpand (form &optional full) | |
868 (message "Expanding...") | |
869 (let ((cl-macroexpand-cmacs full) (cl-compiling-file full) | |
870 (byte-compile-macro-environment nil)) | |
871 (setq form (cl-macroexpand-all form | |
872 (and (not full) '((block) (eval-when))))) | |
873 (message "Formatting...") | |
874 (prog1 (cl-prettyprint form) | |
875 (message "")))) | |
876 | |
877 | |
878 | |
879 (run-hooks 'cl-extra-load-hook) | |
880 | |
881 ;;; cl-extra.el ends here |