Mercurial > hg > xemacs-beta
annotate lisp/cl.el @ 4997:8800b5350a13
Move #'some, #'every to C, implementing them with mapcarX.
src/ChangeLog addition:
2010-02-03 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (mapcarX):
Accept a new argument, indicating whether the function is being
called from #'some or #'every. Implement it.
Discard any multiple values where that is appropriate.
(Fmapconcat, FmapcarX, Fmapvector, Fmapcan, Fmapc, Fmap)
(Fmap_into):
Pass the new flag to mapcarX.
(Fsome, Fevery): Move these functions here from cl-extra.el;
implement them in terms of mapcarX.
(maplist): Discard multiple values where appropriate.
lisp/ChangeLog addition:
2010-02-03 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (some, every):
Move these functions to C.
* cl-macs.el (notany, notevery): Add compiler macros for these
functions, no longer proclaim them inline (which would involve
specbinding that's not necessary with the compiler macros).
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 03 Feb 2010 20:26:47 +0000 |
parents | 8431b52e43b1 |
children | 545ec923b4eb |
rev | line source |
---|---|
613 | 1 ;;; cl.el --- Common Lisp extensions for XEmacs Lisp |
428 | 2 |
3 ;; Copyright (C) 1993, 1997 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Dave Gillespie <daveg@synaptics.com> | |
6 ;; Maintainer: XEmacs Development Team | |
7 ;; Version: 2.02 | |
8 ;; Keywords: extensions, dumped, lisp | |
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 | |
2153 | 27 ;;; Synched up with: FSF 21.3. |
428 | 28 |
29 ;;; Commentary: | |
30 | |
31 ;; This file is dumped with XEmacs. | |
32 | |
33 ;; These are extensions to Emacs Lisp that provide a degree of | |
34 ;; Common Lisp compatibility, beyond what is already built-in | |
35 ;; in Emacs Lisp. | |
36 ;; | |
37 ;; This package was written by Dave Gillespie; it is a complete | |
38 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
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 always be present. | |
44 | |
45 | |
46 ;;; Future notes: | |
47 | |
48 ;; Once Emacs 19 becomes standard, many things in this package which are | |
49 ;; messy for reasons of compatibility can be greatly simplified. For now, | |
50 ;; I prefer to maintain one unified version. | |
51 | |
52 | |
53 ;;; Change Log: | |
54 | |
55 ;; Version 2.02 (30 Jul 93): | |
56 ;; * Added "cl-compat.el" file, extra compatibility with old package. | |
57 ;; * Added `lexical-let' and `lexical-let*'. | |
58 ;; * Added `define-modify-macro', `callf', and `callf2'. | |
59 ;; * Added `ignore-errors'. | |
60 ;; * Changed `(setf (nthcdr N PLACE) X)' to work when N is zero. | |
61 ;; * Merged `*gentemp-counter*' into `*gensym-counter*'. | |
62 ;; * Extended `subseq' to allow negative START and END like `substring'. | |
63 ;; * Added `in-ref', `across-ref', `elements of-ref' loop clauses. | |
64 ;; * Added `concat', `vconcat' loop clauses. | |
65 ;; * Cleaned up a number of compiler warnings. | |
66 | |
67 ;; Version 2.01 (7 Jul 93): | |
68 ;; * Added support for FSF version of Emacs 19. | |
69 ;; * Added `add-hook' for Emacs 18 users. | |
70 ;; * Added `defsubst*' and `symbol-macrolet'. | |
71 ;; * Added `maplist', `mapc', `mapl', `mapcan', `mapcon'. | |
72 ;; * Added `map', `concatenate', `reduce', `merge'. | |
73 ;; * Added `revappend', `nreconc', `tailp', `tree-equal'. | |
74 ;; * Added `assert', `check-type', `typecase', `typep', and `deftype'. | |
75 ;; * Added destructuring and `&environment' support to `defmacro*'. | |
76 ;; * Added destructuring to `loop', and added the following clauses: | |
77 ;; `elements', `frames', `overlays', `intervals', `buffers', `key-seqs'. | |
78 ;; * Renamed `delete' to `delete*' and `remove' to `remove*'. | |
79 ;; * Completed support for all keywords in `remove*', `substitute', etc. | |
80 ;; * Added `most-positive-float' and company. | |
81 ;; * Fixed hash tables to work with latest Lucid Emacs. | |
82 ;; * `proclaim' forms are no longer compile-time-evaluating; use `declaim'. | |
83 ;; * Syntax for `warn' declarations has changed. | |
84 ;; * Improved implementation of `random*'. | |
85 ;; * Moved most sequence functions to a new file, cl-seq.el. | |
86 ;; * Moved `eval-when' into cl-macs.el. | |
87 ;; * Moved `pushnew' and `adjoin' to cl.el for most common cases. | |
88 ;; * Moved `provide' forms down to ends of files. | |
89 ;; * Changed expansion of `pop' to something that compiles to better code. | |
90 ;; * Changed so that no patch is required for Emacs 19 byte compiler. | |
91 ;; * Made more things dependent on `optimize' declarations. | |
92 ;; * Added a partial implementation of struct print functions. | |
93 ;; * Miscellaneous minor changes. | |
94 | |
95 ;; Version 2.00: | |
96 ;; * First public release of this package. | |
97 | |
98 | |
99 ;;; Code: | |
100 | |
101 (defvar cl-emacs-type (cond ((or (and (fboundp 'epoch::version) | |
102 (symbol-value 'epoch::version)) | |
103 (string-lessp emacs-version "19")) 18) | |
104 ((string-match "XEmacs" emacs-version) | |
105 'lucid) | |
106 (t 19))) | |
107 | |
108 (defvar cl-optimize-speed 1) | |
109 (defvar cl-optimize-safety 1) | |
110 | |
111 | |
112 (defvar custom-print-functions nil | |
113 "This is a list of functions that format user objects for printing. | |
114 Each function is called in turn with three arguments: the object, the | |
115 stream, and the print level (currently ignored). If it is able to | |
116 print the object it returns true; otherwise it returns nil and the | |
117 printer proceeds to the next function on the list. | |
118 | |
119 This variable is not used at present, but it is defined in hopes that | |
120 a future Emacs interpreter will be able to use it.") | |
121 | |
122 | |
123 ;;; Predicates. | |
124 | |
125 (defun eql (a b) ; See compiler macro in cl-macs.el | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
126 "Return t if the arguments are the same Lisp object, or numerically equal. |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
127 |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
128 They must be of the same type; the difference between `eq' and `eql' is most |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
129 relevant when it comes to the non-fixnum number types. In this |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
130 implementation, fixnums of the same numeric value are always `eq', but this |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
131 is not true for other numeric types, among them floats, bignums and ratios, |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
132 if available. |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
133 |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
134 See also `=' (which doesn't require that its arguments be of the same type, |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
135 but only accepts numeric arguments, characters and markers) and `equal'." |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
136 (or (eq a b) (and (numberp a) (equal a b)))) |
428 | 137 |
138 ;;; Generalized variables. These macros are defined here so that they | |
139 ;;; can safely be used in .emacs files. | |
140 | |
141 (defmacro incf (place &optional x) | |
3343 | 142 "Increment PLACE by X (1 by default). |
428 | 143 PLACE may be a symbol, or any generalized variable allowed by `setf'. |
144 The return value is the incremented value of PLACE." | |
145 (if (symbolp place) | |
146 (list 'setq place (if x (list '+ place x) (list '1+ place))) | |
147 ;; XEmacs byte-compiler optimizes (+ FOO 1) to (1+ FOO), so this | |
148 ;; is OK. | |
149 (list 'callf '+ place (or x 1)))) | |
150 | |
151 (defmacro decf (place &optional x) | |
3343 | 152 "Decrement PLACE by X (1 by default). |
428 | 153 PLACE may be a symbol, or any generalized variable allowed by `setf'. |
154 The return value is the decremented value of PLACE." | |
155 (if (symbolp place) | |
156 (list 'setq place (if x (list '- place x) (list '1- place))) | |
157 (list 'callf '- place (or x 1)))) | |
158 | |
159 (defmacro pop (place) | |
3343 | 160 "Remove and return the head of the list stored in PLACE. |
428 | 161 Analogous to (prog1 (car PLACE) (setf PLACE (cdr PLACE))), though more |
162 careful about evaluating each argument only once and in the right order. | |
163 PLACE may be a symbol, or any generalized variable allowed by `setf'." | |
164 (if (symbolp place) | |
165 `(car (prog1 ,place (setq ,place (cdr ,place)))) | |
166 (cl-do-pop place))) | |
167 | |
3343 | 168 (defmacro push (newelt listname) |
3355 | 169 "Add NEWELT at the beginning of the list stored in LISTNAME. |
170 Analogous to (setf LISTNAME (cons NEWELT LISTNAME)), though more careful | |
171 about evaluating each argument only once and in the right order. LISTNAME | |
172 may be a symbol, or any generalized variable allowed by `setf'; that is, it | |
173 does not necessarily have to be a list, though `push' is most often used on | |
174 lists. " | |
3343 | 175 (if (symbolp listname) `(setq ,listname (cons ,newelt ,listname)) |
176 (list 'callf2 'cons newelt listname))) | |
428 | 177 |
3343 | 178 (defmacro pushnew (newelt listname &rest keys) |
3355 | 179 "Add NEWELT at the beginning of LISTNAME, unless it's already in LISTNAME. |
3343 | 180 Like (push NEWELT LISTNAME), except that the list is unmodified if NEWELT is |
181 `eql' to an element already on the list. | |
428 | 182 Keywords supported: :test :test-not :key" |
3343 | 183 (if (symbolp listname) (list 'setq listname |
184 (list* 'adjoin newelt listname keys)) | |
185 (list* 'callf2 'adjoin newelt listname keys))) | |
428 | 186 |
187 (defun cl-set-elt (seq n val) | |
188 (if (listp seq) (setcar (nthcdr n seq) val) (aset seq n val))) | |
189 | |
190 (defun cl-set-nthcdr (n list x) | |
191 (if (<= n 0) x (setcdr (nthcdr (1- n) list) x) list)) | |
192 | |
193 (defun cl-set-buffer-substring (start end val) | |
194 (save-excursion (delete-region start end) | |
195 (goto-char start) | |
196 (insert val) | |
197 val)) | |
198 | |
199 (defun cl-set-substring (str start end val) | |
200 (if end (if (< end 0) (incf end (length str))) | |
201 (setq end (length str))) | |
2136 | 202 (if (< start 0) (incf start (length str))) |
428 | 203 (concat (and (> start 0) (substring str 0 start)) |
204 val | |
205 (and (< end (length str)) (substring str end)))) | |
206 | |
207 | |
208 ;;; Control structures. | |
209 | |
210 ;; The macros `when' and `unless' are so useful that we want them to | |
211 ;; ALWAYS be available. So they've been moved from cl.el to eval.c. | |
212 ;; Note: FSF Emacs moved them to subr.el in FSF 20. | |
213 | |
2153 | 214 (defalias 'cl-map-extents 'map-extents) |
428 | 215 |
216 | |
217 ;;; Blocks and exits. | |
218 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
219 ;; This used to be #'identity, but that didn't preserve multiple values in |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
220 ;; interpreted code. #'and isn't great either, there's no error on too many |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
221 ;; arguments passed to it when interpreted. Fortunately most of the places |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
222 ;; where cl-block-wrapper is called are generated from old, established |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
223 ;; macros, so too many arguments resulting from human error is unlikely; and |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
224 ;; the byte compile handler in cl-macs.el warns if more than one arg is |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
225 ;; passed to it. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
226 (defalias 'cl-block-wrapper 'and) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
227 |
428 | 228 (defalias 'cl-block-throw 'throw) |
229 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
230 ;;; XEmacs; multiple values are in eval.c and cl-macs.el. |
2153 | 231 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
232 ;;; We no longer support `multiple-value-apply', which was ill-conceived to |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
233 ;;; start with, is not specified by Common Lisp, and which nothing uses, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
234 ;;; according to Google Code Search, as of Sat Mar 14 23:31:35 GMT 2009. |
2153 | 235 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3355
diff
changeset
|
236 (make-obsolete 'multiple-value-apply 'multiple-value-call) |
428 | 237 |
238 ;;; Macros. | |
239 | |
240 (defvar cl-macro-environment nil) | |
241 ;; XEmacs: we renamed the internal function to macroexpand-internal | |
242 ;; to avoid doc-file problems. | |
243 (defvar cl-old-macroexpand (prog1 (symbol-function 'macroexpand-internal) | |
244 (defalias 'macroexpand 'cl-macroexpand))) | |
245 | |
246 (defun cl-macroexpand (cl-macro &optional cl-env) | |
247 "Return result of expanding macros at top level of FORM. | |
248 If FORM is not a macro call, it is returned unchanged. | |
249 Otherwise, the macro is expanded and the expansion is considered | |
250 in place of FORM. When a non-macro-call results, it is returned. | |
251 | |
442 | 252 The second optional arg ENVIRONMENT specifies an environment of macro |
428 | 253 definitions to shadow the loaded ones for use in file byte-compilation." |
254 (let ((cl-macro-environment cl-env)) | |
255 (while (progn (setq cl-macro (funcall cl-old-macroexpand cl-macro cl-env)) | |
256 (and (symbolp cl-macro) | |
257 (cdr (assq (symbol-name cl-macro) cl-env)))) | |
258 (setq cl-macro (cadr (assq (symbol-name cl-macro) cl-env)))) | |
259 cl-macro)) | |
260 | |
261 | |
262 ;;; Declarations. | |
263 | |
264 (defvar cl-compiling-file nil) | |
265 (defun cl-compiling-file () | |
266 (or cl-compiling-file | |
267 ;; XEmacs change | |
268 ; (and (boundp 'outbuffer) (bufferp (symbol-value 'outbuffer)) | |
269 ; (equal (buffer-name (symbol-value 'outbuffer)) | |
270 ; " *Compiler Output*")) | |
271 (and (boundp 'byte-compile-outbuffer) | |
272 (bufferp (symbol-value 'byte-compile-outbuffer)) | |
273 (equal (buffer-name (symbol-value 'byte-compile-outbuffer)) | |
274 " *Compiler Output*")) | |
275 )) | |
276 | |
277 (defvar cl-proclaims-deferred nil) | |
278 | |
279 (defun proclaim (spec) | |
280 (if (fboundp 'cl-do-proclaim) (cl-do-proclaim spec t) | |
281 (push spec cl-proclaims-deferred)) | |
282 nil) | |
283 | |
284 (defmacro declaim (&rest specs) | |
285 (let ((body (mapcar (function (lambda (x) (list 'proclaim (list 'quote x)))) | |
286 specs))) | |
287 (if (cl-compiling-file) (list* 'eval-when '(compile load eval) body) | |
288 (cons 'progn body)))) ; avoid loading cl-macs.el for eval-when | |
289 | |
290 | |
291 ;;; Symbols. | |
292 | |
293 (defun cl-random-time () | |
294 (let* ((time (copy-sequence (current-time-string))) (i (length time)) (v 0)) | |
295 (while (>= (decf i) 0) (setq v (+ (* v 3) (aref time i)))) | |
2509 | 296 (if-fboundp 'coerce-number |
297 (coerce-number v 'fixnum) | |
1983 | 298 v))) |
428 | 299 |
300 (defvar *gensym-counter* (* (logand (cl-random-time) 1023) 100)) | |
301 | |
2153 | 302 ;; XEmacs change: gensym and gentemp moved here from cl-macs.el |
442 | 303 (defun gensym (&optional arg) |
304 "Generate a new uninterned symbol. | |
2071 | 305 The name is made by appending a number to a prefix. If ARG is a string, it |
306 is the prefix, otherwise the prefix defaults to \"G\". If ARG is an integer, | |
307 the internal counter is reset to that number before creating the name. | |
308 There is no way to specify both using this function." | |
442 | 309 (let ((prefix (if (stringp arg) arg "G")) |
310 (num (if (integerp arg) arg | |
311 (prog1 *gensym-counter* | |
312 (setq *gensym-counter* (1+ *gensym-counter*)))))) | |
313 (make-symbol (format "%s%d" prefix num)))) | |
314 | |
315 (defun gentemp (&optional arg) | |
316 "Generate a new interned symbol with a unique name. | |
2071 | 317 The name is made by appending a number to ARG, default \"G\". |
318 If ARG is not a string, it is ignored." | |
442 | 319 (let ((prefix (if (stringp arg) arg "G")) |
320 name) | |
321 (while (intern-soft (setq name (format "%s%d" prefix *gensym-counter*))) | |
322 (setq *gensym-counter* (1+ *gensym-counter*))) | |
323 (intern name))) | |
428 | 324 |
325 ;;; Numbers. | |
326 | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
327 ;; XEmacs change: ditch floatp-safe. |
428 | 328 |
446 | 329 (defun plusp (number) |
428 | 330 "Return t if NUMBER is positive." |
446 | 331 (> number 0)) |
332 | |
333 (defun minusp (number) | |
334 "Return t if NUMBER is negative." | |
335 (< number 0)) | |
428 | 336 |
446 | 337 (defun oddp (integer) |
428 | 338 "Return t if INTEGER is odd." |
446 | 339 (eq (logand integer 1) 1)) |
428 | 340 |
446 | 341 (defun evenp (integer) |
428 | 342 "Return t if INTEGER is even." |
446 | 343 (eq (logand integer 1) 0)) |
428 | 344 |
2153 | 345 ;; XEmacs addition |
346 (defalias 'cl-abs 'abs) | |
428 | 347 |
348 (defvar *random-state* (vector 'cl-random-state-tag -1 30 (cl-random-time))) | |
349 | |
350 ;;; The following are set by code in cl-extra.el | |
351 (defconst most-positive-float nil | |
352 "The float closest in value to positive infinity.") | |
353 (defconst most-negative-float nil | |
354 "The float closest in value to negative infinity.") | |
355 (defconst least-positive-float nil | |
356 "The positive float closest in value to 0.") | |
357 (defconst least-negative-float nil | |
358 "The negative float closest in value to 0.") | |
359 (defconst least-positive-normalized-float nil) | |
360 (defconst least-negative-normalized-float nil) | |
361 (defconst float-epsilon nil) | |
362 (defconst float-negative-epsilon nil) | |
363 | |
364 | |
365 ;;; Sequence functions. | |
366 | |
367 (defalias 'copy-seq 'copy-sequence) | |
368 | |
2153 | 369 (defalias 'svref 'aref) |
428 | 370 |
371 ;;; List functions. | |
372 | |
373 ;; These functions are made known to the byte-compiler by cl-macs.el | |
374 ;; and turned into efficient car and cdr bytecodes. | |
375 | |
376 (defalias 'first 'car) | |
377 (defalias 'rest 'cdr) | |
378 (defalias 'endp 'null) | |
379 | |
2153 | 380 ;; XEmacs change: make it a real function |
428 | 381 (defun second (x) |
382 "Return the second element of the list LIST." | |
383 (car (cdr x))) | |
384 | |
385 (defun third (x) | |
2153 | 386 "Return the third element of the list X." |
428 | 387 (car (cdr (cdr x)))) |
388 | |
389 (defun fourth (x) | |
2153 | 390 "Return the fourth element of the list X." |
428 | 391 (nth 3 x)) |
392 | |
393 (defun fifth (x) | |
2153 | 394 "Return the fifth element of the list X." |
428 | 395 (nth 4 x)) |
396 | |
397 (defun sixth (x) | |
2153 | 398 "Return the sixth element of the list X." |
428 | 399 (nth 5 x)) |
400 | |
401 (defun seventh (x) | |
2153 | 402 "Return the seventh element of the list X." |
428 | 403 (nth 6 x)) |
404 | |
405 (defun eighth (x) | |
2153 | 406 "Return the eighth element of the list X." |
428 | 407 (nth 7 x)) |
408 | |
409 (defun ninth (x) | |
2153 | 410 "Return the ninth element of the list X." |
428 | 411 (nth 8 x)) |
412 | |
413 (defun tenth (x) | |
2153 | 414 "Return the tenth element of the list X." |
428 | 415 (nth 9 x)) |
416 | |
2153 | 417 ;; XEmacs change: Emacs defines caar, cadr, cdar, and cddr in subr.el. |
428 | 418 (defun caar (x) |
419 "Return the `car' of the `car' of X." | |
420 (car (car x))) | |
421 | |
422 (defun cadr (x) | |
423 "Return the `car' of the `cdr' of X." | |
424 (car (cdr x))) | |
425 | |
426 (defun cdar (x) | |
427 "Return the `cdr' of the `car' of X." | |
428 (cdr (car x))) | |
429 | |
430 (defun cddr (x) | |
431 "Return the `cdr' of the `cdr' of X." | |
432 (cdr (cdr x))) | |
433 | |
434 (defun caaar (x) | |
435 "Return the `car' of the `car' of the `car' of X." | |
436 (car (car (car x)))) | |
437 | |
438 (defun caadr (x) | |
439 "Return the `car' of the `car' of the `cdr' of X." | |
440 (car (car (cdr x)))) | |
441 | |
442 (defun cadar (x) | |
443 "Return the `car' of the `cdr' of the `car' of X." | |
444 (car (cdr (car x)))) | |
445 | |
446 (defun caddr (x) | |
447 "Return the `car' of the `cdr' of the `cdr' of X." | |
448 (car (cdr (cdr x)))) | |
449 | |
450 (defun cdaar (x) | |
451 "Return the `cdr' of the `car' of the `car' of X." | |
452 (cdr (car (car x)))) | |
453 | |
454 (defun cdadr (x) | |
455 "Return the `cdr' of the `car' of the `cdr' of X." | |
456 (cdr (car (cdr x)))) | |
457 | |
458 (defun cddar (x) | |
459 "Return the `cdr' of the `cdr' of the `car' of X." | |
460 (cdr (cdr (car x)))) | |
461 | |
462 (defun cdddr (x) | |
463 "Return the `cdr' of the `cdr' of the `cdr' of X." | |
464 (cdr (cdr (cdr x)))) | |
465 | |
466 (defun caaaar (x) | |
467 "Return the `car' of the `car' of the `car' of the `car' of X." | |
468 (car (car (car (car x))))) | |
469 | |
470 (defun caaadr (x) | |
471 "Return the `car' of the `car' of the `car' of the `cdr' of X." | |
472 (car (car (car (cdr x))))) | |
473 | |
474 (defun caadar (x) | |
475 "Return the `car' of the `car' of the `cdr' of the `car' of X." | |
476 (car (car (cdr (car x))))) | |
477 | |
478 (defun caaddr (x) | |
479 "Return the `car' of the `car' of the `cdr' of the `cdr' of X." | |
480 (car (car (cdr (cdr x))))) | |
481 | |
482 (defun cadaar (x) | |
483 "Return the `car' of the `cdr' of the `car' of the `car' of X." | |
484 (car (cdr (car (car x))))) | |
485 | |
486 (defun cadadr (x) | |
487 "Return the `car' of the `cdr' of the `car' of the `cdr' of X." | |
488 (car (cdr (car (cdr x))))) | |
489 | |
490 (defun caddar (x) | |
491 "Return the `car' of the `cdr' of the `cdr' of the `car' of X." | |
492 (car (cdr (cdr (car x))))) | |
493 | |
494 (defun cadddr (x) | |
495 "Return the `car' of the `cdr' of the `cdr' of the `cdr' of X." | |
496 (car (cdr (cdr (cdr x))))) | |
497 | |
498 (defun cdaaar (x) | |
499 "Return the `cdr' of the `car' of the `car' of the `car' of X." | |
500 (cdr (car (car (car x))))) | |
501 | |
502 (defun cdaadr (x) | |
503 "Return the `cdr' of the `car' of the `car' of the `cdr' of X." | |
504 (cdr (car (car (cdr x))))) | |
505 | |
506 (defun cdadar (x) | |
507 "Return the `cdr' of the `car' of the `cdr' of the `car' of X." | |
508 (cdr (car (cdr (car x))))) | |
509 | |
510 (defun cdaddr (x) | |
511 "Return the `cdr' of the `car' of the `cdr' of the `cdr' of X." | |
512 (cdr (car (cdr (cdr x))))) | |
513 | |
514 (defun cddaar (x) | |
515 "Return the `cdr' of the `cdr' of the `car' of the `car' of X." | |
516 (cdr (cdr (car (car x))))) | |
517 | |
518 (defun cddadr (x) | |
519 "Return the `cdr' of the `cdr' of the `car' of the `cdr' of X." | |
520 (cdr (cdr (car (cdr x))))) | |
521 | |
522 (defun cdddar (x) | |
523 "Return the `cdr' of the `cdr' of the `cdr' of the `car' of X." | |
524 (cdr (cdr (cdr (car x))))) | |
525 | |
526 (defun cddddr (x) | |
527 "Return the `cdr' of the `cdr' of the `cdr' of the `cdr' of X." | |
528 (cdr (cdr (cdr (cdr x))))) | |
529 | |
530 ;;; `last' is implemented as a C primitive, as of 1998-11 | |
2153 | 531 ;;(defun last* (x &optional n) |
532 ;; "Returns the last link in the list LIST. | |
533 ;;With optional argument N, returns Nth-to-last link (default 1)." | |
534 ;; (if n | |
535 ;; (let ((m 0) (p x)) | |
536 ;; (while (consp p) (incf m) (pop p)) | |
537 ;; (if (<= n 0) p | |
538 ;; (if (< n m) (nthcdr (- m n) x) x))) | |
539 ;; (while (consp (cdr x)) (pop x)) | |
540 ;; x)) | |
428 | 541 |
542 (defun list* (arg &rest rest) ; See compiler macro in cl-macs.el | |
543 "Return a new list with specified args as elements, cons'd to last arg. | |
544 Thus, `(list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to | |
545 `(cons A (cons B (cons C D)))'." | |
546 (cond ((not rest) arg) | |
547 ((not (cdr rest)) (cons arg (car rest))) | |
548 (t (let* ((n (length rest)) | |
549 (copy (copy-sequence rest)) | |
550 (last (nthcdr (- n 2) copy))) | |
551 (setcdr last (car (cdr last))) | |
552 (cons arg copy))))) | |
553 | |
554 (defun ldiff (list sublist) | |
555 "Return a copy of LIST with the tail SUBLIST removed." | |
556 (let ((res nil)) | |
557 (while (and (consp list) (not (eq list sublist))) | |
558 (push (pop list) res)) | |
559 (nreverse res))) | |
560 | |
561 ;;; `copy-list' is implemented as a C primitive, as of 1998-11 | |
562 | |
563 ;(defun copy-list (list) | |
564 ; "Return a copy of a list, which may be a dotted list. | |
565 ;The elements of the list are not copied, just the list structure itself." | |
566 ; (if (consp list) | |
567 ; (let ((res nil)) | |
568 ; (while (consp list) (push (pop list) res)) | |
569 ; (prog1 (nreverse res) (setcdr res list))) | |
570 ; (car list))) | |
571 | |
572 (defun cl-maclisp-member (item list) | |
573 (while (and list (not (equal item (car list)))) (setq list (cdr list))) | |
574 list) | |
575 | |
576 (defalias 'cl-member 'memq) ; for compatibility with old CL package | |
577 (defalias 'cl-floor 'floor*) | |
578 (defalias 'cl-ceiling 'ceiling*) | |
579 (defalias 'cl-truncate 'truncate*) | |
580 (defalias 'cl-round 'round*) | |
581 (defalias 'cl-mod 'mod*) | |
582 | |
583 (defun adjoin (cl-item cl-list &rest cl-keys) ; See compiler macro in cl-macs | |
584 "Return ITEM consed onto the front of LIST only if it's not already there. | |
585 Otherwise, return LIST unmodified. | |
586 Keywords supported: :test :test-not :key" | |
587 (cond ((or (equal cl-keys '(:test eq)) | |
588 (and (null cl-keys) (not (numberp cl-item)))) | |
589 (if (memq cl-item cl-list) cl-list (cons cl-item cl-list))) | |
590 ((or (equal cl-keys '(:test equal)) (null cl-keys)) | |
591 (if (member cl-item cl-list) cl-list (cons cl-item cl-list))) | |
592 (t (apply 'cl-adjoin cl-item cl-list cl-keys)))) | |
593 | |
594 (defun subst (cl-new cl-old cl-tree &rest cl-keys) | |
595 "Substitute NEW for OLD everywhere in TREE (non-destructively). | |
596 Return a copy of TREE with all elements `eql' to OLD replaced by NEW. | |
597 Keywords supported: :test :test-not :key" | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
598 (if (or cl-keys (and (numberp cl-old) (not (fixnump cl-old)))) |
428 | 599 (apply 'sublis (list (cons cl-old cl-new)) cl-tree cl-keys) |
600 (cl-do-subst cl-new cl-old cl-tree))) | |
601 | |
602 (defun cl-do-subst (cl-new cl-old cl-tree) | |
603 (cond ((eq cl-tree cl-old) cl-new) | |
604 ((consp cl-tree) | |
605 (let ((a (cl-do-subst cl-new cl-old (car cl-tree))) | |
606 (d (cl-do-subst cl-new cl-old (cdr cl-tree)))) | |
607 (if (and (eq a (car cl-tree)) (eq d (cdr cl-tree))) | |
608 cl-tree (cons a d)))) | |
609 (t cl-tree))) | |
610 | |
611 (defun acons (a b c) | |
612 "Return a new alist created by adding (KEY . VALUE) to ALIST." | |
613 (cons (cons a b) c)) | |
614 | |
615 (defun pairlis (a b &optional c) (nconc (mapcar* 'cons a b) c)) | |
616 | |
617 | |
618 ;;; Miscellaneous. | |
619 | |
620 ;; XEmacs change | |
621 (define-error 'cl-assertion-failed "Assertion failed") | |
622 | |
2153 | 623 ;; XEmacs change: omit the autoload rules; we handle those a different way |
428 | 624 |
625 ;;; Define data for indentation and edebug. | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4885
diff
changeset
|
626 (mapc |
428 | 627 #'(lambda (entry) |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4885
diff
changeset
|
628 (mapc |
428 | 629 #'(lambda (func) |
630 (put func 'lisp-indent-function (nth 1 entry)) | |
631 (put func 'lisp-indent-hook (nth 1 entry)) | |
632 (or (get func 'edebug-form-spec) | |
633 (put func 'edebug-form-spec (nth 2 entry)))) | |
634 (car entry))) | |
635 '(((defun* defmacro*) defun) | |
636 ((function*) nil | |
637 (&or symbolp ([&optional 'macro] 'lambda (&rest sexp) &rest form))) | |
638 ((eval-when) 1 (sexp &rest form)) | |
639 ((when unless) 1 (&rest form)) | |
640 ((declare) nil (&rest sexp)) | |
641 ((the) 1 (sexp &rest form)) | |
642 ((case ecase typecase etypecase) 1 (form &rest (sexp &rest form))) | |
643 ((block return-from) 1 (sexp &rest form)) | |
644 ((return) nil (&optional form)) | |
645 ((do do*) 2 ((&rest &or symbolp (symbolp &optional form form)) | |
646 (form &rest form) | |
647 &rest form)) | |
648 ((dolist dotimes) 1 ((symbolp form &rest form) &rest form)) | |
649 ((do-symbols) 1 ((symbolp form &optional form form) &rest form)) | |
650 ((do-all-symbols) 1 ((symbolp form &optional form) &rest form)) | |
651 ((psetq setf psetf) nil edebug-setq-form) | |
652 ((progv) 2 (&rest form)) | |
653 ((flet labels macrolet) 1 | |
654 ((&rest (sexp sexp &rest form)) &rest form)) | |
655 ((symbol-macrolet lexical-let lexical-let*) 1 | |
656 ((&rest &or symbolp (symbolp form)) &rest form)) | |
657 ((multiple-value-bind) 2 ((&rest symbolp) &rest form)) | |
658 ((multiple-value-setq) 1 ((&rest symbolp) &rest form)) | |
659 ((incf decf remf pop push pushnew shiftf rotatef) nil (&rest form)) | |
660 ((letf letf*) 1 ((&rest (&rest form)) &rest form)) | |
661 ((callf destructuring-bind) 2 (sexp form &rest form)) | |
662 ((callf2) 3 (sexp form form &rest form)) | |
663 ((loop) defun (&rest &or symbolp form)) | |
664 ((ignore-errors) 0 (&rest form)))) | |
665 | |
666 | |
667 ;;; This goes here so that cl-macs can find it if it loads right now. | |
668 (provide 'cl-19) ; usage: (require 'cl-19 "cl") | |
669 | |
670 | |
671 ;;; Things to do after byte-compiler is loaded. | |
672 ;;; As a side effect, we cause cl-macs to be loaded when compiling, so | |
673 ;;; that the compiler-macros defined there will be present. | |
674 | |
675 (defvar cl-hacked-flag nil) | |
676 (defun cl-hack-byte-compiler () | |
677 (if (and (not cl-hacked-flag) (fboundp 'byte-compile-file-form)) | |
678 (progn | |
2153 | 679 (setq cl-hacked-flag t) ; Do it first, to prevent recursion. |
442 | 680 (when (not (fboundp 'cl-compile-time-init)) |
681 (load "cl-macs" nil t)) | |
2153 | 682 (cl-compile-time-init)))) ; In cl-macs.el. |
428 | 683 |
684 ;;; Try it now in case the compiler has already been loaded. | |
685 (cl-hack-byte-compiler) | |
686 | |
4683
0cc9d22c3732
Be more reliable about loading cl-macs at byte-compile time, cl.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
687 ;;; Also make a hook in case compiler is loaded after this file. |
0cc9d22c3732
Be more reliable about loading cl-macs at byte-compile time, cl.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
688 (add-hook 'bytecomp-load-hook 'cl-hack-byte-compiler) |
428 | 689 |
690 ;;; The following ensures that packages which expect the old-style cl.el | |
691 ;;; will be happy with this one. | |
692 | |
693 (provide 'cl) | |
694 | |
695 (run-hooks 'cl-load-hook) | |
696 | |
2153 | 697 ;;; arch-tag: 5f07fa74-f153-4524-9303-21f5be125851 |
428 | 698 ;;; cl.el ends here |