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