Mercurial > hg > xemacs-beta
annotate lisp/cl-compat.el @ 4995:8431b52e43b1
Move the various map* functions to C; add #'map-into.
src/ChangeLog addition:
2010-01-31 Aidan Kehoe <kehoea@parhasard.net>
Move #'mapcar*, #'mapcan, #'mapc, #'map, #'mapl, #'mapcon to C;
extend #'mapvector, #'mapconcat, #'mapcar to support more
SEQUENCES; have them all error with circular lists.
* fns.c (Fsubseq): Call CHECK_SEQUENCE here; Flength can return
from the debugger if it errors with a non-sequence, leading to a
crash in Fsubseq if sequence really is *not* a sequence.
(mapcarX): Rename mapcar1 to mapcarX; rework it comprehensively to
take an optional lisp output argument, and a varying number of
sequences.
Special-case a single list argument, as we used to, saving its
elements in the stack space for the results before calling
FUNCTION, so FUNCTION can corrupt the list all it
wants. dead_wrong_type_argument() in the other cases if we
encounter a non-cons where we expected a cons.
(Fmapconcat):
Accept further SEQUENCES after separator here. Special-case
the idiom (mapconcat 'identity SEQUENCE), don't even funcall.
(FmapcarX): Rename this from Fmapcar. Accept optional SEQUENCES.
(Fmapvector): Accept optional SEQUENCES.
(Fmapcan, Fmapc, Fmap): Move these here from cl-extra.el.
(Fmap_into): New function, as specified by Common Lisp.
(maplist): New function, the guts of the implementation of
Fmaplist and Fmapl.
(Fmaplist, Fmapl, Fmapcon): Move these from cl-extra.el.
(syms_of_fns):
Add a few needed symbols here, for the type tests
used by #'map. Add the new subrs, with aliases for #'mapc-internal
and #'mapcar.
* general-slots.h: Declare Qcoerce here, now it's used in both
indent.c and fns.c
* indent.c (syms_of_indent): Qcoerce is gone from here.
* lisp.h: Add ARRAYP(), SEQUENCEP(), and the corresponding CHECK_*
macros. Declare Fbit_vector, Fstring, FmapcarX, now other files
need to use them.
* data.c (Farrayp, Fsequencep): Use ARRAYP and SEQUENCEP, just
added to lisp.h
* buffer.c (Fbuffer_list): Now Fmapcar has been renamed FmapcarX
and takes MANY arguments, update this function to reflect that.
lisp/ChangeLog addition:
2010-01-31 Aidan Kehoe <kehoea@parhasard.net>
* cl.el (mapcar*): Delete; this is now in fns.c.
Use #'mapc, not #'mapc-internal in a couple of places.
* cl-macs.el (mapc, mapcar*, map): Delete these compiler macros
now the corresponding functions are in fns.c; there's no run-time
advantage to the macros.
* cl-extra.el (coerce): Extend the possible conversions here a
little; it's not remotely comprehensive yet, though it does allow
running slightly more Common Lisp code than previously.
(cl-mapcar-many): Delete.
(map, maplist, mapc, mapl, mapcan, mapcon): Move these to fns.c.
* bytecomp.el (byte-compile-maybe-mapc):
Use #'mapc itself, not #'mapc-internal, now the former is in C.
(mapcar*): Use #'byte-compile-maybe-mapc as this function's
byte-compile method, now a #'mapc that can take more than one
sequence is in C.
* obsolete.el (cl-mapc): Move this compatibility alias to this file.
* update-elc.el (do-autoload-commands): Use #'mapc, not
#'mapc-internal here.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 31 Jan 2010 18:29:48 +0000 |
parents | 8b50bee3c88c |
children | 2a54dfbe434f 308d34e9f07d |
rev | line source |
---|---|
613 | 1 ;;; cl-compat.el --- Common Lisp extensions for XEmacs Lisp (compatibility) |
209 | 2 |
3 ;; Copyright (C) 1993 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Dave Gillespie <daveg@synaptics.com> | |
6 ;; Version: 2.02 | |
7 ;; Keywords: extensions | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | |
12 ;; under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; XEmacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
24 ;; 02111-1307, USA. | |
25 | |
2153 | 26 ;;; Synched up with: FSF 21.3. |
209 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; These are extensions to Emacs Lisp that provide a degree of | |
31 ;; Common Lisp compatibility, beyond what is already built-in | |
32 ;; in Emacs Lisp. | |
33 ;; | |
34 ;; This package was written by Dave Gillespie; it is a complete | |
35 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
36 ;; | |
37 ;; This package works with Emacs 18, Emacs 19, and XEmacs/Lucid Emacs 19. | |
38 ;; | |
39 ;; Bug reports, comments, and suggestions are welcome! | |
40 | |
41 ;; This file contains emulations of internal routines of the older | |
42 ;; CL package which users may have called directly from their code. | |
43 ;; Use (require 'cl-compat) to get these routines. | |
44 | |
45 ;; See cl.el for Change Log. | |
46 | |
47 | |
48 ;;; Code: | |
49 | |
50 ;; Require at load-time, but not when compiling cl-compat. | |
51 (or (featurep 'cl) (require 'cl)) | |
52 | |
53 | |
54 ;;; Keyword routines not supported by new package. | |
55 | |
56 (defmacro defkeyword (x &optional doc) | |
57 (list* 'defconst x (list 'quote x) (and doc (list doc)))) | |
58 | |
59 (defun keyword-of (sym) | |
4793
8b50bee3c88c
Remove attempted support for 1996-era emacs without self-quoting keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4678
diff
changeset
|
60 (or (keywordp sym) (keywordp (read (format ":%s" sym))))) |
209 | 61 |
62 ;;; Routines for parsing keyword arguments. | |
63 | |
64 (defun build-klist (arglist keys &optional allow-others) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
65 (let ((res (multiple-value-call 'mapcar* 'cons (unzip-lists arglist)))) |
209 | 66 (or allow-others |
67 (let ((bad (set-difference (mapcar 'car res) keys))) | |
68 (if bad (error "Bad keywords: %s not in %s" bad keys)))) | |
69 res)) | |
70 | |
71 (defun extract-from-klist (klist key &optional def) | |
72 (let ((res (assq key klist))) (if res (cdr res) def))) | |
73 | |
74 (defun keyword-argument-supplied-p (klist key) | |
75 (assq key klist)) | |
76 | |
77 (defun elt-satisfies-test-p (item elt klist) | |
78 (let ((test-not (cdr (assq ':test-not klist))) | |
79 (test (cdr (assq ':test klist))) | |
80 (key (cdr (assq ':key klist)))) | |
81 (if key (setq elt (funcall key elt))) | |
82 (if test-not (not (funcall test-not item elt)) | |
83 (funcall (or test 'eql) item elt)))) | |
84 | |
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
85 ;; The rounding functions in C now have all the functionality this package |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
86 ;; used to: |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
87 (loop |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
88 for symbol in '(floor ceiling round truncate) |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
89 do (defalias (intern (format "cl-%s" symbol)) symbol)) |
209 | 90 |
91 (defun safe-idiv (a b) | |
92 (let* ((q (/ (abs a) (abs b))) | |
93 (s (* (signum a) (signum b)))) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
94 (values q (- a (* s q b)) s))) |
209 | 95 |
96 ;; Internal routines. | |
97 | |
98 (defun pair-with-newsyms (oldforms) | |
99 (let ((newsyms (mapcar (function (lambda (x) (gensym))) oldforms))) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
100 (values (mapcar* 'list newsyms oldforms) newsyms))) |
209 | 101 |
102 (defun zip-lists (evens odds) | |
103 (mapcan 'list evens odds)) | |
104 | |
105 (defun unzip-lists (list) | |
106 (let ((e nil) (o nil)) | |
107 (while list | |
108 (setq e (cons (car list) e) o (cons (cadr list) o) list (cddr list))) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
109 (values (nreverse e) (nreverse o)))) |
209 | 110 |
111 (defun reassemble-argslists (list) | |
112 (let ((n (apply 'min (mapcar 'length list))) (res nil)) | |
113 (while (>= (setq n (1- n)) 0) | |
114 (setq res (cons (mapcar (function (lambda (x) (elt x n))) list) res))) | |
115 res)) | |
116 | |
117 (defun duplicate-symbols-p (list) | |
118 (let ((res nil)) | |
119 (while list | |
120 (if (memq (car list) (cdr list)) (setq res (cons (car list) res))) | |
121 (setq list (cdr list))) | |
122 res)) | |
123 | |
124 | |
125 ;;; Setf internals. | |
126 | |
127 (defun setnth (n list x) | |
128 (setcar (nthcdr n list) x)) | |
129 | |
130 (defun setnthcdr (n list x) | |
131 (setcdr (nthcdr (1- n) list) x)) | |
132 | |
133 (defun setelt (seq n x) | |
134 (if (consp seq) (setcar (nthcdr n seq) x) (aset seq n x))) | |
135 | |
136 | |
137 ;;; Functions omitted: case-clausify, check-do-stepforms, check-do-endforms, | |
138 ;;; extract-do-inits, extract-do[*]-steps, select-stepping-forms, | |
139 ;;; elt-satisfies-if[-not]-p, with-keyword-args, mv-bind-clausify, | |
140 ;;; all names with embedded `$'. | |
141 | |
142 | |
143 (provide 'cl-compat) | |
144 | |
2153 | 145 ;;; arch-tag: 9996bb4f-aaf5-4592-b436-bf64759a3163 |
209 | 146 ;;; cl-compat.el ends here |