Mercurial > hg > xemacs-beta
annotate src/fns.c @ 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 | a5eca70cf401 |
children | c17c857e20bf |
rev | line source |
---|---|
428 | 1 /* Random utility Lisp functions. |
2 Copyright (C) 1985, 86, 87, 93, 94, 95 Free Software Foundation, Inc. | |
1261 | 3 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Mule 2.0, FSF 19.30. */ | |
23 | |
24 /* This file has been Mule-ized. */ | |
25 | |
26 /* Note: FSF 19.30 has bool vectors. We have bit vectors. */ | |
27 | |
28 /* Hacked on for Mule by Ben Wing, December 1994, January 1995. */ | |
29 | |
30 #include <config.h> | |
31 | |
32 /* Note on some machines this defines `vector' as a typedef, | |
33 so make sure we don't use that name in this file. */ | |
34 #undef vector | |
35 #define vector ***** | |
36 | |
37 #include "lisp.h" | |
38 | |
442 | 39 #include "sysfile.h" |
771 | 40 #include "sysproc.h" /* for qxe_getpid() */ |
428 | 41 |
42 #include "buffer.h" | |
43 #include "bytecode.h" | |
44 #include "device.h" | |
45 #include "events.h" | |
46 #include "extents.h" | |
47 #include "frame.h" | |
872 | 48 #include "process.h" |
428 | 49 #include "systime.h" |
50 #include "insdel.h" | |
51 #include "lstream.h" | |
52 #include "opaque.h" | |
53 | |
54 /* NOTE: This symbol is also used in lread.c */ | |
55 #define FEATUREP_SYNTAX | |
56 | |
57 Lisp_Object Qstring_lessp; | |
58 Lisp_Object Qidentity; | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
59 Lisp_Object Qvector, Qarray, Qstring, Qlist, Qbit_vector; |
428 | 60 |
563 | 61 Lisp_Object Qbase64_conversion_error; |
62 | |
771 | 63 Lisp_Object Vpath_separator; |
64 | |
428 | 65 static int internal_old_equal (Lisp_Object, Lisp_Object, int); |
454 | 66 Lisp_Object safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth); |
428 | 67 |
68 static Lisp_Object | |
2286 | 69 mark_bit_vector (Lisp_Object UNUSED (obj)) |
428 | 70 { |
71 return Qnil; | |
72 } | |
73 | |
74 static void | |
2286 | 75 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, |
76 int UNUSED (escapeflag)) | |
428 | 77 { |
665 | 78 Elemcount i; |
440 | 79 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); |
665 | 80 Elemcount len = bit_vector_length (v); |
81 Elemcount last = len; | |
428 | 82 |
83 if (INTP (Vprint_length)) | |
84 last = min (len, XINT (Vprint_length)); | |
826 | 85 write_c_string (printcharfun, "#*"); |
428 | 86 for (i = 0; i < last; i++) |
87 { | |
88 if (bit_vector_bit (v, i)) | |
826 | 89 write_c_string (printcharfun, "1"); |
428 | 90 else |
826 | 91 write_c_string (printcharfun, "0"); |
428 | 92 } |
93 | |
94 if (last != len) | |
826 | 95 write_c_string (printcharfun, "..."); |
428 | 96 } |
97 | |
98 static int | |
2286 | 99 bit_vector_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth)) |
428 | 100 { |
440 | 101 Lisp_Bit_Vector *v1 = XBIT_VECTOR (obj1); |
102 Lisp_Bit_Vector *v2 = XBIT_VECTOR (obj2); | |
428 | 103 |
104 return ((bit_vector_length (v1) == bit_vector_length (v2)) && | |
105 !memcmp (v1->bits, v2->bits, | |
106 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) * | |
107 sizeof (long))); | |
108 } | |
109 | |
665 | 110 static Hashcode |
2286 | 111 bit_vector_hash (Lisp_Object obj, int UNUSED (depth)) |
428 | 112 { |
440 | 113 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); |
428 | 114 return HASH2 (bit_vector_length (v), |
115 memory_hash (v->bits, | |
116 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) * | |
117 sizeof (long))); | |
118 } | |
119 | |
665 | 120 static Bytecount |
442 | 121 size_bit_vector (const void *lheader) |
122 { | |
123 Lisp_Bit_Vector *v = (Lisp_Bit_Vector *) lheader; | |
456 | 124 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, unsigned long, bits, |
442 | 125 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v))); |
126 } | |
127 | |
1204 | 128 static const struct memory_description bit_vector_description[] = { |
428 | 129 { XD_END } |
130 }; | |
131 | |
132 | |
1204 | 133 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("bit-vector", bit_vector, |
134 1, /*dumpable-flag*/ | |
135 mark_bit_vector, | |
136 print_bit_vector, 0, | |
137 bit_vector_equal, | |
138 bit_vector_hash, | |
139 bit_vector_description, | |
140 size_bit_vector, | |
141 Lisp_Bit_Vector); | |
934 | 142 |
428 | 143 |
144 DEFUN ("identity", Fidentity, 1, 1, 0, /* | |
145 Return the argument unchanged. | |
146 */ | |
147 (arg)) | |
148 { | |
149 return arg; | |
150 } | |
151 | |
152 DEFUN ("random", Frandom, 0, 1, 0, /* | |
153 Return a pseudo-random number. | |
1983 | 154 All fixnums are equally likely. On most systems, this is 31 bits' worth. |
428 | 155 With positive integer argument N, return random number in interval [0,N). |
1983 | 156 N can be a bignum, in which case the range of possible values is extended. |
428 | 157 With argument t, set the random number seed from the current time and pid. |
158 */ | |
159 (limit)) | |
160 { | |
161 EMACS_INT val; | |
162 unsigned long denominator; | |
163 | |
164 if (EQ (limit, Qt)) | |
771 | 165 seed_random (qxe_getpid () + time (NULL)); |
428 | 166 if (NATNUMP (limit) && !ZEROP (limit)) |
167 { | |
168 /* Try to take our random number from the higher bits of VAL, | |
169 not the lower, since (says Gentzel) the low bits of `random' | |
170 are less random than the higher ones. We do this by using the | |
171 quotient rather than the remainder. At the high end of the RNG | |
172 it's possible to get a quotient larger than limit; discarding | |
173 these values eliminates the bias that would otherwise appear | |
174 when using a large limit. */ | |
2039 | 175 denominator = ((unsigned long)1 << INT_VALBITS) / XINT (limit); |
428 | 176 do |
177 val = get_random () / denominator; | |
178 while (val >= XINT (limit)); | |
179 } | |
1983 | 180 #ifdef HAVE_BIGNUM |
181 else if (BIGNUMP (limit)) | |
182 { | |
183 bignum_random (scratch_bignum, XBIGNUM_DATA (limit)); | |
184 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
185 } | |
186 #endif | |
428 | 187 else |
188 val = get_random (); | |
189 | |
190 return make_int (val); | |
191 } | |
192 | |
193 /* Random data-structure functions */ | |
194 | |
195 #ifdef LOSING_BYTECODE | |
196 | |
197 /* #### Delete this shit */ | |
198 | |
199 /* Charcount is a misnomer here as we might be dealing with the | |
200 length of a vector or list, but emphasizes that we're not dealing | |
201 with Bytecounts in strings */ | |
202 static Charcount | |
203 length_with_bytecode_hack (Lisp_Object seq) | |
204 { | |
205 if (!COMPILED_FUNCTIONP (seq)) | |
206 return XINT (Flength (seq)); | |
207 else | |
208 { | |
440 | 209 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (seq); |
428 | 210 |
211 return (f->flags.interactivep ? COMPILED_INTERACTIVE : | |
212 f->flags.domainp ? COMPILED_DOMAIN : | |
213 COMPILED_DOC_STRING) | |
214 + 1; | |
215 } | |
216 } | |
217 | |
218 #endif /* LOSING_BYTECODE */ | |
219 | |
220 void | |
442 | 221 check_losing_bytecode (const char *function, Lisp_Object seq) |
428 | 222 { |
223 if (COMPILED_FUNCTIONP (seq)) | |
563 | 224 signal_ferror_with_frob |
225 (Qinvalid_argument, seq, | |
428 | 226 "As of 20.3, `%s' no longer works with compiled-function objects", |
227 function); | |
228 } | |
229 | |
230 DEFUN ("length", Flength, 1, 1, 0, /* | |
231 Return the length of vector, bit vector, list or string SEQUENCE. | |
232 */ | |
233 (sequence)) | |
234 { | |
235 retry: | |
236 if (STRINGP (sequence)) | |
826 | 237 return make_int (string_char_length (sequence)); |
428 | 238 else if (CONSP (sequence)) |
239 { | |
665 | 240 Elemcount len; |
428 | 241 GET_EXTERNAL_LIST_LENGTH (sequence, len); |
242 return make_int (len); | |
243 } | |
244 else if (VECTORP (sequence)) | |
245 return make_int (XVECTOR_LENGTH (sequence)); | |
246 else if (NILP (sequence)) | |
247 return Qzero; | |
248 else if (BIT_VECTORP (sequence)) | |
249 return make_int (bit_vector_length (XBIT_VECTOR (sequence))); | |
250 else | |
251 { | |
252 check_losing_bytecode ("length", sequence); | |
253 sequence = wrong_type_argument (Qsequencep, sequence); | |
254 goto retry; | |
255 } | |
256 } | |
257 | |
258 DEFUN ("safe-length", Fsafe_length, 1, 1, 0, /* | |
259 Return the length of a list, but avoid error or infinite loop. | |
260 This function never gets an error. If LIST is not really a list, | |
261 it returns 0. If LIST is circular, it returns a finite value | |
262 which is at least the number of distinct elements. | |
263 */ | |
264 (list)) | |
265 { | |
266 Lisp_Object hare, tortoise; | |
665 | 267 Elemcount len; |
428 | 268 |
269 for (hare = tortoise = list, len = 0; | |
270 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); | |
271 hare = XCDR (hare), len++) | |
272 { | |
273 if (len & 1) | |
274 tortoise = XCDR (tortoise); | |
275 } | |
276 | |
277 return make_int (len); | |
278 } | |
279 | |
280 /*** string functions. ***/ | |
281 | |
282 DEFUN ("string-equal", Fstring_equal, 2, 2, 0, /* | |
283 Return t if two strings have identical contents. | |
284 Case is significant. Text properties are ignored. | |
285 \(Under XEmacs, `equal' also ignores text properties and extents in | |
286 strings, but this is not the case under FSF Emacs 19. In FSF Emacs 20 | |
287 `equal' is the same as in XEmacs, in that respect.) | |
288 Symbols are also allowed; their print names are used instead. | |
289 */ | |
444 | 290 (string1, string2)) |
428 | 291 { |
292 Bytecount len; | |
793 | 293 Lisp_Object p1, p2; |
428 | 294 |
444 | 295 if (SYMBOLP (string1)) |
296 p1 = XSYMBOL (string1)->name; | |
428 | 297 else |
298 { | |
444 | 299 CHECK_STRING (string1); |
793 | 300 p1 = string1; |
428 | 301 } |
302 | |
444 | 303 if (SYMBOLP (string2)) |
304 p2 = XSYMBOL (string2)->name; | |
428 | 305 else |
306 { | |
444 | 307 CHECK_STRING (string2); |
793 | 308 p2 = string2; |
428 | 309 } |
310 | |
793 | 311 return (((len = XSTRING_LENGTH (p1)) == XSTRING_LENGTH (p2)) && |
312 !memcmp (XSTRING_DATA (p1), XSTRING_DATA (p2), len)) ? Qt : Qnil; | |
428 | 313 } |
314 | |
801 | 315 DEFUN ("compare-strings", Fcompare_strings, 6, 7, 0, /* |
316 Compare the contents of two strings, maybe ignoring case. | |
317 In string STR1, skip the first START1 characters and stop at END1. | |
318 In string STR2, skip the first START2 characters and stop at END2. | |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
319 END1 and END2 default to the full lengths of the respective strings, |
4797
a5eca70cf401
Fix typo in last patch.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4796
diff
changeset
|
320 and arguments that are outside the string (negative STARTi or ENDi |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
321 greater than length) are coerced to 0 or string length as appropriate. |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
322 |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
323 Optional IGNORE-CASE non-nil means use case-insensitive comparison. |
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
324 Case is significant by default. |
801 | 325 |
326 The value is t if the strings (or specified portions) match. | |
327 If string STR1 is less, the value is a negative number N; | |
328 - 1 - N is the number of characters that match at the beginning. | |
329 If string STR1 is greater, the value is a positive number N; | |
330 N - 1 is the number of characters that match at the beginning. | |
331 */ | |
332 (str1, start1, end1, str2, start2, end2, ignore_case)) | |
333 { | |
334 Charcount ccstart1, ccend1, ccstart2, ccend2; | |
335 Bytecount bstart1, blen1, bstart2, blen2; | |
336 Charcount matching; | |
337 int res; | |
338 | |
339 CHECK_STRING (str1); | |
340 CHECK_STRING (str2); | |
341 get_string_range_char (str1, start1, end1, &ccstart1, &ccend1, | |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
342 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 343 get_string_range_char (str2, start2, end2, &ccstart2, &ccend2, |
4796
c45fdd4e1858
Don't args-out-of-range in compare-strings.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4693
diff
changeset
|
344 GB_HISTORICAL_STRING_BEHAVIOR|GB_COERCE_RANGE); |
801 | 345 |
346 bstart1 = string_index_char_to_byte (str1, ccstart1); | |
347 blen1 = string_offset_char_to_byte_len (str1, bstart1, ccend1 - ccstart1); | |
348 bstart2 = string_index_char_to_byte (str2, ccstart2); | |
349 blen2 = string_offset_char_to_byte_len (str2, bstart2, ccend2 - ccstart2); | |
350 | |
351 res = ((NILP (ignore_case) ? qxetextcmp_matching : qxetextcasecmp_matching) | |
352 (XSTRING_DATA (str1) + bstart1, blen1, | |
353 XSTRING_DATA (str2) + bstart2, blen2, | |
354 &matching)); | |
355 | |
356 if (!res) | |
357 return Qt; | |
358 else if (res > 0) | |
359 return make_int (1 + matching); | |
360 else | |
361 return make_int (-1 - matching); | |
362 } | |
363 | |
428 | 364 DEFUN ("string-lessp", Fstring_lessp, 2, 2, 0, /* |
365 Return t if first arg string is less than second in lexicographic order. | |
771 | 366 Comparison is simply done on a character-by-character basis using the |
367 numeric value of a character. (Note that this may not produce | |
368 particularly meaningful results under Mule if characters from | |
369 different charsets are being compared.) | |
428 | 370 |
371 Symbols are also allowed; their print names are used instead. | |
372 | |
771 | 373 Currently we don't do proper language-specific collation or handle |
374 multiple character sets. This may be changed when Unicode support | |
375 is implemented. | |
428 | 376 */ |
444 | 377 (string1, string2)) |
428 | 378 { |
793 | 379 Lisp_Object p1, p2; |
428 | 380 Charcount end, len2; |
381 int i; | |
382 | |
444 | 383 if (SYMBOLP (string1)) |
384 p1 = XSYMBOL (string1)->name; | |
793 | 385 else |
386 { | |
444 | 387 CHECK_STRING (string1); |
793 | 388 p1 = string1; |
428 | 389 } |
390 | |
444 | 391 if (SYMBOLP (string2)) |
392 p2 = XSYMBOL (string2)->name; | |
428 | 393 else |
394 { | |
444 | 395 CHECK_STRING (string2); |
793 | 396 p2 = string2; |
428 | 397 } |
398 | |
826 | 399 end = string_char_length (p1); |
400 len2 = string_char_length (p2); | |
428 | 401 if (end > len2) |
402 end = len2; | |
403 | |
404 { | |
867 | 405 Ibyte *ptr1 = XSTRING_DATA (p1); |
406 Ibyte *ptr2 = XSTRING_DATA (p2); | |
428 | 407 |
408 /* #### It is not really necessary to do this: We could compare | |
409 byte-by-byte and still get a reasonable comparison, since this | |
410 would compare characters with a charset in the same way. With | |
411 a little rearrangement of the leading bytes, we could make most | |
412 inter-charset comparisons work out the same, too; even if some | |
413 don't, this is not a big deal because inter-charset comparisons | |
414 aren't really well-defined anyway. */ | |
415 for (i = 0; i < end; i++) | |
416 { | |
867 | 417 if (itext_ichar (ptr1) != itext_ichar (ptr2)) |
418 return itext_ichar (ptr1) < itext_ichar (ptr2) ? Qt : Qnil; | |
419 INC_IBYTEPTR (ptr1); | |
420 INC_IBYTEPTR (ptr2); | |
428 | 421 } |
422 } | |
423 /* Can't do i < len2 because then comparison between "foo" and "foo^@" | |
424 won't work right in I18N2 case */ | |
425 return end < len2 ? Qt : Qnil; | |
426 } | |
427 | |
428 DEFUN ("string-modified-tick", Fstring_modified_tick, 1, 1, 0, /* | |
429 Return STRING's tick counter, incremented for each change to the string. | |
430 Each string has a tick counter which is incremented each time the contents | |
431 of the string are changed (e.g. with `aset'). It wraps around occasionally. | |
432 */ | |
433 (string)) | |
434 { | |
435 CHECK_STRING (string); | |
793 | 436 if (CONSP (XSTRING_PLIST (string)) && INTP (XCAR (XSTRING_PLIST (string)))) |
437 return XCAR (XSTRING_PLIST (string)); | |
428 | 438 else |
439 return Qzero; | |
440 } | |
441 | |
442 void | |
443 bump_string_modiff (Lisp_Object str) | |
444 { | |
793 | 445 Lisp_Object *ptr = &XSTRING_PLIST (str); |
428 | 446 |
447 #ifdef I18N3 | |
448 /* #### remove the `string-translatable' property from the string, | |
449 if there is one. */ | |
450 #endif | |
451 /* skip over extent info if it's there */ | |
452 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
453 ptr = &XCDR (*ptr); | |
454 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
793 | 455 XCAR (*ptr) = make_int (1+XINT (XCAR (*ptr))); |
428 | 456 else |
457 *ptr = Fcons (make_int (1), *ptr); | |
458 } | |
459 | |
460 | |
461 enum concat_target_type { c_cons, c_string, c_vector, c_bit_vector }; | |
462 static Lisp_Object concat (int nargs, Lisp_Object *args, | |
463 enum concat_target_type target_type, | |
464 int last_special); | |
465 | |
466 Lisp_Object | |
444 | 467 concat2 (Lisp_Object string1, Lisp_Object string2) |
428 | 468 { |
469 Lisp_Object args[2]; | |
444 | 470 args[0] = string1; |
471 args[1] = string2; | |
428 | 472 return concat (2, args, c_string, 0); |
473 } | |
474 | |
475 Lisp_Object | |
444 | 476 concat3 (Lisp_Object string1, Lisp_Object string2, Lisp_Object string3) |
428 | 477 { |
478 Lisp_Object args[3]; | |
444 | 479 args[0] = string1; |
480 args[1] = string2; | |
481 args[2] = string3; | |
428 | 482 return concat (3, args, c_string, 0); |
483 } | |
484 | |
485 Lisp_Object | |
444 | 486 vconcat2 (Lisp_Object vec1, Lisp_Object vec2) |
428 | 487 { |
488 Lisp_Object args[2]; | |
444 | 489 args[0] = vec1; |
490 args[1] = vec2; | |
428 | 491 return concat (2, args, c_vector, 0); |
492 } | |
493 | |
494 Lisp_Object | |
444 | 495 vconcat3 (Lisp_Object vec1, Lisp_Object vec2, Lisp_Object vec3) |
428 | 496 { |
497 Lisp_Object args[3]; | |
444 | 498 args[0] = vec1; |
499 args[1] = vec2; | |
500 args[2] = vec3; | |
428 | 501 return concat (3, args, c_vector, 0); |
502 } | |
503 | |
504 DEFUN ("append", Fappend, 0, MANY, 0, /* | |
505 Concatenate all the arguments and make the result a list. | |
506 The result is a list whose elements are the elements of all the arguments. | |
507 Each argument may be a list, vector, bit vector, or string. | |
508 The last argument is not copied, just used as the tail of the new list. | |
509 Also see: `nconc'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
510 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
511 arguments: (&rest ARGS) |
428 | 512 */ |
513 (int nargs, Lisp_Object *args)) | |
514 { | |
515 return concat (nargs, args, c_cons, 1); | |
516 } | |
517 | |
518 DEFUN ("concat", Fconcat, 0, MANY, 0, /* | |
519 Concatenate all the arguments and make the result a string. | |
520 The result is a string whose elements are the elements of all the arguments. | |
521 Each argument may be a string or a list or vector of characters. | |
522 | |
523 As of XEmacs 21.0, this function does NOT accept individual integers | |
524 as arguments. Old code that relies on, for example, (concat "foo" 50) | |
525 returning "foo50" will fail. To fix such code, either apply | |
526 `int-to-string' to the integer argument, or use `format'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
527 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
528 arguments: (&rest ARGS) |
428 | 529 */ |
530 (int nargs, Lisp_Object *args)) | |
531 { | |
532 return concat (nargs, args, c_string, 0); | |
533 } | |
534 | |
535 DEFUN ("vconcat", Fvconcat, 0, MANY, 0, /* | |
536 Concatenate all the arguments and make the result a vector. | |
537 The result is a vector whose elements are the elements of all the arguments. | |
538 Each argument may be a list, vector, bit vector, or string. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
539 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
540 arguments: (&rest ARGS) |
428 | 541 */ |
542 (int nargs, Lisp_Object *args)) | |
543 { | |
544 return concat (nargs, args, c_vector, 0); | |
545 } | |
546 | |
547 DEFUN ("bvconcat", Fbvconcat, 0, MANY, 0, /* | |
548 Concatenate all the arguments and make the result a bit vector. | |
549 The result is a bit vector whose elements are the elements of all the | |
550 arguments. Each argument may be a list, vector, bit vector, or string. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
551 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
552 arguments: (&rest ARGS) |
428 | 553 */ |
554 (int nargs, Lisp_Object *args)) | |
555 { | |
556 return concat (nargs, args, c_bit_vector, 0); | |
557 } | |
558 | |
559 /* Copy a (possibly dotted) list. LIST must be a cons. | |
560 Can't use concat (1, &alist, c_cons, 0) - doesn't handle dotted lists. */ | |
561 static Lisp_Object | |
562 copy_list (Lisp_Object list) | |
563 { | |
564 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list)); | |
565 Lisp_Object last = list_copy; | |
566 Lisp_Object hare, tortoise; | |
665 | 567 Elemcount len; |
428 | 568 |
569 for (tortoise = hare = XCDR (list), len = 1; | |
570 CONSP (hare); | |
571 hare = XCDR (hare), len++) | |
572 { | |
573 XCDR (last) = Fcons (XCAR (hare), XCDR (hare)); | |
574 last = XCDR (last); | |
575 | |
576 if (len < CIRCULAR_LIST_SUSPICION_LENGTH) | |
577 continue; | |
578 if (len & 1) | |
579 tortoise = XCDR (tortoise); | |
580 if (EQ (tortoise, hare)) | |
581 signal_circular_list_error (list); | |
582 } | |
583 | |
584 return list_copy; | |
585 } | |
586 | |
587 DEFUN ("copy-list", Fcopy_list, 1, 1, 0, /* | |
588 Return a copy of list LIST, which may be a dotted list. | |
589 The elements of LIST are not copied; they are shared | |
590 with the original. | |
591 */ | |
592 (list)) | |
593 { | |
594 again: | |
595 if (NILP (list)) return list; | |
596 if (CONSP (list)) return copy_list (list); | |
597 | |
598 list = wrong_type_argument (Qlistp, list); | |
599 goto again; | |
600 } | |
601 | |
602 DEFUN ("copy-sequence", Fcopy_sequence, 1, 1, 0, /* | |
603 Return a copy of list, vector, bit vector or string SEQUENCE. | |
604 The elements of a list or vector are not copied; they are shared | |
605 with the original. SEQUENCE may be a dotted list. | |
606 */ | |
607 (sequence)) | |
608 { | |
609 again: | |
610 if (NILP (sequence)) return sequence; | |
611 if (CONSP (sequence)) return copy_list (sequence); | |
612 if (STRINGP (sequence)) return concat (1, &sequence, c_string, 0); | |
613 if (VECTORP (sequence)) return concat (1, &sequence, c_vector, 0); | |
614 if (BIT_VECTORP (sequence)) return concat (1, &sequence, c_bit_vector, 0); | |
615 | |
616 check_losing_bytecode ("copy-sequence", sequence); | |
617 sequence = wrong_type_argument (Qsequencep, sequence); | |
618 goto again; | |
619 } | |
620 | |
621 struct merge_string_extents_struct | |
622 { | |
623 Lisp_Object string; | |
624 Bytecount entry_offset; | |
625 Bytecount entry_length; | |
626 }; | |
627 | |
628 static Lisp_Object | |
629 concat (int nargs, Lisp_Object *args, | |
630 enum concat_target_type target_type, | |
631 int last_special) | |
632 { | |
633 Lisp_Object val; | |
634 Lisp_Object tail = Qnil; | |
635 int toindex; | |
636 int argnum; | |
637 Lisp_Object last_tail; | |
638 Lisp_Object prev; | |
639 struct merge_string_extents_struct *args_mse = 0; | |
867 | 640 Ibyte *string_result = 0; |
641 Ibyte *string_result_ptr = 0; | |
428 | 642 struct gcpro gcpro1; |
851 | 643 int sdep = specpdl_depth (); |
428 | 644 |
645 /* The modus operandi in Emacs is "caller gc-protects args". | |
646 However, concat is called many times in Emacs on freshly | |
647 created stuff. So we help those callers out by protecting | |
648 the args ourselves to save them a lot of temporary-variable | |
649 grief. */ | |
650 | |
651 GCPRO1 (args[0]); | |
652 gcpro1.nvars = nargs; | |
653 | |
654 #ifdef I18N3 | |
655 /* #### if the result is a string and any of the strings have a string | |
656 for the `string-translatable' property, then concat should also | |
657 concat the args but use the `string-translatable' strings, and store | |
658 the result in the returned string's `string-translatable' property. */ | |
659 #endif | |
660 if (target_type == c_string) | |
661 args_mse = alloca_array (struct merge_string_extents_struct, nargs); | |
662 | |
663 /* In append, the last arg isn't treated like the others */ | |
664 if (last_special && nargs > 0) | |
665 { | |
666 nargs--; | |
667 last_tail = args[nargs]; | |
668 } | |
669 else | |
670 last_tail = Qnil; | |
671 | |
672 /* Check and coerce the arguments. */ | |
673 for (argnum = 0; argnum < nargs; argnum++) | |
674 { | |
675 Lisp_Object seq = args[argnum]; | |
676 if (LISTP (seq)) | |
677 ; | |
678 else if (VECTORP (seq) || STRINGP (seq) || BIT_VECTORP (seq)) | |
679 ; | |
680 #ifdef LOSING_BYTECODE | |
681 else if (COMPILED_FUNCTIONP (seq)) | |
682 /* Urk! We allow this, for "compatibility"... */ | |
683 ; | |
684 #endif | |
685 #if 0 /* removed for XEmacs 21 */ | |
686 else if (INTP (seq)) | |
687 /* This is too revolting to think about but maintains | |
688 compatibility with FSF (and lots and lots of old code). */ | |
689 args[argnum] = Fnumber_to_string (seq); | |
690 #endif | |
691 else | |
692 { | |
693 check_losing_bytecode ("concat", seq); | |
694 args[argnum] = wrong_type_argument (Qsequencep, seq); | |
695 } | |
696 | |
697 if (args_mse) | |
698 { | |
699 if (STRINGP (seq)) | |
700 args_mse[argnum].string = seq; | |
701 else | |
702 args_mse[argnum].string = Qnil; | |
703 } | |
704 } | |
705 | |
706 { | |
707 /* Charcount is a misnomer here as we might be dealing with the | |
708 length of a vector or list, but emphasizes that we're not dealing | |
709 with Bytecounts in strings */ | |
710 Charcount total_length; | |
711 | |
712 for (argnum = 0, total_length = 0; argnum < nargs; argnum++) | |
713 { | |
714 #ifdef LOSING_BYTECODE | |
715 Charcount thislen = length_with_bytecode_hack (args[argnum]); | |
716 #else | |
717 Charcount thislen = XINT (Flength (args[argnum])); | |
718 #endif | |
719 total_length += thislen; | |
720 } | |
721 | |
722 switch (target_type) | |
723 { | |
724 case c_cons: | |
725 if (total_length == 0) | |
851 | 726 { |
727 unbind_to (sdep); | |
728 /* In append, if all but last arg are nil, return last arg */ | |
729 RETURN_UNGCPRO (last_tail); | |
730 } | |
428 | 731 val = Fmake_list (make_int (total_length), Qnil); |
732 break; | |
733 case c_vector: | |
734 val = make_vector (total_length, Qnil); | |
735 break; | |
736 case c_bit_vector: | |
737 val = make_bit_vector (total_length, Qzero); | |
738 break; | |
739 case c_string: | |
740 /* We don't make the string yet because we don't know the | |
741 actual number of bytes. This loop was formerly written | |
742 to call Fmake_string() here and then call set_string_char() | |
743 for each char. This seems logical enough but is waaaaaaaay | |
744 slow -- set_string_char() has to scan the whole string up | |
745 to the place where the substitution is called for in order | |
746 to find the place to change, and may have to do some | |
747 realloc()ing in order to make the char fit properly. | |
748 O(N^2) yuckage. */ | |
749 val = Qnil; | |
851 | 750 string_result = |
867 | 751 (Ibyte *) MALLOC_OR_ALLOCA (total_length * MAX_ICHAR_LEN); |
428 | 752 string_result_ptr = string_result; |
753 break; | |
754 default: | |
442 | 755 val = Qnil; |
2500 | 756 ABORT (); |
428 | 757 } |
758 } | |
759 | |
760 | |
761 if (CONSP (val)) | |
762 tail = val, toindex = -1; /* -1 in toindex is flag we are | |
763 making a list */ | |
764 else | |
765 toindex = 0; | |
766 | |
767 prev = Qnil; | |
768 | |
769 for (argnum = 0; argnum < nargs; argnum++) | |
770 { | |
771 Charcount thisleni = 0; | |
772 Charcount thisindex = 0; | |
773 Lisp_Object seq = args[argnum]; | |
867 | 774 Ibyte *string_source_ptr = 0; |
775 Ibyte *string_prev_result_ptr = string_result_ptr; | |
428 | 776 |
777 if (!CONSP (seq)) | |
778 { | |
779 #ifdef LOSING_BYTECODE | |
780 thisleni = length_with_bytecode_hack (seq); | |
781 #else | |
782 thisleni = XINT (Flength (seq)); | |
783 #endif | |
784 } | |
785 if (STRINGP (seq)) | |
786 string_source_ptr = XSTRING_DATA (seq); | |
787 | |
788 while (1) | |
789 { | |
790 Lisp_Object elt; | |
791 | |
792 /* We've come to the end of this arg, so exit. */ | |
793 if (NILP (seq)) | |
794 break; | |
795 | |
796 /* Fetch next element of `seq' arg into `elt' */ | |
797 if (CONSP (seq)) | |
798 { | |
799 elt = XCAR (seq); | |
800 seq = XCDR (seq); | |
801 } | |
802 else | |
803 { | |
804 if (thisindex >= thisleni) | |
805 break; | |
806 | |
807 if (STRINGP (seq)) | |
808 { | |
867 | 809 elt = make_char (itext_ichar (string_source_ptr)); |
810 INC_IBYTEPTR (string_source_ptr); | |
428 | 811 } |
812 else if (VECTORP (seq)) | |
813 elt = XVECTOR_DATA (seq)[thisindex]; | |
814 else if (BIT_VECTORP (seq)) | |
815 elt = make_int (bit_vector_bit (XBIT_VECTOR (seq), | |
816 thisindex)); | |
817 else | |
818 elt = Felt (seq, make_int (thisindex)); | |
819 thisindex++; | |
820 } | |
821 | |
822 /* Store into result */ | |
823 if (toindex < 0) | |
824 { | |
825 /* toindex negative means we are making a list */ | |
826 XCAR (tail) = elt; | |
827 prev = tail; | |
828 tail = XCDR (tail); | |
829 } | |
830 else if (VECTORP (val)) | |
831 XVECTOR_DATA (val)[toindex++] = elt; | |
832 else if (BIT_VECTORP (val)) | |
833 { | |
834 CHECK_BIT (elt); | |
835 set_bit_vector_bit (XBIT_VECTOR (val), toindex++, XINT (elt)); | |
836 } | |
837 else | |
838 { | |
839 CHECK_CHAR_COERCE_INT (elt); | |
867 | 840 string_result_ptr += set_itext_ichar (string_result_ptr, |
428 | 841 XCHAR (elt)); |
842 } | |
843 } | |
844 if (args_mse) | |
845 { | |
846 args_mse[argnum].entry_offset = | |
847 string_prev_result_ptr - string_result; | |
848 args_mse[argnum].entry_length = | |
849 string_result_ptr - string_prev_result_ptr; | |
850 } | |
851 } | |
852 | |
853 /* Now we finally make the string. */ | |
854 if (target_type == c_string) | |
855 { | |
856 val = make_string (string_result, string_result_ptr - string_result); | |
857 for (argnum = 0; argnum < nargs; argnum++) | |
858 { | |
859 if (STRINGP (args_mse[argnum].string)) | |
860 copy_string_extents (val, args_mse[argnum].string, | |
861 args_mse[argnum].entry_offset, 0, | |
862 args_mse[argnum].entry_length); | |
863 } | |
864 } | |
865 | |
866 if (!NILP (prev)) | |
867 XCDR (prev) = last_tail; | |
868 | |
851 | 869 unbind_to (sdep); |
428 | 870 RETURN_UNGCPRO (val); |
871 } | |
872 | |
873 DEFUN ("copy-alist", Fcopy_alist, 1, 1, 0, /* | |
874 Return a copy of ALIST. | |
875 This is an alist which represents the same mapping from objects to objects, | |
876 but does not share the alist structure with ALIST. | |
877 The objects mapped (cars and cdrs of elements of the alist) | |
878 are shared, however. | |
879 Elements of ALIST that are not conses are also shared. | |
880 */ | |
881 (alist)) | |
882 { | |
883 Lisp_Object tail; | |
884 | |
885 if (NILP (alist)) | |
886 return alist; | |
887 CHECK_CONS (alist); | |
888 | |
889 alist = concat (1, &alist, c_cons, 0); | |
890 for (tail = alist; CONSP (tail); tail = XCDR (tail)) | |
891 { | |
892 Lisp_Object car = XCAR (tail); | |
893 | |
894 if (CONSP (car)) | |
895 XCAR (tail) = Fcons (XCAR (car), XCDR (car)); | |
896 } | |
897 return alist; | |
898 } | |
899 | |
900 DEFUN ("copy-tree", Fcopy_tree, 1, 2, 0, /* | |
901 Return a copy of a list and substructures. | |
902 The argument is copied, and any lists contained within it are copied | |
903 recursively. Circularities and shared substructures are not preserved. | |
904 Second arg VECP causes vectors to be copied, too. Strings and bit vectors | |
905 are not copied. | |
906 */ | |
907 (arg, vecp)) | |
908 { | |
454 | 909 return safe_copy_tree (arg, vecp, 0); |
910 } | |
911 | |
912 Lisp_Object | |
913 safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth) | |
914 { | |
915 if (depth > 200) | |
563 | 916 stack_overflow ("Stack overflow in copy-tree", arg); |
454 | 917 |
428 | 918 if (CONSP (arg)) |
919 { | |
920 Lisp_Object rest; | |
921 rest = arg = Fcopy_sequence (arg); | |
922 while (CONSP (rest)) | |
923 { | |
924 Lisp_Object elt = XCAR (rest); | |
925 QUIT; | |
926 if (CONSP (elt) || VECTORP (elt)) | |
454 | 927 XCAR (rest) = safe_copy_tree (elt, vecp, depth + 1); |
428 | 928 if (VECTORP (XCDR (rest))) /* hack for (a b . [c d]) */ |
454 | 929 XCDR (rest) = safe_copy_tree (XCDR (rest), vecp, depth +1); |
428 | 930 rest = XCDR (rest); |
931 } | |
932 } | |
933 else if (VECTORP (arg) && ! NILP (vecp)) | |
934 { | |
935 int i = XVECTOR_LENGTH (arg); | |
936 int j; | |
937 arg = Fcopy_sequence (arg); | |
938 for (j = 0; j < i; j++) | |
939 { | |
940 Lisp_Object elt = XVECTOR_DATA (arg) [j]; | |
941 QUIT; | |
942 if (CONSP (elt) || VECTORP (elt)) | |
454 | 943 XVECTOR_DATA (arg) [j] = safe_copy_tree (elt, vecp, depth + 1); |
428 | 944 } |
945 } | |
946 return arg; | |
947 } | |
948 | |
949 DEFUN ("substring", Fsubstring, 2, 3, 0, /* | |
444 | 950 Return the substring of STRING starting at START and ending before END. |
951 END may be nil or omitted; then the substring runs to the end of STRING. | |
952 If START or END is negative, it counts from the end. | |
953 Relevant parts of the string-extent-data are copied to the new string. | |
428 | 954 */ |
444 | 955 (string, start, end)) |
428 | 956 { |
444 | 957 Charcount ccstart, ccend; |
958 Bytecount bstart, blen; | |
428 | 959 Lisp_Object val; |
960 | |
961 CHECK_STRING (string); | |
444 | 962 CHECK_INT (start); |
963 get_string_range_char (string, start, end, &ccstart, &ccend, | |
428 | 964 GB_HISTORICAL_STRING_BEHAVIOR); |
793 | 965 bstart = string_index_char_to_byte (string, ccstart); |
966 blen = string_offset_char_to_byte_len (string, bstart, ccend - ccstart); | |
444 | 967 val = make_string (XSTRING_DATA (string) + bstart, blen); |
968 /* Copy any applicable extent information into the new string. */ | |
969 copy_string_extents (val, string, 0, bstart, blen); | |
428 | 970 return val; |
971 } | |
972 | |
973 DEFUN ("subseq", Fsubseq, 2, 3, 0, /* | |
442 | 974 Return the subsequence of SEQUENCE starting at START and ending before END. |
975 END may be omitted; then the subsequence runs to the end of SEQUENCE. | |
976 If START or END is negative, it counts from the end. | |
977 The returned subsequence is always of the same type as SEQUENCE. | |
978 If SEQUENCE is a string, relevant parts of the string-extent-data | |
979 are copied to the new string. | |
428 | 980 */ |
442 | 981 (sequence, start, end)) |
428 | 982 { |
442 | 983 EMACS_INT len, s, e; |
984 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
985 CHECK_SEQUENCE (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
986 |
442 | 987 if (STRINGP (sequence)) |
988 return Fsubstring (sequence, start, end); | |
989 | |
990 len = XINT (Flength (sequence)); | |
991 | |
992 CHECK_INT (start); | |
993 s = XINT (start); | |
994 if (s < 0) | |
995 s = len + s; | |
996 | |
997 if (NILP (end)) | |
998 e = len; | |
428 | 999 else |
1000 { | |
442 | 1001 CHECK_INT (end); |
1002 e = XINT (end); | |
1003 if (e < 0) | |
1004 e = len + e; | |
428 | 1005 } |
1006 | |
442 | 1007 if (!(0 <= s && s <= e && e <= len)) |
1008 args_out_of_range_3 (sequence, make_int (s), make_int (e)); | |
1009 | |
1010 if (VECTORP (sequence)) | |
428 | 1011 { |
442 | 1012 Lisp_Object result = make_vector (e - s, Qnil); |
428 | 1013 EMACS_INT i; |
442 | 1014 Lisp_Object *in_elts = XVECTOR_DATA (sequence); |
428 | 1015 Lisp_Object *out_elts = XVECTOR_DATA (result); |
1016 | |
442 | 1017 for (i = s; i < e; i++) |
1018 out_elts[i - s] = in_elts[i]; | |
428 | 1019 return result; |
1020 } | |
442 | 1021 else if (LISTP (sequence)) |
428 | 1022 { |
1023 Lisp_Object result = Qnil; | |
1024 EMACS_INT i; | |
1025 | |
442 | 1026 sequence = Fnthcdr (make_int (s), sequence); |
1027 | |
1028 for (i = s; i < e; i++) | |
428 | 1029 { |
442 | 1030 result = Fcons (Fcar (sequence), result); |
1031 sequence = Fcdr (sequence); | |
428 | 1032 } |
1033 | |
1034 return Fnreverse (result); | |
1035 } | |
442 | 1036 else if (BIT_VECTORP (sequence)) |
1037 { | |
1038 Lisp_Object result = make_bit_vector (e - s, Qzero); | |
1039 EMACS_INT i; | |
1040 | |
1041 for (i = s; i < e; i++) | |
1042 set_bit_vector_bit (XBIT_VECTOR (result), i - s, | |
1043 bit_vector_bit (XBIT_VECTOR (sequence), i)); | |
1044 return result; | |
1045 } | |
1046 else | |
1047 { | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1048 ABORT (); /* unreachable, since CHECK_SEQUENCE (sequence) did not |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
1049 error */ |
442 | 1050 return Qnil; |
1051 } | |
428 | 1052 } |
1053 | |
771 | 1054 /* Split STRING into a list of substrings. The substrings are the |
1055 parts of original STRING separated by SEPCHAR. */ | |
1056 static Lisp_Object | |
867 | 1057 split_string_by_ichar_1 (const Ibyte *string, Bytecount size, |
1058 Ichar sepchar) | |
771 | 1059 { |
1060 Lisp_Object result = Qnil; | |
867 | 1061 const Ibyte *end = string + size; |
771 | 1062 |
1063 while (1) | |
1064 { | |
867 | 1065 const Ibyte *p = string; |
771 | 1066 while (p < end) |
1067 { | |
867 | 1068 if (itext_ichar (p) == sepchar) |
771 | 1069 break; |
867 | 1070 INC_IBYTEPTR (p); |
771 | 1071 } |
1072 result = Fcons (make_string (string, p - string), result); | |
1073 if (p < end) | |
1074 { | |
1075 string = p; | |
867 | 1076 INC_IBYTEPTR (string); /* skip sepchar */ |
771 | 1077 } |
1078 else | |
1079 break; | |
1080 } | |
1081 return Fnreverse (result); | |
1082 } | |
1083 | |
1084 /* The same as the above, except PATH is an external C string (it is | |
1085 converted using Qfile_name), and sepchar is hardcoded to SEPCHAR | |
1086 (':' or whatever). */ | |
1087 Lisp_Object | |
1088 split_external_path (const Extbyte *path) | |
1089 { | |
1090 Bytecount newlen; | |
867 | 1091 Ibyte *newpath; |
771 | 1092 if (!path) |
1093 return Qnil; | |
1094 | |
1095 TO_INTERNAL_FORMAT (C_STRING, path, ALLOCA, (newpath, newlen), Qfile_name); | |
1096 | |
1097 /* #### Does this make sense? It certainly does for | |
1098 split_env_path(), but it looks dubious here. Does any code | |
1099 depend on split_external_path("") returning nil instead of an empty | |
1100 string? */ | |
1101 if (!newlen) | |
1102 return Qnil; | |
1103 | |
867 | 1104 return split_string_by_ichar_1 (newpath, newlen, SEPCHAR); |
771 | 1105 } |
1106 | |
1107 Lisp_Object | |
867 | 1108 split_env_path (const CIbyte *evarname, const Ibyte *default_) |
771 | 1109 { |
867 | 1110 const Ibyte *path = 0; |
771 | 1111 if (evarname) |
1112 path = egetenv (evarname); | |
1113 if (!path) | |
1114 path = default_; | |
1115 if (!path) | |
1116 return Qnil; | |
867 | 1117 return split_string_by_ichar_1 (path, qxestrlen (path), SEPCHAR); |
771 | 1118 } |
1119 | |
1120 /* Ben thinks this function should not exist or be exported to Lisp. | |
1121 We use it to define split-path-string in subr.el (not!). */ | |
1122 | |
949 | 1123 DEFUN ("split-string-by-char", Fsplit_string_by_char, 2, 2, 0, /* |
771 | 1124 Split STRING into a list of substrings originally separated by SEPCHAR. |
1125 */ | |
1126 (string, sepchar)) | |
1127 { | |
1128 CHECK_STRING (string); | |
1129 CHECK_CHAR (sepchar); | |
867 | 1130 return split_string_by_ichar_1 (XSTRING_DATA (string), |
771 | 1131 XSTRING_LENGTH (string), |
1132 XCHAR (sepchar)); | |
1133 } | |
1134 | |
1135 /* #### This was supposed to be in subr.el, but is used VERY early in | |
1136 the bootstrap process, so it goes here. Damn. */ | |
1137 | |
1138 DEFUN ("split-path", Fsplit_path, 1, 1, 0, /* | |
1139 Explode a search path into a list of strings. | |
1140 The path components are separated with the characters specified | |
1141 with `path-separator'. | |
1142 */ | |
1143 (path)) | |
1144 { | |
1145 CHECK_STRING (path); | |
1146 | |
1147 while (!STRINGP (Vpath_separator) | |
826 | 1148 || (string_char_length (Vpath_separator) != 1)) |
771 | 1149 Vpath_separator = signal_continuable_error |
1150 (Qinvalid_state, | |
1151 "`path-separator' should be set to a single-character string", | |
1152 Vpath_separator); | |
1153 | |
867 | 1154 return (split_string_by_ichar_1 |
771 | 1155 (XSTRING_DATA (path), XSTRING_LENGTH (path), |
867 | 1156 itext_ichar (XSTRING_DATA (Vpath_separator)))); |
771 | 1157 } |
1158 | |
428 | 1159 |
1160 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /* | |
1161 Take cdr N times on LIST, and return the result. | |
1162 */ | |
1163 (n, list)) | |
1164 { | |
1920 | 1165 /* This function can GC */ |
647 | 1166 REGISTER EMACS_INT i; |
428 | 1167 REGISTER Lisp_Object tail = list; |
1168 CHECK_NATNUM (n); | |
1169 for (i = XINT (n); i; i--) | |
1170 { | |
1171 if (CONSP (tail)) | |
1172 tail = XCDR (tail); | |
1173 else if (NILP (tail)) | |
1174 return Qnil; | |
1175 else | |
1176 { | |
1177 tail = wrong_type_argument (Qlistp, tail); | |
1178 i++; | |
1179 } | |
1180 } | |
1181 return tail; | |
1182 } | |
1183 | |
1184 DEFUN ("nth", Fnth, 2, 2, 0, /* | |
1185 Return the Nth element of LIST. | |
1186 N counts from zero. If LIST is not that long, nil is returned. | |
1187 */ | |
1188 (n, list)) | |
1189 { | |
1920 | 1190 /* This function can GC */ |
428 | 1191 return Fcar (Fnthcdr (n, list)); |
1192 } | |
1193 | |
1194 DEFUN ("elt", Felt, 2, 2, 0, /* | |
1195 Return element of SEQUENCE at index N. | |
1196 */ | |
1197 (sequence, n)) | |
1198 { | |
1920 | 1199 /* This function can GC */ |
428 | 1200 retry: |
1201 CHECK_INT_COERCE_CHAR (n); /* yuck! */ | |
1202 if (LISTP (sequence)) | |
1203 { | |
1204 Lisp_Object tem = Fnthcdr (n, sequence); | |
1205 /* #### Utterly, completely, fucking disgusting. | |
1206 * #### The whole point of "elt" is that it operates on | |
1207 * #### sequences, and does error- (bounds-) checking. | |
1208 */ | |
1209 if (CONSP (tem)) | |
1210 return XCAR (tem); | |
1211 else | |
1212 #if 1 | |
1213 /* This is The Way It Has Always Been. */ | |
1214 return Qnil; | |
1215 #else | |
1216 /* This is The Way Mly and Cltl2 say It Should Be. */ | |
1217 args_out_of_range (sequence, n); | |
1218 #endif | |
1219 } | |
1220 else if (STRINGP (sequence) || | |
1221 VECTORP (sequence) || | |
1222 BIT_VECTORP (sequence)) | |
1223 return Faref (sequence, n); | |
1224 #ifdef LOSING_BYTECODE | |
1225 else if (COMPILED_FUNCTIONP (sequence)) | |
1226 { | |
1227 EMACS_INT idx = XINT (n); | |
1228 if (idx < 0) | |
1229 { | |
1230 lose: | |
1231 args_out_of_range (sequence, n); | |
1232 } | |
1233 /* Utter perversity */ | |
1234 { | |
1235 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (sequence); | |
1236 switch (idx) | |
1237 { | |
1238 case COMPILED_ARGLIST: | |
1239 return compiled_function_arglist (f); | |
1240 case COMPILED_INSTRUCTIONS: | |
1241 return compiled_function_instructions (f); | |
1242 case COMPILED_CONSTANTS: | |
1243 return compiled_function_constants (f); | |
1244 case COMPILED_STACK_DEPTH: | |
1245 return compiled_function_stack_depth (f); | |
1246 case COMPILED_DOC_STRING: | |
1247 return compiled_function_documentation (f); | |
1248 case COMPILED_DOMAIN: | |
1249 return compiled_function_domain (f); | |
1250 case COMPILED_INTERACTIVE: | |
1251 if (f->flags.interactivep) | |
1252 return compiled_function_interactive (f); | |
1253 /* if we return nil, can't tell interactive with no args | |
1254 from noninteractive. */ | |
1255 goto lose; | |
1256 default: | |
1257 goto lose; | |
1258 } | |
1259 } | |
1260 } | |
1261 #endif /* LOSING_BYTECODE */ | |
1262 else | |
1263 { | |
1264 check_losing_bytecode ("elt", sequence); | |
1265 sequence = wrong_type_argument (Qsequencep, sequence); | |
1266 goto retry; | |
1267 } | |
1268 } | |
1269 | |
1270 DEFUN ("last", Flast, 1, 2, 0, /* | |
1271 Return the tail of list LIST, of length N (default 1). | |
1272 LIST may be a dotted list, but not a circular list. | |
1273 Optional argument N must be a non-negative integer. | |
1274 If N is zero, then the atom that terminates the list is returned. | |
1275 If N is greater than the length of LIST, then LIST itself is returned. | |
1276 */ | |
1277 (list, n)) | |
1278 { | |
1279 EMACS_INT int_n, count; | |
1280 Lisp_Object retval, tortoise, hare; | |
1281 | |
1282 CHECK_LIST (list); | |
1283 | |
1284 if (NILP (n)) | |
1285 int_n = 1; | |
1286 else | |
1287 { | |
1288 CHECK_NATNUM (n); | |
1289 int_n = XINT (n); | |
1290 } | |
1291 | |
1292 for (retval = tortoise = hare = list, count = 0; | |
1293 CONSP (hare); | |
1294 hare = XCDR (hare), | |
1295 (int_n-- <= 0 ? ((void) (retval = XCDR (retval))) : (void)0), | |
1296 count++) | |
1297 { | |
1298 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
1299 | |
1300 if (count & 1) | |
1301 tortoise = XCDR (tortoise); | |
1302 if (EQ (hare, tortoise)) | |
1303 signal_circular_list_error (list); | |
1304 } | |
1305 | |
1306 return retval; | |
1307 } | |
1308 | |
1309 DEFUN ("nbutlast", Fnbutlast, 1, 2, 0, /* | |
1310 Modify LIST to remove the last N (default 1) elements. | |
1311 If LIST has N or fewer elements, nil is returned and LIST is unmodified. | |
1312 */ | |
1313 (list, n)) | |
1314 { | |
1315 EMACS_INT int_n; | |
1316 | |
1317 CHECK_LIST (list); | |
1318 | |
1319 if (NILP (n)) | |
1320 int_n = 1; | |
1321 else | |
1322 { | |
1323 CHECK_NATNUM (n); | |
1324 int_n = XINT (n); | |
1325 } | |
1326 | |
1327 { | |
1328 Lisp_Object last_cons = list; | |
1329 | |
1330 EXTERNAL_LIST_LOOP_1 (list) | |
1331 { | |
1332 if (int_n-- < 0) | |
1333 last_cons = XCDR (last_cons); | |
1334 } | |
1335 | |
1336 if (int_n >= 0) | |
1337 return Qnil; | |
1338 | |
1339 XCDR (last_cons) = Qnil; | |
1340 return list; | |
1341 } | |
1342 } | |
1343 | |
1344 DEFUN ("butlast", Fbutlast, 1, 2, 0, /* | |
1345 Return a copy of LIST with the last N (default 1) elements removed. | |
1346 If LIST has N or fewer elements, nil is returned. | |
1347 */ | |
1348 (list, n)) | |
1349 { | |
444 | 1350 EMACS_INT int_n; |
428 | 1351 |
1352 CHECK_LIST (list); | |
1353 | |
1354 if (NILP (n)) | |
1355 int_n = 1; | |
1356 else | |
1357 { | |
1358 CHECK_NATNUM (n); | |
1359 int_n = XINT (n); | |
1360 } | |
1361 | |
1362 { | |
1363 Lisp_Object retval = Qnil; | |
1364 Lisp_Object tail = list; | |
1365 | |
1366 EXTERNAL_LIST_LOOP_1 (list) | |
1367 { | |
1368 if (--int_n < 0) | |
1369 { | |
1370 retval = Fcons (XCAR (tail), retval); | |
1371 tail = XCDR (tail); | |
1372 } | |
1373 } | |
1374 | |
1375 return Fnreverse (retval); | |
1376 } | |
1377 } | |
1378 | |
1379 DEFUN ("member", Fmember, 2, 2, 0, /* | |
1380 Return non-nil if ELT is an element of LIST. Comparison done with `equal'. | |
1381 The value is actually the tail of LIST whose car is ELT. | |
1382 */ | |
1383 (elt, list)) | |
1384 { | |
1385 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1386 { | |
1387 if (internal_equal (elt, list_elt, 0)) | |
1388 return tail; | |
1389 } | |
1390 return Qnil; | |
1391 } | |
1392 | |
1393 DEFUN ("old-member", Fold_member, 2, 2, 0, /* | |
1394 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'. | |
1395 The value is actually the tail of LIST whose car is ELT. | |
1396 This function is provided only for byte-code compatibility with v19. | |
1397 Do not use it. | |
1398 */ | |
1399 (elt, list)) | |
1400 { | |
1401 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1402 { | |
1403 if (internal_old_equal (elt, list_elt, 0)) | |
1404 return tail; | |
1405 } | |
1406 return Qnil; | |
1407 } | |
1408 | |
1409 DEFUN ("memq", Fmemq, 2, 2, 0, /* | |
1410 Return non-nil if ELT is an element of LIST. Comparison done with `eq'. | |
1411 The value is actually the tail of LIST whose car is ELT. | |
1412 */ | |
1413 (elt, list)) | |
1414 { | |
1415 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1416 { | |
1417 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1418 return tail; | |
1419 } | |
1420 return Qnil; | |
1421 } | |
1422 | |
1423 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /* | |
1424 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'. | |
1425 The value is actually the tail of LIST whose car is ELT. | |
1426 This function is provided only for byte-code compatibility with v19. | |
1427 Do not use it. | |
1428 */ | |
1429 (elt, list)) | |
1430 { | |
1431 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) | |
1432 { | |
1433 if (HACKEQ_UNSAFE (elt, list_elt)) | |
1434 return tail; | |
1435 } | |
1436 return Qnil; | |
1437 } | |
1438 | |
1439 Lisp_Object | |
1440 memq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1441 { | |
1442 LIST_LOOP_3 (list_elt, list, tail) | |
1443 { | |
1444 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) | |
1445 return tail; | |
1446 } | |
1447 return Qnil; | |
1448 } | |
1449 | |
1450 DEFUN ("assoc", Fassoc, 2, 2, 0, /* | |
444 | 1451 Return non-nil if KEY is `equal' to the car of an element of ALIST. |
1452 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1453 */ |
444 | 1454 (key, alist)) |
428 | 1455 { |
1456 /* This function can GC. */ | |
444 | 1457 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1458 { |
1459 if (internal_equal (key, elt_car, 0)) | |
1460 return elt; | |
1461 } | |
1462 return Qnil; | |
1463 } | |
1464 | |
1465 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /* | |
444 | 1466 Return non-nil if KEY is `old-equal' to the car of an element of ALIST. |
1467 The value is actually the element of ALIST whose car equals KEY. | |
428 | 1468 */ |
444 | 1469 (key, alist)) |
428 | 1470 { |
1471 /* This function can GC. */ | |
444 | 1472 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1473 { |
1474 if (internal_old_equal (key, elt_car, 0)) | |
1475 return elt; | |
1476 } | |
1477 return Qnil; | |
1478 } | |
1479 | |
1480 Lisp_Object | |
444 | 1481 assoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1482 { |
1483 int speccount = specpdl_depth (); | |
1484 specbind (Qinhibit_quit, Qt); | |
771 | 1485 return unbind_to_1 (speccount, Fassoc (key, alist)); |
428 | 1486 } |
1487 | |
1488 DEFUN ("assq", Fassq, 2, 2, 0, /* | |
444 | 1489 Return non-nil if KEY is `eq' to the car of an element of ALIST. |
1490 The value is actually the element of ALIST whose car is KEY. | |
1491 Elements of ALIST that are not conses are ignored. | |
428 | 1492 */ |
444 | 1493 (key, alist)) |
428 | 1494 { |
444 | 1495 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1496 { |
1497 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1498 return elt; | |
1499 } | |
1500 return Qnil; | |
1501 } | |
1502 | |
1503 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /* | |
444 | 1504 Return non-nil if KEY is `old-eq' to the car of an element of ALIST. |
1505 The value is actually the element of ALIST whose car is KEY. | |
1506 Elements of ALIST that are not conses are ignored. | |
428 | 1507 This function is provided only for byte-code compatibility with v19. |
1508 Do not use it. | |
1509 */ | |
444 | 1510 (key, alist)) |
428 | 1511 { |
444 | 1512 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1513 { |
1514 if (HACKEQ_UNSAFE (key, elt_car)) | |
1515 return elt; | |
1516 } | |
1517 return Qnil; | |
1518 } | |
1519 | |
1520 /* Like Fassq but never report an error and do not allow quits. | |
1521 Use only on lists known never to be circular. */ | |
1522 | |
1523 Lisp_Object | |
444 | 1524 assq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1525 { |
1526 /* This cannot GC. */ | |
444 | 1527 LIST_LOOP_2 (elt, alist) |
428 | 1528 { |
1529 Lisp_Object elt_car = XCAR (elt); | |
1530 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) | |
1531 return elt; | |
1532 } | |
1533 return Qnil; | |
1534 } | |
1535 | |
1536 DEFUN ("rassoc", Frassoc, 2, 2, 0, /* | |
444 | 1537 Return non-nil if VALUE is `equal' to the cdr of an element of ALIST. |
1538 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1539 */ |
444 | 1540 (value, alist)) |
428 | 1541 { |
444 | 1542 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1543 { |
444 | 1544 if (internal_equal (value, elt_cdr, 0)) |
428 | 1545 return elt; |
1546 } | |
1547 return Qnil; | |
1548 } | |
1549 | |
1550 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /* | |
444 | 1551 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST. |
1552 The value is actually the element of ALIST whose cdr equals VALUE. | |
428 | 1553 */ |
444 | 1554 (value, alist)) |
428 | 1555 { |
444 | 1556 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1557 { |
444 | 1558 if (internal_old_equal (value, elt_cdr, 0)) |
428 | 1559 return elt; |
1560 } | |
1561 return Qnil; | |
1562 } | |
1563 | |
1564 DEFUN ("rassq", Frassq, 2, 2, 0, /* | |
444 | 1565 Return non-nil if VALUE is `eq' to the cdr of an element of ALIST. |
1566 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1567 */ |
444 | 1568 (value, alist)) |
428 | 1569 { |
444 | 1570 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1571 { |
444 | 1572 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1573 return elt; |
1574 } | |
1575 return Qnil; | |
1576 } | |
1577 | |
1578 DEFUN ("old-rassq", Fold_rassq, 2, 2, 0, /* | |
444 | 1579 Return non-nil if VALUE is `old-eq' to the cdr of an element of ALIST. |
1580 The value is actually the element of ALIST whose cdr is VALUE. | |
428 | 1581 */ |
444 | 1582 (value, alist)) |
428 | 1583 { |
444 | 1584 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) |
428 | 1585 { |
444 | 1586 if (HACKEQ_UNSAFE (value, elt_cdr)) |
428 | 1587 return elt; |
1588 } | |
1589 return Qnil; | |
1590 } | |
1591 | |
444 | 1592 /* Like Frassq, but caller must ensure that ALIST is properly |
428 | 1593 nil-terminated and ebola-free. */ |
1594 Lisp_Object | |
444 | 1595 rassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1596 { |
444 | 1597 LIST_LOOP_2 (elt, alist) |
428 | 1598 { |
1599 Lisp_Object elt_cdr = XCDR (elt); | |
444 | 1600 if (EQ_WITH_EBOLA_NOTICE (value, elt_cdr)) |
428 | 1601 return elt; |
1602 } | |
1603 return Qnil; | |
1604 } | |
1605 | |
1606 | |
1607 DEFUN ("delete", Fdelete, 2, 2, 0, /* | |
1608 Delete by side effect any occurrences of ELT as a member of LIST. | |
1609 The modified LIST is returned. Comparison is done with `equal'. | |
1610 If the first member of LIST is ELT, there is no way to remove it by side | |
1611 effect; therefore, write `(setq foo (delete element foo))' to be sure | |
1612 of changing the value of `foo'. | |
1613 Also see: `remove'. | |
1614 */ | |
1615 (elt, list)) | |
1616 { | |
1617 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1618 (internal_equal (elt, list_elt, 0))); | |
1619 return list; | |
1620 } | |
1621 | |
1622 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /* | |
1623 Delete by side effect any occurrences of ELT as a member of LIST. | |
1624 The modified LIST is returned. Comparison is done with `old-equal'. | |
1625 If the first member of LIST is ELT, there is no way to remove it by side | |
1626 effect; therefore, write `(setq foo (old-delete element foo))' to be sure | |
1627 of changing the value of `foo'. | |
1628 */ | |
1629 (elt, list)) | |
1630 { | |
1631 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1632 (internal_old_equal (elt, list_elt, 0))); | |
1633 return list; | |
1634 } | |
1635 | |
1636 DEFUN ("delq", Fdelq, 2, 2, 0, /* | |
1637 Delete by side effect any occurrences of ELT as a member of LIST. | |
1638 The modified LIST is returned. Comparison is done with `eq'. | |
1639 If the first member of LIST is ELT, there is no way to remove it by side | |
1640 effect; therefore, write `(setq foo (delq element foo))' to be sure of | |
1641 changing the value of `foo'. | |
1642 */ | |
1643 (elt, list)) | |
1644 { | |
1645 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1646 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1647 return list; | |
1648 } | |
1649 | |
1650 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /* | |
1651 Delete by side effect any occurrences of ELT as a member of LIST. | |
1652 The modified LIST is returned. Comparison is done with `old-eq'. | |
1653 If the first member of LIST is ELT, there is no way to remove it by side | |
1654 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of | |
1655 changing the value of `foo'. | |
1656 */ | |
1657 (elt, list)) | |
1658 { | |
1659 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list, | |
1660 (HACKEQ_UNSAFE (elt, list_elt))); | |
1661 return list; | |
1662 } | |
1663 | |
1664 /* Like Fdelq, but caller must ensure that LIST is properly | |
1665 nil-terminated and ebola-free. */ | |
1666 | |
1667 Lisp_Object | |
1668 delq_no_quit (Lisp_Object elt, Lisp_Object list) | |
1669 { | |
1670 LIST_LOOP_DELETE_IF (list_elt, list, | |
1671 (EQ_WITH_EBOLA_NOTICE (elt, list_elt))); | |
1672 return list; | |
1673 } | |
1674 | |
1675 /* Be VERY careful with this. This is like delq_no_quit() but | |
1676 also calls free_cons() on the removed conses. You must be SURE | |
1677 that no pointers to the freed conses remain around (e.g. | |
1678 someone else is pointing to part of the list). This function | |
1679 is useful on internal lists that are used frequently and where | |
1680 the actual list doesn't escape beyond known code bounds. */ | |
1681 | |
1682 Lisp_Object | |
1683 delq_no_quit_and_free_cons (Lisp_Object elt, Lisp_Object list) | |
1684 { | |
1685 REGISTER Lisp_Object tail = list; | |
1686 REGISTER Lisp_Object prev = Qnil; | |
1687 | |
1688 while (!NILP (tail)) | |
1689 { | |
1690 REGISTER Lisp_Object tem = XCAR (tail); | |
1691 if (EQ (elt, tem)) | |
1692 { | |
1693 Lisp_Object cons_to_free = tail; | |
1694 if (NILP (prev)) | |
1695 list = XCDR (tail); | |
1696 else | |
1697 XCDR (prev) = XCDR (tail); | |
1698 tail = XCDR (tail); | |
853 | 1699 free_cons (cons_to_free); |
428 | 1700 } |
1701 else | |
1702 { | |
1703 prev = tail; | |
1704 tail = XCDR (tail); | |
1705 } | |
1706 } | |
1707 return list; | |
1708 } | |
1709 | |
1710 DEFUN ("remassoc", Fremassoc, 2, 2, 0, /* | |
444 | 1711 Delete by side effect any elements of ALIST whose car is `equal' to KEY. |
1712 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1713 that is `equal' to KEY, there is no way to remove it by side effect; |
1714 therefore, write `(setq foo (remassoc key foo))' to be sure of changing | |
1715 the value of `foo'. | |
1716 */ | |
444 | 1717 (key, alist)) |
428 | 1718 { |
444 | 1719 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1720 (CONSP (elt) && |
1721 internal_equal (key, XCAR (elt), 0))); | |
444 | 1722 return alist; |
428 | 1723 } |
1724 | |
1725 Lisp_Object | |
444 | 1726 remassoc_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1727 { |
1728 int speccount = specpdl_depth (); | |
1729 specbind (Qinhibit_quit, Qt); | |
771 | 1730 return unbind_to_1 (speccount, Fremassoc (key, alist)); |
428 | 1731 } |
1732 | |
1733 DEFUN ("remassq", Fremassq, 2, 2, 0, /* | |
444 | 1734 Delete by side effect any elements of ALIST whose car is `eq' to KEY. |
1735 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1736 that is `eq' to KEY, there is no way to remove it by side effect; |
1737 therefore, write `(setq foo (remassq key foo))' to be sure of changing | |
1738 the value of `foo'. | |
1739 */ | |
444 | 1740 (key, alist)) |
428 | 1741 { |
444 | 1742 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1743 (CONSP (elt) && |
1744 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1745 return alist; |
428 | 1746 } |
1747 | |
1748 /* no quit, no errors; be careful */ | |
1749 | |
1750 Lisp_Object | |
444 | 1751 remassq_no_quit (Lisp_Object key, Lisp_Object alist) |
428 | 1752 { |
444 | 1753 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1754 (CONSP (elt) && |
1755 EQ_WITH_EBOLA_NOTICE (key, XCAR (elt)))); | |
444 | 1756 return alist; |
428 | 1757 } |
1758 | |
1759 DEFUN ("remrassoc", Fremrassoc, 2, 2, 0, /* | |
444 | 1760 Delete by side effect any elements of ALIST whose cdr is `equal' to VALUE. |
1761 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1762 that is `equal' to VALUE, there is no way to remove it by side effect; |
1763 therefore, write `(setq foo (remrassoc value foo))' to be sure of changing | |
1764 the value of `foo'. | |
1765 */ | |
444 | 1766 (value, alist)) |
428 | 1767 { |
444 | 1768 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1769 (CONSP (elt) && |
1770 internal_equal (value, XCDR (elt), 0))); | |
444 | 1771 return alist; |
428 | 1772 } |
1773 | |
1774 DEFUN ("remrassq", Fremrassq, 2, 2, 0, /* | |
444 | 1775 Delete by side effect any elements of ALIST whose cdr is `eq' to VALUE. |
1776 The modified ALIST is returned. If the first member of ALIST has a car | |
428 | 1777 that is `eq' to VALUE, there is no way to remove it by side effect; |
1778 therefore, write `(setq foo (remrassq value foo))' to be sure of changing | |
1779 the value of `foo'. | |
1780 */ | |
444 | 1781 (value, alist)) |
428 | 1782 { |
444 | 1783 EXTERNAL_LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1784 (CONSP (elt) && |
1785 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 1786 return alist; |
428 | 1787 } |
1788 | |
1789 /* Like Fremrassq, fast and unsafe; be careful */ | |
1790 Lisp_Object | |
444 | 1791 remrassq_no_quit (Lisp_Object value, Lisp_Object alist) |
428 | 1792 { |
444 | 1793 LIST_LOOP_DELETE_IF (elt, alist, |
428 | 1794 (CONSP (elt) && |
1795 EQ_WITH_EBOLA_NOTICE (value, XCDR (elt)))); | |
444 | 1796 return alist; |
428 | 1797 } |
1798 | |
1799 DEFUN ("nreverse", Fnreverse, 1, 1, 0, /* | |
1800 Reverse LIST by destructively modifying cdr pointers. | |
1801 Return the beginning of the reversed list. | |
1802 Also see: `reverse'. | |
1803 */ | |
1804 (list)) | |
1805 { | |
1806 struct gcpro gcpro1, gcpro2; | |
1849 | 1807 Lisp_Object prev = Qnil; |
1808 Lisp_Object tail = list; | |
428 | 1809 |
1810 /* We gcpro our args; see `nconc' */ | |
1811 GCPRO2 (prev, tail); | |
1812 while (!NILP (tail)) | |
1813 { | |
1814 REGISTER Lisp_Object next; | |
1815 CONCHECK_CONS (tail); | |
1816 next = XCDR (tail); | |
1817 XCDR (tail) = prev; | |
1818 prev = tail; | |
1819 tail = next; | |
1820 } | |
1821 UNGCPRO; | |
1822 return prev; | |
1823 } | |
1824 | |
1825 DEFUN ("reverse", Freverse, 1, 1, 0, /* | |
1826 Reverse LIST, copying. Return the beginning of the reversed list. | |
1827 See also the function `nreverse', which is used more often. | |
1828 */ | |
1829 (list)) | |
1830 { | |
1831 Lisp_Object reversed_list = Qnil; | |
1832 EXTERNAL_LIST_LOOP_2 (elt, list) | |
1833 { | |
1834 reversed_list = Fcons (elt, reversed_list); | |
1835 } | |
1836 return reversed_list; | |
1837 } | |
1838 | |
1839 static Lisp_Object list_merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
1840 Lisp_Object lisp_arg, | |
1841 int (*pred_fn) (Lisp_Object, Lisp_Object, | |
1842 Lisp_Object lisp_arg)); | |
1843 | |
872 | 1844 /* The sort function should return > 0 if OBJ1 < OBJ2, < 0 otherwise. |
1845 NOTE: This is backwards from the way qsort() works. */ | |
1846 | |
428 | 1847 Lisp_Object |
1848 list_sort (Lisp_Object list, | |
1849 Lisp_Object lisp_arg, | |
872 | 1850 int (*pred_fn) (Lisp_Object obj1, Lisp_Object obj2, |
428 | 1851 Lisp_Object lisp_arg)) |
1852 { | |
1853 struct gcpro gcpro1, gcpro2, gcpro3; | |
1854 Lisp_Object back, tem; | |
1855 Lisp_Object front = list; | |
1856 Lisp_Object len = Flength (list); | |
444 | 1857 |
1858 if (XINT (len) < 2) | |
428 | 1859 return list; |
1860 | |
444 | 1861 len = make_int (XINT (len) / 2 - 1); |
428 | 1862 tem = Fnthcdr (len, list); |
1863 back = Fcdr (tem); | |
1864 Fsetcdr (tem, Qnil); | |
1865 | |
1866 GCPRO3 (front, back, lisp_arg); | |
1867 front = list_sort (front, lisp_arg, pred_fn); | |
1868 back = list_sort (back, lisp_arg, pred_fn); | |
1869 UNGCPRO; | |
1870 return list_merge (front, back, lisp_arg, pred_fn); | |
1871 } | |
1872 | |
1873 | |
1874 static int | |
1875 merge_pred_function (Lisp_Object obj1, Lisp_Object obj2, | |
1876 Lisp_Object pred) | |
1877 { | |
1878 Lisp_Object tmp; | |
1879 | |
1880 /* prevents the GC from happening in call2 */ | |
853 | 1881 /* Emacs' GC doesn't actually relocate pointers, so this probably |
1882 isn't strictly necessary */ | |
771 | 1883 int speccount = begin_gc_forbidden (); |
428 | 1884 tmp = call2 (pred, obj1, obj2); |
771 | 1885 unbind_to (speccount); |
428 | 1886 |
1887 if (NILP (tmp)) | |
1888 return -1; | |
1889 else | |
1890 return 1; | |
1891 } | |
1892 | |
1893 DEFUN ("sort", Fsort, 2, 2, 0, /* | |
1894 Sort LIST, stably, comparing elements using PREDICATE. | |
1895 Returns the sorted list. LIST is modified by side effects. | |
1896 PREDICATE is called with two elements of LIST, and should return T | |
1897 if the first element is "less" than the second. | |
1898 */ | |
444 | 1899 (list, predicate)) |
428 | 1900 { |
444 | 1901 return list_sort (list, predicate, merge_pred_function); |
428 | 1902 } |
1903 | |
1904 Lisp_Object | |
1905 merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
1906 Lisp_Object pred) | |
1907 { | |
1908 return list_merge (org_l1, org_l2, pred, merge_pred_function); | |
1909 } | |
1910 | |
1911 | |
1912 static Lisp_Object | |
1913 list_merge (Lisp_Object org_l1, Lisp_Object org_l2, | |
1914 Lisp_Object lisp_arg, | |
1915 int (*pred_fn) (Lisp_Object, Lisp_Object, Lisp_Object lisp_arg)) | |
1916 { | |
1917 Lisp_Object value; | |
1918 Lisp_Object tail; | |
1919 Lisp_Object tem; | |
1920 Lisp_Object l1, l2; | |
1921 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
1922 | |
1923 l1 = org_l1; | |
1924 l2 = org_l2; | |
1925 tail = Qnil; | |
1926 value = Qnil; | |
1927 | |
1928 /* It is sufficient to protect org_l1 and org_l2. | |
1929 When l1 and l2 are updated, we copy the new values | |
1930 back into the org_ vars. */ | |
1931 | |
1932 GCPRO4 (org_l1, org_l2, lisp_arg, value); | |
1933 | |
1934 while (1) | |
1935 { | |
1936 if (NILP (l1)) | |
1937 { | |
1938 UNGCPRO; | |
1939 if (NILP (tail)) | |
1940 return l2; | |
1941 Fsetcdr (tail, l2); | |
1942 return value; | |
1943 } | |
1944 if (NILP (l2)) | |
1945 { | |
1946 UNGCPRO; | |
1947 if (NILP (tail)) | |
1948 return l1; | |
1949 Fsetcdr (tail, l1); | |
1950 return value; | |
1951 } | |
1952 | |
1953 if (((*pred_fn) (Fcar (l2), Fcar (l1), lisp_arg)) < 0) | |
1954 { | |
1955 tem = l1; | |
1956 l1 = Fcdr (l1); | |
1957 org_l1 = l1; | |
1958 } | |
1959 else | |
1960 { | |
1961 tem = l2; | |
1962 l2 = Fcdr (l2); | |
1963 org_l2 = l2; | |
1964 } | |
1965 if (NILP (tail)) | |
1966 value = tem; | |
1967 else | |
1968 Fsetcdr (tail, tem); | |
1969 tail = tem; | |
1970 } | |
1971 } | |
1972 | |
1973 | |
1974 /************************************************************************/ | |
1975 /* property-list functions */ | |
1976 /************************************************************************/ | |
1977 | |
1978 /* For properties of text, we need to do order-insensitive comparison of | |
1979 plists. That is, we need to compare two plists such that they are the | |
1980 same if they have the same set of keys, and equivalent values. | |
1981 So (a 1 b 2) would be equal to (b 2 a 1). | |
1982 | |
1983 NIL_MEANS_NOT_PRESENT is as in `plists-eq' etc. | |
1984 LAXP means use `equal' for comparisons. | |
1985 */ | |
1986 int | |
1987 plists_differ (Lisp_Object a, Lisp_Object b, int nil_means_not_present, | |
1988 int laxp, int depth) | |
1989 { | |
438 | 1990 int eqp = (depth == -1); /* -1 as depth means use eq, not equal. */ |
428 | 1991 int la, lb, m, i, fill; |
1992 Lisp_Object *keys, *vals; | |
1993 char *flags; | |
1994 Lisp_Object rest; | |
1995 | |
1996 if (NILP (a) && NILP (b)) | |
1997 return 0; | |
1998 | |
1999 Fcheck_valid_plist (a); | |
2000 Fcheck_valid_plist (b); | |
2001 | |
2002 la = XINT (Flength (a)); | |
2003 lb = XINT (Flength (b)); | |
2004 m = (la > lb ? la : lb); | |
2005 fill = 0; | |
2006 keys = alloca_array (Lisp_Object, m); | |
2007 vals = alloca_array (Lisp_Object, m); | |
2008 flags = alloca_array (char, m); | |
2009 | |
2010 /* First extract the pairs from A. */ | |
2011 for (rest = a; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2012 { | |
2013 Lisp_Object k = XCAR (rest); | |
2014 Lisp_Object v = XCAR (XCDR (rest)); | |
2015 /* Maybe be Ebolified. */ | |
2016 if (nil_means_not_present && NILP (v)) continue; | |
2017 keys [fill] = k; | |
2018 vals [fill] = v; | |
2019 flags[fill] = 0; | |
2020 fill++; | |
2021 } | |
2022 /* Now iterate over B, and stop if we find something that's not in A, | |
2023 or that doesn't match. As we match, mark them. */ | |
2024 for (rest = b; !NILP (rest); rest = XCDR (XCDR (rest))) | |
2025 { | |
2026 Lisp_Object k = XCAR (rest); | |
2027 Lisp_Object v = XCAR (XCDR (rest)); | |
2028 /* Maybe be Ebolified. */ | |
2029 if (nil_means_not_present && NILP (v)) continue; | |
2030 for (i = 0; i < fill; i++) | |
2031 { | |
2032 if (!laxp ? EQ (k, keys [i]) : internal_equal (k, keys [i], depth)) | |
2033 { | |
434 | 2034 if (eqp |
2035 /* We narrowly escaped being Ebolified here. */ | |
2036 ? !EQ_WITH_EBOLA_NOTICE (v, vals [i]) | |
2037 : !internal_equal (v, vals [i], depth)) | |
428 | 2038 /* a property in B has a different value than in A */ |
2039 goto MISMATCH; | |
2040 flags [i] = 1; | |
2041 break; | |
2042 } | |
2043 } | |
2044 if (i == fill) | |
2045 /* there are some properties in B that are not in A */ | |
2046 goto MISMATCH; | |
2047 } | |
2048 /* Now check to see that all the properties in A were also in B */ | |
2049 for (i = 0; i < fill; i++) | |
2050 if (flags [i] == 0) | |
2051 goto MISMATCH; | |
2052 | |
2053 /* Ok. */ | |
2054 return 0; | |
2055 | |
2056 MISMATCH: | |
2057 return 1; | |
2058 } | |
2059 | |
2060 DEFUN ("plists-eq", Fplists_eq, 2, 3, 0, /* | |
2061 Return non-nil if property lists A and B are `eq'. | |
2062 A property list is an alternating list of keywords and values. | |
2063 This function does order-insensitive comparisons of the property lists: | |
2064 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2065 Comparison between values is done using `eq'. See also `plists-equal'. | |
2066 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2067 a nil value is ignored. This feature is a virus that has infected | |
2068 old Lisp implementations, but should not be used except for backward | |
2069 compatibility. | |
2070 */ | |
2071 (a, b, nil_means_not_present)) | |
2072 { | |
2073 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, -1) | |
2074 ? Qnil : Qt); | |
2075 } | |
2076 | |
2077 DEFUN ("plists-equal", Fplists_equal, 2, 3, 0, /* | |
2078 Return non-nil if property lists A and B are `equal'. | |
2079 A property list is an alternating list of keywords and values. This | |
2080 function does order-insensitive comparisons of the property lists: For | |
2081 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2082 Comparison between values is done using `equal'. See also `plists-eq'. | |
2083 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2084 a nil value is ignored. This feature is a virus that has infected | |
2085 old Lisp implementations, but should not be used except for backward | |
2086 compatibility. | |
2087 */ | |
2088 (a, b, nil_means_not_present)) | |
2089 { | |
2090 return (plists_differ (a, b, !NILP (nil_means_not_present), 0, 1) | |
2091 ? Qnil : Qt); | |
2092 } | |
2093 | |
2094 | |
2095 DEFUN ("lax-plists-eq", Flax_plists_eq, 2, 3, 0, /* | |
2096 Return non-nil if lax property lists A and B are `eq'. | |
2097 A property list is an alternating list of keywords and values. | |
2098 This function does order-insensitive comparisons of the property lists: | |
2099 For example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2100 Comparison between values is done using `eq'. See also `plists-equal'. | |
2101 A lax property list is like a regular one except that comparisons between | |
2102 keywords is done using `equal' instead of `eq'. | |
2103 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2104 a nil value is ignored. This feature is a virus that has infected | |
2105 old Lisp implementations, but should not be used except for backward | |
2106 compatibility. | |
2107 */ | |
2108 (a, b, nil_means_not_present)) | |
2109 { | |
2110 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, -1) | |
2111 ? Qnil : Qt); | |
2112 } | |
2113 | |
2114 DEFUN ("lax-plists-equal", Flax_plists_equal, 2, 3, 0, /* | |
2115 Return non-nil if lax property lists A and B are `equal'. | |
2116 A property list is an alternating list of keywords and values. This | |
2117 function does order-insensitive comparisons of the property lists: For | |
2118 example, the property lists '(a 1 b 2) and '(b 2 a 1) are equal. | |
2119 Comparison between values is done using `equal'. See also `plists-eq'. | |
2120 A lax property list is like a regular one except that comparisons between | |
2121 keywords is done using `equal' instead of `eq'. | |
2122 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2123 a nil value is ignored. This feature is a virus that has infected | |
2124 old Lisp implementations, but should not be used except for backward | |
2125 compatibility. | |
2126 */ | |
2127 (a, b, nil_means_not_present)) | |
2128 { | |
2129 return (plists_differ (a, b, !NILP (nil_means_not_present), 1, 1) | |
2130 ? Qnil : Qt); | |
2131 } | |
2132 | |
2133 /* Return the value associated with key PROPERTY in property list PLIST. | |
2134 Return nil if key not found. This function is used for internal | |
2135 property lists that cannot be directly manipulated by the user. | |
2136 */ | |
2137 | |
2138 Lisp_Object | |
2139 internal_plist_get (Lisp_Object plist, Lisp_Object property) | |
2140 { | |
2141 Lisp_Object tail; | |
2142 | |
2143 for (tail = plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2144 { | |
2145 if (EQ (XCAR (tail), property)) | |
2146 return XCAR (XCDR (tail)); | |
2147 } | |
2148 | |
2149 return Qunbound; | |
2150 } | |
2151 | |
2152 /* Set PLIST's value for PROPERTY to VALUE. Analogous to | |
2153 internal_plist_get(). */ | |
2154 | |
2155 void | |
2156 internal_plist_put (Lisp_Object *plist, Lisp_Object property, | |
2157 Lisp_Object value) | |
2158 { | |
2159 Lisp_Object tail; | |
2160 | |
2161 for (tail = *plist; !NILP (tail); tail = XCDR (XCDR (tail))) | |
2162 { | |
2163 if (EQ (XCAR (tail), property)) | |
2164 { | |
2165 XCAR (XCDR (tail)) = value; | |
2166 return; | |
2167 } | |
2168 } | |
2169 | |
2170 *plist = Fcons (property, Fcons (value, *plist)); | |
2171 } | |
2172 | |
2173 int | |
2174 internal_remprop (Lisp_Object *plist, Lisp_Object property) | |
2175 { | |
2176 Lisp_Object tail, prev; | |
2177 | |
2178 for (tail = *plist, prev = Qnil; | |
2179 !NILP (tail); | |
2180 tail = XCDR (XCDR (tail))) | |
2181 { | |
2182 if (EQ (XCAR (tail), property)) | |
2183 { | |
2184 if (NILP (prev)) | |
2185 *plist = XCDR (XCDR (tail)); | |
2186 else | |
2187 XCDR (XCDR (prev)) = XCDR (XCDR (tail)); | |
2188 return 1; | |
2189 } | |
2190 else | |
2191 prev = tail; | |
2192 } | |
2193 | |
2194 return 0; | |
2195 } | |
2196 | |
2197 /* Called on a malformed property list. BADPLACE should be some | |
2198 place where truncating will form a good list -- i.e. we shouldn't | |
2199 result in a list with an odd length. */ | |
2200 | |
2201 static Lisp_Object | |
578 | 2202 bad_bad_bunny (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2203 { |
2204 if (ERRB_EQ (errb, ERROR_ME)) | |
2205 return Fsignal (Qmalformed_property_list, list2 (*plist, *badplace)); | |
2206 else | |
2207 { | |
2208 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2209 { | |
2210 warn_when_safe_lispobj | |
2211 (Qlist, Qwarning, | |
771 | 2212 list2 (build_msg_string |
428 | 2213 ("Malformed property list -- list has been truncated"), |
2214 *plist)); | |
793 | 2215 /* #### WARNING: This is more dangerous than it seems; perhaps |
2216 not a good idea. It also violates the principle of least | |
2217 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2218 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2219 *badplace = Qnil; |
2220 } | |
2221 return Qunbound; | |
2222 } | |
2223 } | |
2224 | |
2225 /* Called on a circular property list. BADPLACE should be some place | |
2226 where truncating will result in an even-length list, as above. | |
2227 If doesn't particularly matter where we truncate -- anywhere we | |
2228 truncate along the entire list will break the circularity, because | |
2229 it will create a terminus and the list currently doesn't have one. | |
2230 */ | |
2231 | |
2232 static Lisp_Object | |
578 | 2233 bad_bad_turtle (Lisp_Object *plist, Lisp_Object *badplace, Error_Behavior errb) |
428 | 2234 { |
2235 if (ERRB_EQ (errb, ERROR_ME)) | |
2236 return Fsignal (Qcircular_property_list, list1 (*plist)); | |
2237 else | |
2238 { | |
2239 if (ERRB_EQ (errb, ERROR_ME_WARN)) | |
2240 { | |
2241 warn_when_safe_lispobj | |
2242 (Qlist, Qwarning, | |
771 | 2243 list2 (build_msg_string |
428 | 2244 ("Circular property list -- list has been truncated"), |
2245 *plist)); | |
793 | 2246 /* #### WARNING: This is more dangerous than it seems; perhaps |
2247 not a good idea. It also violates the principle of least | |
2248 surprise -- passing in ERROR_ME_WARN causes truncation, but | |
2249 ERROR_ME and ERROR_ME_NOT don't. */ | |
428 | 2250 *badplace = Qnil; |
2251 } | |
2252 return Qunbound; | |
2253 } | |
2254 } | |
2255 | |
2256 /* Advance the tortoise pointer by two (one iteration of a property-list | |
2257 loop) and the hare pointer by four and verify that no malformations | |
2258 or circularities exist. If so, return zero and store a value into | |
2259 RETVAL that should be returned by the calling function. Otherwise, | |
2260 return 1. See external_plist_get(). | |
2261 */ | |
2262 | |
2263 static int | |
2264 advance_plist_pointers (Lisp_Object *plist, | |
2265 Lisp_Object **tortoise, Lisp_Object **hare, | |
578 | 2266 Error_Behavior errb, Lisp_Object *retval) |
428 | 2267 { |
2268 int i; | |
2269 Lisp_Object *tortsave = *tortoise; | |
2270 | |
2271 /* Note that our "fixing" may be more brutal than necessary, | |
2272 but it's the user's own problem, not ours, if they went in and | |
2273 manually fucked up a plist. */ | |
2274 | |
2275 for (i = 0; i < 2; i++) | |
2276 { | |
2277 /* This is a standard iteration of a defensive-loop-checking | |
2278 loop. We just do it twice because we want to advance past | |
2279 both the property and its value. | |
2280 | |
2281 If the pointer indirection is confusing you, remember that | |
2282 one level of indirection on the hare and tortoise pointers | |
2283 is only due to pass-by-reference for this function. The other | |
2284 level is so that the plist can be fixed in place. */ | |
2285 | |
2286 /* When we reach the end of a well-formed plist, **HARE is | |
2287 nil. In that case, we don't do anything at all except | |
2288 advance TORTOISE by one. Otherwise, we advance HARE | |
2289 by two (making sure it's OK to do so), then advance | |
2290 TORTOISE by one (it will always be OK to do so because | |
2291 the HARE is always ahead of the TORTOISE and will have | |
2292 already verified the path), then make sure TORTOISE and | |
2293 HARE don't contain the same non-nil object -- if the | |
2294 TORTOISE and the HARE ever meet, then obviously we're | |
2295 in a circularity, and if we're in a circularity, then | |
2296 the TORTOISE and the HARE can't cross paths without | |
2297 meeting, since the HARE only gains one step over the | |
2298 TORTOISE per iteration. */ | |
2299 | |
2300 if (!NILP (**hare)) | |
2301 { | |
2302 Lisp_Object *haresave = *hare; | |
2303 if (!CONSP (**hare)) | |
2304 { | |
2305 *retval = bad_bad_bunny (plist, haresave, errb); | |
2306 return 0; | |
2307 } | |
2308 *hare = &XCDR (**hare); | |
2309 /* In a non-plist, we'd check here for a nil value for | |
2310 **HARE, which is OK (it just means the list has an | |
2311 odd number of elements). In a plist, it's not OK | |
2312 for the list to have an odd number of elements. */ | |
2313 if (!CONSP (**hare)) | |
2314 { | |
2315 *retval = bad_bad_bunny (plist, haresave, errb); | |
2316 return 0; | |
2317 } | |
2318 *hare = &XCDR (**hare); | |
2319 } | |
2320 | |
2321 *tortoise = &XCDR (**tortoise); | |
2322 if (!NILP (**hare) && EQ (**tortoise, **hare)) | |
2323 { | |
2324 *retval = bad_bad_turtle (plist, tortsave, errb); | |
2325 return 0; | |
2326 } | |
2327 } | |
2328 | |
2329 return 1; | |
2330 } | |
2331 | |
2332 /* Return the value of PROPERTY from PLIST, or Qunbound if | |
2333 property is not on the list. | |
2334 | |
2335 PLIST is a Lisp-accessible property list, meaning that it | |
2336 has to be checked for malformations and circularities. | |
2337 | |
2338 If ERRB is ERROR_ME, an error will be signalled. Otherwise, the | |
2339 function will never signal an error; and if ERRB is ERROR_ME_WARN, | |
2340 on finding a malformation or a circularity, it issues a warning and | |
2341 attempts to silently fix the problem. | |
2342 | |
2343 A pointer to PLIST is passed in so that PLIST can be successfully | |
2344 "fixed" even if the error is at the beginning of the plist. */ | |
2345 | |
2346 Lisp_Object | |
2347 external_plist_get (Lisp_Object *plist, Lisp_Object property, | |
578 | 2348 int laxp, Error_Behavior errb) |
428 | 2349 { |
2350 Lisp_Object *tortoise = plist; | |
2351 Lisp_Object *hare = plist; | |
2352 | |
2353 while (!NILP (*tortoise)) | |
2354 { | |
2355 Lisp_Object *tortsave = tortoise; | |
2356 Lisp_Object retval; | |
2357 | |
2358 /* We do the standard tortoise/hare march. We isolate the | |
2359 grungy stuff to do this in advance_plist_pointers(), though. | |
2360 To us, all this function does is advance the tortoise | |
2361 pointer by two and the hare pointer by four and make sure | |
2362 everything's OK. We first advance the pointers and then | |
2363 check if a property matched; this ensures that our | |
2364 check for a matching property is safe. */ | |
2365 | |
2366 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2367 return retval; | |
2368 | |
2369 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2370 : internal_equal (XCAR (*tortsave), property, 0)) | |
2371 return XCAR (XCDR (*tortsave)); | |
2372 } | |
2373 | |
2374 return Qunbound; | |
2375 } | |
2376 | |
2377 /* Set PLIST's value for PROPERTY to VALUE, given a possibly | |
2378 malformed or circular plist. Analogous to external_plist_get(). */ | |
2379 | |
2380 void | |
2381 external_plist_put (Lisp_Object *plist, Lisp_Object property, | |
578 | 2382 Lisp_Object value, int laxp, Error_Behavior errb) |
428 | 2383 { |
2384 Lisp_Object *tortoise = plist; | |
2385 Lisp_Object *hare = plist; | |
2386 | |
2387 while (!NILP (*tortoise)) | |
2388 { | |
2389 Lisp_Object *tortsave = tortoise; | |
2390 Lisp_Object retval; | |
2391 | |
2392 /* See above */ | |
2393 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2394 return; | |
2395 | |
2396 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2397 : internal_equal (XCAR (*tortsave), property, 0)) | |
2398 { | |
2399 XCAR (XCDR (*tortsave)) = value; | |
2400 return; | |
2401 } | |
2402 } | |
2403 | |
2404 *plist = Fcons (property, Fcons (value, *plist)); | |
2405 } | |
2406 | |
2407 int | |
2408 external_remprop (Lisp_Object *plist, Lisp_Object property, | |
578 | 2409 int laxp, Error_Behavior errb) |
428 | 2410 { |
2411 Lisp_Object *tortoise = plist; | |
2412 Lisp_Object *hare = plist; | |
2413 | |
2414 while (!NILP (*tortoise)) | |
2415 { | |
2416 Lisp_Object *tortsave = tortoise; | |
2417 Lisp_Object retval; | |
2418 | |
2419 /* See above */ | |
2420 if (!advance_plist_pointers (plist, &tortoise, &hare, errb, &retval)) | |
2421 return 0; | |
2422 | |
2423 if (!laxp ? EQ (XCAR (*tortsave), property) | |
2424 : internal_equal (XCAR (*tortsave), property, 0)) | |
2425 { | |
2426 /* Now you see why it's so convenient to have that level | |
2427 of indirection. */ | |
2428 *tortsave = XCDR (XCDR (*tortsave)); | |
2429 return 1; | |
2430 } | |
2431 } | |
2432 | |
2433 return 0; | |
2434 } | |
2435 | |
2436 DEFUN ("plist-get", Fplist_get, 2, 3, 0, /* | |
2437 Extract a value from a property list. | |
2438 PLIST is a property list, which is a list of the form | |
444 | 2439 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...). |
2440 PROPERTY is usually a symbol. | |
2441 This function returns the value corresponding to the PROPERTY, | |
2442 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 2443 */ |
444 | 2444 (plist, property, default_)) |
428 | 2445 { |
444 | 2446 Lisp_Object value = external_plist_get (&plist, property, 0, ERROR_ME); |
2447 return UNBOUNDP (value) ? default_ : value; | |
428 | 2448 } |
2449 | |
2450 DEFUN ("plist-put", Fplist_put, 3, 3, 0, /* | |
444 | 2451 Change value in PLIST of PROPERTY to VALUE. |
2452 PLIST is a property list, which is a list of the form | |
2453 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
2454 PROPERTY is usually a symbol and VALUE is any object. | |
2455 If PROPERTY is already a property on the list, its value is set to VALUE, | |
2456 otherwise the new PROPERTY VALUE pair is added. | |
2457 The new plist is returned; use `(setq x (plist-put x property value))' | |
2458 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 2459 */ |
444 | 2460 (plist, property, value)) |
428 | 2461 { |
444 | 2462 external_plist_put (&plist, property, value, 0, ERROR_ME); |
428 | 2463 return plist; |
2464 } | |
2465 | |
2466 DEFUN ("plist-remprop", Fplist_remprop, 2, 2, 0, /* | |
444 | 2467 Remove from PLIST the property PROPERTY and its value. |
2468 PLIST is a property list, which is a list of the form | |
2469 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2 ...). | |
2470 PROPERTY is usually a symbol. | |
2471 The new plist is returned; use `(setq x (plist-remprop x property))' | |
2472 to be sure to use the new value. PLIST is modified by side effect. | |
428 | 2473 */ |
444 | 2474 (plist, property)) |
428 | 2475 { |
444 | 2476 external_remprop (&plist, property, 0, ERROR_ME); |
428 | 2477 return plist; |
2478 } | |
2479 | |
2480 DEFUN ("plist-member", Fplist_member, 2, 2, 0, /* | |
444 | 2481 Return t if PROPERTY has a value specified in PLIST. |
428 | 2482 */ |
444 | 2483 (plist, property)) |
428 | 2484 { |
444 | 2485 Lisp_Object value = Fplist_get (plist, property, Qunbound); |
2486 return UNBOUNDP (value) ? Qnil : Qt; | |
428 | 2487 } |
2488 | |
2489 DEFUN ("check-valid-plist", Fcheck_valid_plist, 1, 1, 0, /* | |
2490 Given a plist, signal an error if there is anything wrong with it. | |
2491 This means that it's a malformed or circular plist. | |
2492 */ | |
2493 (plist)) | |
2494 { | |
2495 Lisp_Object *tortoise; | |
2496 Lisp_Object *hare; | |
2497 | |
2498 start_over: | |
2499 tortoise = &plist; | |
2500 hare = &plist; | |
2501 while (!NILP (*tortoise)) | |
2502 { | |
2503 Lisp_Object retval; | |
2504 | |
2505 /* See above */ | |
2506 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME, | |
2507 &retval)) | |
2508 goto start_over; | |
2509 } | |
2510 | |
2511 return Qnil; | |
2512 } | |
2513 | |
2514 DEFUN ("valid-plist-p", Fvalid_plist_p, 1, 1, 0, /* | |
2515 Given a plist, return non-nil if its format is correct. | |
2516 If it returns nil, `check-valid-plist' will signal an error when given | |
442 | 2517 the plist; that means it's a malformed or circular plist. |
428 | 2518 */ |
2519 (plist)) | |
2520 { | |
2521 Lisp_Object *tortoise; | |
2522 Lisp_Object *hare; | |
2523 | |
2524 tortoise = &plist; | |
2525 hare = &plist; | |
2526 while (!NILP (*tortoise)) | |
2527 { | |
2528 Lisp_Object retval; | |
2529 | |
2530 /* See above */ | |
2531 if (!advance_plist_pointers (&plist, &tortoise, &hare, ERROR_ME_NOT, | |
2532 &retval)) | |
2533 return Qnil; | |
2534 } | |
2535 | |
2536 return Qt; | |
2537 } | |
2538 | |
2539 DEFUN ("canonicalize-plist", Fcanonicalize_plist, 1, 2, 0, /* | |
2540 Destructively remove any duplicate entries from a plist. | |
2541 In such cases, the first entry applies. | |
2542 | |
2543 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2544 a nil value is removed. This feature is a virus that has infected | |
2545 old Lisp implementations, but should not be used except for backward | |
2546 compatibility. | |
2547 | |
2548 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
2549 return value may not be EQ to the passed-in value, so make sure to | |
2550 `setq' the value back into where it came from. | |
2551 */ | |
2552 (plist, nil_means_not_present)) | |
2553 { | |
2554 Lisp_Object head = plist; | |
2555 | |
2556 Fcheck_valid_plist (plist); | |
2557 | |
2558 while (!NILP (plist)) | |
2559 { | |
2560 Lisp_Object prop = Fcar (plist); | |
2561 Lisp_Object next = Fcdr (plist); | |
2562 | |
2563 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
2564 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
2565 { | |
2566 if (EQ (head, plist)) | |
2567 head = Fcdr (next); | |
2568 plist = Fcdr (next); | |
2569 continue; | |
2570 } | |
2571 /* external_remprop returns 1 if it removed any property. | |
2572 We have to loop till it didn't remove anything, in case | |
2573 the property occurs many times. */ | |
2574 while (external_remprop (&XCDR (next), prop, 0, ERROR_ME)) | |
2575 DO_NOTHING; | |
2576 plist = Fcdr (next); | |
2577 } | |
2578 | |
2579 return head; | |
2580 } | |
2581 | |
2582 DEFUN ("lax-plist-get", Flax_plist_get, 2, 3, 0, /* | |
2583 Extract a value from a lax property list. | |
444 | 2584 LAX-PLIST is a lax property list, which is a list of the form |
2585 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2586 properties is done using `equal' instead of `eq'. | |
2587 PROPERTY is usually a symbol. | |
2588 This function returns the value corresponding to PROPERTY, | |
2589 or DEFAULT if PROPERTY is not one of the properties on the list. | |
428 | 2590 */ |
444 | 2591 (lax_plist, property, default_)) |
428 | 2592 { |
444 | 2593 Lisp_Object value = external_plist_get (&lax_plist, property, 1, ERROR_ME); |
2594 return UNBOUNDP (value) ? default_ : value; | |
428 | 2595 } |
2596 | |
2597 DEFUN ("lax-plist-put", Flax_plist_put, 3, 3, 0, /* | |
444 | 2598 Change value in LAX-PLIST of PROPERTY to VALUE. |
2599 LAX-PLIST is a lax property list, which is a list of the form | |
2600 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2601 properties is done using `equal' instead of `eq'. | |
2602 PROPERTY is usually a symbol and VALUE is any object. | |
2603 If PROPERTY is already a property on the list, its value is set to | |
2604 VALUE, otherwise the new PROPERTY VALUE pair is added. | |
2605 The new plist is returned; use `(setq x (lax-plist-put x property value))' | |
2606 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 2607 */ |
444 | 2608 (lax_plist, property, value)) |
428 | 2609 { |
444 | 2610 external_plist_put (&lax_plist, property, value, 1, ERROR_ME); |
428 | 2611 return lax_plist; |
2612 } | |
2613 | |
2614 DEFUN ("lax-plist-remprop", Flax_plist_remprop, 2, 2, 0, /* | |
444 | 2615 Remove from LAX-PLIST the property PROPERTY and its value. |
2616 LAX-PLIST is a lax property list, which is a list of the form | |
2617 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2618 properties is done using `equal' instead of `eq'. | |
2619 PROPERTY is usually a symbol. | |
2620 The new plist is returned; use `(setq x (lax-plist-remprop x property))' | |
2621 to be sure to use the new value. LAX-PLIST is modified by side effect. | |
428 | 2622 */ |
444 | 2623 (lax_plist, property)) |
428 | 2624 { |
444 | 2625 external_remprop (&lax_plist, property, 1, ERROR_ME); |
428 | 2626 return lax_plist; |
2627 } | |
2628 | |
2629 DEFUN ("lax-plist-member", Flax_plist_member, 2, 2, 0, /* | |
444 | 2630 Return t if PROPERTY has a value specified in LAX-PLIST. |
2631 LAX-PLIST is a lax property list, which is a list of the form | |
2632 \(PROPERTY1 VALUE1 PROPERTY2 VALUE2...), where comparisons between | |
2633 properties is done using `equal' instead of `eq'. | |
428 | 2634 */ |
444 | 2635 (lax_plist, property)) |
428 | 2636 { |
444 | 2637 return UNBOUNDP (Flax_plist_get (lax_plist, property, Qunbound)) ? Qnil : Qt; |
428 | 2638 } |
2639 | |
2640 DEFUN ("canonicalize-lax-plist", Fcanonicalize_lax_plist, 1, 2, 0, /* | |
2641 Destructively remove any duplicate entries from a lax plist. | |
2642 In such cases, the first entry applies. | |
2643 | |
2644 If optional arg NIL-MEANS-NOT-PRESENT is non-nil, then a property with | |
2645 a nil value is removed. This feature is a virus that has infected | |
2646 old Lisp implementations, but should not be used except for backward | |
2647 compatibility. | |
2648 | |
2649 The new plist is returned. If NIL-MEANS-NOT-PRESENT is given, the | |
2650 return value may not be EQ to the passed-in value, so make sure to | |
2651 `setq' the value back into where it came from. | |
2652 */ | |
2653 (lax_plist, nil_means_not_present)) | |
2654 { | |
2655 Lisp_Object head = lax_plist; | |
2656 | |
2657 Fcheck_valid_plist (lax_plist); | |
2658 | |
2659 while (!NILP (lax_plist)) | |
2660 { | |
2661 Lisp_Object prop = Fcar (lax_plist); | |
2662 Lisp_Object next = Fcdr (lax_plist); | |
2663 | |
2664 CHECK_CONS (next); /* just make doubly sure we catch any errors */ | |
2665 if (!NILP (nil_means_not_present) && NILP (Fcar (next))) | |
2666 { | |
2667 if (EQ (head, lax_plist)) | |
2668 head = Fcdr (next); | |
2669 lax_plist = Fcdr (next); | |
2670 continue; | |
2671 } | |
2672 /* external_remprop returns 1 if it removed any property. | |
2673 We have to loop till it didn't remove anything, in case | |
2674 the property occurs many times. */ | |
2675 while (external_remprop (&XCDR (next), prop, 1, ERROR_ME)) | |
2676 DO_NOTHING; | |
2677 lax_plist = Fcdr (next); | |
2678 } | |
2679 | |
2680 return head; | |
2681 } | |
2682 | |
2683 /* In C because the frame props stuff uses it */ | |
2684 | |
2685 DEFUN ("destructive-alist-to-plist", Fdestructive_alist_to_plist, 1, 1, 0, /* | |
2686 Convert association list ALIST into the equivalent property-list form. | |
2687 The plist is returned. This converts from | |
2688 | |
2689 \((a . 1) (b . 2) (c . 3)) | |
2690 | |
2691 into | |
2692 | |
2693 \(a 1 b 2 c 3) | |
2694 | |
2695 The original alist is destroyed in the process of constructing the plist. | |
2696 See also `alist-to-plist'. | |
2697 */ | |
2698 (alist)) | |
2699 { | |
2700 Lisp_Object head = alist; | |
2701 while (!NILP (alist)) | |
2702 { | |
2703 /* remember the alist element. */ | |
2704 Lisp_Object el = Fcar (alist); | |
2705 | |
2706 Fsetcar (alist, Fcar (el)); | |
2707 Fsetcar (el, Fcdr (el)); | |
2708 Fsetcdr (el, Fcdr (alist)); | |
2709 Fsetcdr (alist, el); | |
2710 alist = Fcdr (Fcdr (alist)); | |
2711 } | |
2712 | |
2713 return head; | |
2714 } | |
2715 | |
2716 DEFUN ("get", Fget, 2, 3, 0, /* | |
442 | 2717 Return the value of OBJECT's PROPERTY property. |
2718 This is the last VALUE stored with `(put OBJECT PROPERTY VALUE)'. | |
428 | 2719 If there is no such property, return optional third arg DEFAULT |
442 | 2720 \(which defaults to `nil'). OBJECT can be a symbol, string, extent, |
2721 face, or glyph. See also `put', `remprop', and `object-plist'. | |
428 | 2722 */ |
442 | 2723 (object, property, default_)) |
428 | 2724 { |
2725 /* Various places in emacs call Fget() and expect it not to quit, | |
2726 so don't quit. */ | |
442 | 2727 Lisp_Object val; |
2728 | |
2729 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->getprop) | |
2730 val = XRECORD_LHEADER_IMPLEMENTATION (object)->getprop (object, property); | |
428 | 2731 else |
563 | 2732 invalid_operation ("Object type has no properties", object); |
442 | 2733 |
2734 return UNBOUNDP (val) ? default_ : val; | |
428 | 2735 } |
2736 | |
2737 DEFUN ("put", Fput, 3, 3, 0, /* | |
442 | 2738 Set OBJECT's PROPERTY to VALUE. |
2739 It can be subsequently retrieved with `(get OBJECT PROPERTY)'. | |
2740 OBJECT can be a symbol, face, extent, or string. | |
428 | 2741 For a string, no properties currently have predefined meanings. |
2742 For the predefined properties for extents, see `set-extent-property'. | |
2743 For the predefined properties for faces, see `set-face-property'. | |
2744 See also `get', `remprop', and `object-plist'. | |
2745 */ | |
442 | 2746 (object, property, value)) |
428 | 2747 { |
1920 | 2748 /* This function cannot GC */ |
428 | 2749 CHECK_LISP_WRITEABLE (object); |
2750 | |
442 | 2751 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->putprop) |
428 | 2752 { |
442 | 2753 if (! XRECORD_LHEADER_IMPLEMENTATION (object)->putprop |
2754 (object, property, value)) | |
563 | 2755 invalid_change ("Can't set property on object", property); |
428 | 2756 } |
2757 else | |
563 | 2758 invalid_change ("Object type has no settable properties", object); |
428 | 2759 |
2760 return value; | |
2761 } | |
2762 | |
2763 DEFUN ("remprop", Fremprop, 2, 2, 0, /* | |
442 | 2764 Remove, from OBJECT's property list, PROPERTY and its corresponding value. |
2765 OBJECT can be a symbol, string, extent, face, or glyph. Return non-nil | |
2766 if the property list was actually modified (i.e. if PROPERTY was present | |
2767 in the property list). See also `get', `put', and `object-plist'. | |
428 | 2768 */ |
442 | 2769 (object, property)) |
428 | 2770 { |
442 | 2771 int ret = 0; |
2772 | |
428 | 2773 CHECK_LISP_WRITEABLE (object); |
2774 | |
442 | 2775 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->remprop) |
428 | 2776 { |
442 | 2777 ret = XRECORD_LHEADER_IMPLEMENTATION (object)->remprop (object, property); |
2778 if (ret == -1) | |
563 | 2779 invalid_change ("Can't remove property from object", property); |
428 | 2780 } |
2781 else | |
563 | 2782 invalid_change ("Object type has no removable properties", object); |
442 | 2783 |
2784 return ret ? Qt : Qnil; | |
428 | 2785 } |
2786 | |
2787 DEFUN ("object-plist", Fobject_plist, 1, 1, 0, /* | |
442 | 2788 Return a property list of OBJECT's properties. |
2789 For a symbol, this is equivalent to `symbol-plist'. | |
2790 OBJECT can be a symbol, string, extent, face, or glyph. | |
2791 Do not modify the returned property list directly; | |
2792 this may or may not have the desired effects. Use `put' instead. | |
428 | 2793 */ |
2794 (object)) | |
2795 { | |
442 | 2796 if (LRECORDP (object) && XRECORD_LHEADER_IMPLEMENTATION (object)->plist) |
2797 return XRECORD_LHEADER_IMPLEMENTATION (object)->plist (object); | |
428 | 2798 else |
563 | 2799 invalid_operation ("Object type has no properties", object); |
428 | 2800 |
2801 return Qnil; | |
2802 } | |
2803 | |
2804 | |
853 | 2805 static Lisp_Object |
2806 tweaked_internal_equal (Lisp_Object obj1, Lisp_Object obj2, | |
2807 Lisp_Object depth) | |
2808 { | |
2809 return make_int (internal_equal (obj1, obj2, XINT (depth))); | |
2810 } | |
2811 | |
2812 int | |
2813 internal_equal_trapping_problems (Lisp_Object warning_class, | |
2814 const char *warning_string, | |
2815 int flags, | |
2816 struct call_trapping_problems_result *p, | |
2817 int retval, | |
2818 Lisp_Object obj1, Lisp_Object obj2, | |
2819 int depth) | |
2820 { | |
2821 Lisp_Object glorp = | |
2822 va_call_trapping_problems (warning_class, warning_string, | |
2823 flags, p, | |
2824 (lisp_fn_t) tweaked_internal_equal, | |
2825 3, obj1, obj2, make_int (depth)); | |
2826 if (UNBOUNDP (glorp)) | |
2827 return retval; | |
2828 else | |
2829 return XINT (glorp); | |
2830 } | |
2831 | |
428 | 2832 int |
2833 internal_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2834 { | |
2835 if (depth > 200) | |
563 | 2836 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 2837 QUIT; |
2838 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) | |
2839 return 1; | |
2840 /* Note that (equal 20 20.0) should be nil */ | |
2841 if (XTYPE (obj1) != XTYPE (obj2)) | |
2842 return 0; | |
2843 if (LRECORDP (obj1)) | |
2844 { | |
442 | 2845 const struct lrecord_implementation |
428 | 2846 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), |
2847 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
2848 | |
2849 return (imp1 == imp2) && | |
2850 /* EQ-ness of the objects was noticed above */ | |
2851 (imp1->equal && (imp1->equal) (obj1, obj2, depth)); | |
2852 } | |
2853 | |
2854 return 0; | |
2855 } | |
2856 | |
801 | 2857 int |
2858 internal_equalp (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2859 { | |
2860 if (depth > 200) | |
2861 stack_overflow ("Stack overflow in equalp", Qunbound); | |
2862 QUIT; | |
2863 if (EQ_WITH_EBOLA_NOTICE (obj1, obj2)) | |
2864 return 1; | |
1983 | 2865 #ifdef WITH_NUMBER_TYPES |
2866 if (NUMBERP (obj1) && NUMBERP (obj2)) | |
2867 { | |
2868 switch (promote_args (&obj1, &obj2)) | |
2869 { | |
2870 case FIXNUM_T: | |
2871 return XREALINT (obj1) == XREALINT (obj2); | |
2872 #ifdef HAVE_BIGNUM | |
2873 case BIGNUM_T: | |
2874 return bignum_eql (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)); | |
2875 #endif | |
2876 #ifdef HAVE_RATIO | |
2877 case RATIO_T: | |
2878 return ratio_eql (XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
2879 #endif | |
2880 case FLOAT_T: | |
2881 return XFLOAT_DATA (obj1) == XFLOAT_DATA (obj2); | |
2882 #ifdef HAVE_BIGFLOAT | |
2883 case BIGFLOAT_T: | |
2884 return bigfloat_eql (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)); | |
2885 #endif | |
2886 } | |
2887 } | |
2888 #else | |
801 | 2889 if ((INTP (obj1) && FLOATP (obj2)) || (FLOATP (obj1) && INTP (obj2))) |
2890 return extract_float (obj1) == extract_float (obj2); | |
1983 | 2891 #endif |
801 | 2892 if (CHARP (obj1) && CHARP (obj2)) |
2893 return DOWNCASE (0, XCHAR (obj1)) == DOWNCASE (0, XCHAR (obj2)); | |
2894 if (XTYPE (obj1) != XTYPE (obj2)) | |
2895 return 0; | |
2896 if (LRECORDP (obj1)) | |
2897 { | |
2898 const struct lrecord_implementation | |
2899 *imp1 = XRECORD_LHEADER_IMPLEMENTATION (obj1), | |
2900 *imp2 = XRECORD_LHEADER_IMPLEMENTATION (obj2); | |
2901 | |
2902 /* #### not yet implemented properly, needs another flag to specify | |
2903 equalp-ness */ | |
2904 return (imp1 == imp2) && | |
2905 /* EQ-ness of the objects was noticed above */ | |
2906 (imp1->equal && (imp1->equal) (obj1, obj2, depth)); | |
2907 } | |
2908 | |
2909 return 0; | |
2910 } | |
2911 | |
428 | 2912 /* Note that we may be calling sub-objects that will use |
2913 internal_equal() (instead of internal_old_equal()). Oh well. | |
2914 We will get an Ebola note if there's any possibility of confusion, | |
2915 but that seems unlikely. */ | |
2916 | |
2917 static int | |
2918 internal_old_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2919 { | |
2920 if (depth > 200) | |
563 | 2921 stack_overflow ("Stack overflow in equal", Qunbound); |
428 | 2922 QUIT; |
2923 if (HACKEQ_UNSAFE (obj1, obj2)) | |
2924 return 1; | |
2925 /* Note that (equal 20 20.0) should be nil */ | |
2926 if (XTYPE (obj1) != XTYPE (obj2)) | |
2927 return 0; | |
2928 | |
2929 return internal_equal (obj1, obj2, depth); | |
2930 } | |
2931 | |
2932 DEFUN ("equal", Fequal, 2, 2, 0, /* | |
2933 Return t if two Lisp objects have similar structure and contents. | |
2934 They must have the same data type. | |
2935 Conses are compared by comparing the cars and the cdrs. | |
2936 Vectors and strings are compared element by element. | |
2937 Numbers are compared by value. Symbols must match exactly. | |
2938 */ | |
444 | 2939 (object1, object2)) |
428 | 2940 { |
444 | 2941 return internal_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 2942 } |
2943 | |
2944 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /* | |
2945 Return t if two Lisp objects have similar structure and contents. | |
2946 They must have the same data type. | |
2947 \(Note, however, that an exception is made for characters and integers; | |
2948 this is known as the "char-int confoundance disease." See `eq' and | |
2949 `old-eq'.) | |
2950 This function is provided only for byte-code compatibility with v19. | |
2951 Do not use it. | |
2952 */ | |
444 | 2953 (object1, object2)) |
428 | 2954 { |
444 | 2955 return internal_old_equal (object1, object2, 0) ? Qt : Qnil; |
428 | 2956 } |
2957 | |
2958 | |
2959 DEFUN ("fillarray", Ffillarray, 2, 2, 0, /* | |
434 | 2960 Destructively modify ARRAY by replacing each element with ITEM. |
428 | 2961 ARRAY is a vector, bit vector, or string. |
2962 */ | |
2963 (array, item)) | |
2964 { | |
2965 retry: | |
2966 if (STRINGP (array)) | |
2967 { | |
793 | 2968 Bytecount old_bytecount = XSTRING_LENGTH (array); |
434 | 2969 Bytecount new_bytecount; |
2970 Bytecount item_bytecount; | |
867 | 2971 Ibyte item_buf[MAX_ICHAR_LEN]; |
2972 Ibyte *p; | |
2973 Ibyte *end; | |
434 | 2974 |
428 | 2975 CHECK_CHAR_COERCE_INT (item); |
2720 | 2976 |
428 | 2977 CHECK_LISP_WRITEABLE (array); |
771 | 2978 sledgehammer_check_ascii_begin (array); |
867 | 2979 item_bytecount = set_itext_ichar (item_buf, XCHAR (item)); |
826 | 2980 new_bytecount = item_bytecount * (Bytecount) string_char_length (array); |
793 | 2981 |
2982 resize_string (array, -1, new_bytecount - old_bytecount); | |
2983 | |
2984 for (p = XSTRING_DATA (array), end = p + new_bytecount; | |
434 | 2985 p < end; |
2986 p += item_bytecount) | |
2987 memcpy (p, item_buf, item_bytecount); | |
2988 *p = '\0'; | |
2989 | |
793 | 2990 XSET_STRING_ASCII_BEGIN (array, |
2991 item_bytecount == 1 ? | |
2992 min (new_bytecount, MAX_STRING_ASCII_BEGIN) : | |
2993 0); | |
428 | 2994 bump_string_modiff (array); |
771 | 2995 sledgehammer_check_ascii_begin (array); |
428 | 2996 } |
2997 else if (VECTORP (array)) | |
2998 { | |
2999 Lisp_Object *p = XVECTOR_DATA (array); | |
665 | 3000 Elemcount len = XVECTOR_LENGTH (array); |
428 | 3001 CHECK_LISP_WRITEABLE (array); |
3002 while (len--) | |
3003 *p++ = item; | |
3004 } | |
3005 else if (BIT_VECTORP (array)) | |
3006 { | |
440 | 3007 Lisp_Bit_Vector *v = XBIT_VECTOR (array); |
665 | 3008 Elemcount len = bit_vector_length (v); |
428 | 3009 int bit; |
3010 CHECK_BIT (item); | |
444 | 3011 bit = XINT (item); |
428 | 3012 CHECK_LISP_WRITEABLE (array); |
3013 while (len--) | |
3014 set_bit_vector_bit (v, len, bit); | |
3015 } | |
3016 else | |
3017 { | |
3018 array = wrong_type_argument (Qarrayp, array); | |
3019 goto retry; | |
3020 } | |
3021 return array; | |
3022 } | |
3023 | |
3024 Lisp_Object | |
3025 nconc2 (Lisp_Object arg1, Lisp_Object arg2) | |
3026 { | |
3027 Lisp_Object args[2]; | |
3028 struct gcpro gcpro1; | |
3029 args[0] = arg1; | |
3030 args[1] = arg2; | |
3031 | |
3032 GCPRO1 (args[0]); | |
3033 gcpro1.nvars = 2; | |
3034 | |
3035 RETURN_UNGCPRO (bytecode_nconc2 (args)); | |
3036 } | |
3037 | |
3038 Lisp_Object | |
3039 bytecode_nconc2 (Lisp_Object *args) | |
3040 { | |
3041 retry: | |
3042 | |
3043 if (CONSP (args[0])) | |
3044 { | |
3045 /* (setcdr (last args[0]) args[1]) */ | |
3046 Lisp_Object tortoise, hare; | |
665 | 3047 Elemcount count; |
428 | 3048 |
3049 for (hare = tortoise = args[0], count = 0; | |
3050 CONSP (XCDR (hare)); | |
3051 hare = XCDR (hare), count++) | |
3052 { | |
3053 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3054 | |
3055 if (count & 1) | |
3056 tortoise = XCDR (tortoise); | |
3057 if (EQ (hare, tortoise)) | |
3058 signal_circular_list_error (args[0]); | |
3059 } | |
3060 XCDR (hare) = args[1]; | |
3061 return args[0]; | |
3062 } | |
3063 else if (NILP (args[0])) | |
3064 { | |
3065 return args[1]; | |
3066 } | |
3067 else | |
3068 { | |
3069 args[0] = wrong_type_argument (args[0], Qlistp); | |
3070 goto retry; | |
3071 } | |
3072 } | |
3073 | |
3074 DEFUN ("nconc", Fnconc, 0, MANY, 0, /* | |
3075 Concatenate any number of lists by altering them. | |
3076 Only the last argument is not altered, and need not be a list. | |
3077 Also see: `append'. | |
3078 If the first argument is nil, there is no way to modify it by side | |
3079 effect; therefore, write `(setq foo (nconc foo list))' to be sure of | |
3080 changing the value of `foo'. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
3081 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3842
diff
changeset
|
3082 arguments: (&rest ARGS) |
428 | 3083 */ |
3084 (int nargs, Lisp_Object *args)) | |
3085 { | |
3086 int argnum = 0; | |
3087 struct gcpro gcpro1; | |
3088 | |
3089 /* The modus operandi in Emacs is "caller gc-protects args". | |
3090 However, nconc (particularly nconc2 ()) is called many times | |
3091 in Emacs on freshly created stuff (e.g. you see the idiom | |
3092 nconc2 (Fcopy_sequence (foo), bar) a lot). So we help those | |
3093 callers out by protecting the args ourselves to save them | |
3094 a lot of temporary-variable grief. */ | |
3095 | |
3096 GCPRO1 (args[0]); | |
3097 gcpro1.nvars = nargs; | |
3098 | |
3099 while (argnum < nargs) | |
3100 { | |
3101 Lisp_Object val; | |
3102 retry: | |
3103 val = args[argnum]; | |
3104 if (CONSP (val)) | |
3105 { | |
3106 /* `val' is the first cons, which will be our return value. */ | |
3107 /* `last_cons' will be the cons cell to mutate. */ | |
3108 Lisp_Object last_cons = val; | |
3109 Lisp_Object tortoise = val; | |
3110 | |
3111 for (argnum++; argnum < nargs; argnum++) | |
3112 { | |
3113 Lisp_Object next = args[argnum]; | |
3114 retry_next: | |
3115 if (CONSP (next) || argnum == nargs -1) | |
3116 { | |
3117 /* (setcdr (last val) next) */ | |
665 | 3118 Elemcount count; |
428 | 3119 |
3120 for (count = 0; | |
3121 CONSP (XCDR (last_cons)); | |
3122 last_cons = XCDR (last_cons), count++) | |
3123 { | |
3124 if (count < CIRCULAR_LIST_SUSPICION_LENGTH) continue; | |
3125 | |
3126 if (count & 1) | |
3127 tortoise = XCDR (tortoise); | |
3128 if (EQ (last_cons, tortoise)) | |
3129 signal_circular_list_error (args[argnum-1]); | |
3130 } | |
3131 XCDR (last_cons) = next; | |
3132 } | |
3133 else if (NILP (next)) | |
3134 { | |
3135 continue; | |
3136 } | |
3137 else | |
3138 { | |
3139 next = wrong_type_argument (Qlistp, next); | |
3140 goto retry_next; | |
3141 } | |
3142 } | |
3143 RETURN_UNGCPRO (val); | |
3144 } | |
3145 else if (NILP (val)) | |
3146 argnum++; | |
3147 else if (argnum == nargs - 1) /* last arg? */ | |
3148 RETURN_UNGCPRO (val); | |
3149 else | |
3150 { | |
3151 args[argnum] = wrong_type_argument (Qlistp, val); | |
3152 goto retry; | |
3153 } | |
3154 } | |
3155 RETURN_UNGCPRO (Qnil); /* No non-nil args provided. */ | |
3156 } | |
3157 | |
3158 | |
434 | 3159 /* This is the guts of several mapping functions. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3160 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3161 Call FUNCTION CALL_COUNT times, with NSEQUENCES arguments each time, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3162 taking the elements from SEQUENCES. If VALS is non-NULL, store the |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3163 results into VALS, a C array of Lisp_Objects; else, if LISP_VALS is |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3164 non-nil, store the results into LISP_VALS, a sequence with sufficient |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3165 room for CALL_COUNT results. Else, do not accumulate any result. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3166 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3167 If VALS is non-NULL, NSEQUENCES is one, and SEQUENCES[0] is a cons, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3168 mapcarX will store the elements of SEQUENCES[0] in stack and GCPRO them, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3169 so FUNCTION cannot insert a non-cons into SEQUENCES[0] and throw off |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3170 mapcarX. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3171 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3172 Otherwise, mapcarX signals a wrong-type-error if it encounters a |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3173 non-cons, non-array when traversing SEQUENCES. Common Lisp specifies in |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3174 MAPPING-DESTRUCTIVE-INTERACTION that it is an error when FUNCTION |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3175 destructively modifies SEQUENCES in a way that might affect the ongoing |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3176 traversal operation. */ |
428 | 3177 |
3178 static void | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3179 mapcarX (Elemcount call_count, Lisp_Object *vals, Lisp_Object lisp_vals, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3180 Lisp_Object function, int nsequences, Lisp_Object *sequences) |
428 | 3181 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3182 Lisp_Object called, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3183 struct gcpro gcpro1, gcpro2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3184 int i, j; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3185 enum lrecord_type lisp_vals_type; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3186 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3187 assert (LRECORDP (lisp_vals)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3188 lisp_vals_type = XRECORD_LHEADER (lisp_vals)->type; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3189 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3190 args = alloca_array (Lisp_Object, nsequences + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3191 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3192 for (i = 1; i <= nsequences; ++i) |
428 | 3193 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3194 args[i] = Qnil; |
428 | 3195 } |
3196 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3197 if (vals != NULL) |
428 | 3198 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3199 GCPRO2 (args[0], vals[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3200 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3201 gcpro2.nvars = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3202 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3203 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3204 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3205 GCPRO1 (args[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3206 gcpro1.nvars = nsequences + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3207 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3208 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3209 /* Be extra nice in the event that we've been handed one list and one |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3210 only; make it possible for FUNCTION to set cdrs not yet processed to |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3211 non-cons, non-nil objects without ill-effect, if we have been handed |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3212 the stack space to do that. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3213 if (vals != NULL && 1 == nsequences && CONSP (sequences[0])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3214 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3215 Lisp_Object lst = sequences[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3216 Lisp_Object *val = vals; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3217 for (i = 0; i < call_count; ++i) |
434 | 3218 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3219 *val++ = XCAR (lst); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3220 lst = XCDR (lst); |
428 | 3221 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3222 gcpro2.nvars = call_count; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3223 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3224 for (i = 0; i < call_count; ++i) |
428 | 3225 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3226 args[1] = vals[i]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3227 vals[i] = Ffuncall (nsequences + 1, args); |
428 | 3228 } |
3229 } | |
3230 else | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3231 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3232 Binbyte *sequence_types = alloca_array (Binbyte, nsequences); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3233 for (j = 0; j < nsequences; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3234 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3235 sequence_types[j] = XRECORD_LHEADER (sequences[j])->type; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3236 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3237 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3238 for (i = 0; i < call_count; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3239 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3240 for (j = 0; j < nsequences; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3241 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3242 switch (sequence_types[j]) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3243 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3244 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3245 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3246 if (!CONSP (sequences[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3247 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3248 /* This means FUNCTION has probably messed |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3249 around with a cons in one of the sequences, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3250 since we checked the type |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3251 (CHECK_SEQUENCE()) and the length and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3252 structure (with Flength()) correctly in our |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3253 callers. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3254 dead_wrong_type_argument (Qconsp, sequences[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3255 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3256 args[j + 1] = XCAR (sequences[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3257 sequences[j] = XCDR (sequences[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3258 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3259 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3260 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3261 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3262 args[j + 1] = XVECTOR_DATA (sequences[j])[i]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3263 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3264 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3265 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3266 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3267 args[j + 1] = make_char (string_ichar (sequences[j], i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3268 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3269 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3270 case lrecord_type_bit_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3271 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3272 args[j + 1] |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3273 = make_int (bit_vector_bit (XBIT_VECTOR (sequences[j]), |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3274 i)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3275 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3276 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3277 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3278 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3279 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3280 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3281 called = Ffuncall (nsequences + 1, args); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3282 if (vals != NULL) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3283 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3284 vals[i] = called; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3285 gcpro2.nvars += 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3286 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3287 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3288 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3289 switch (lisp_vals_type) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3290 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3291 case lrecord_type_symbol: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3292 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3293 case lrecord_type_cons: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3294 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3295 if (!CONSP (lisp_vals)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3296 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3297 /* If FUNCTION has inserted a non-cons non-nil cdr |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3298 into the list before we've processed the relevant |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3299 part, error. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3300 dead_wrong_type_argument (Qconsp, lisp_vals); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3301 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3302 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3303 XSETCAR (lisp_vals, called); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3304 lisp_vals = XCDR (lisp_vals); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3305 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3306 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3307 case lrecord_type_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3308 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3309 i < XVECTOR_LENGTH (lisp_vals) ? |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3310 (XVECTOR_DATA (lisp_vals)[i] = called) : |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3311 /* Let #'aset error. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3312 Faset (lisp_vals, make_int (i), called); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3313 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3314 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3315 case lrecord_type_string: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3316 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3317 /* If this ever becomes a code hotspot, we can keep |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3318 around pointers into the data of the string, checking |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3319 each time that it hasn't been relocated. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3320 Faset (lisp_vals, make_int (i), called); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3321 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3322 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3323 case lrecord_type_bit_vector: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3324 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3325 (BITP (called) && |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3326 i < bit_vector_length (XBIT_VECTOR (lisp_vals))) ? |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3327 set_bit_vector_bit (XBIT_VECTOR (lisp_vals), i, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3328 XINT (called)) : |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3329 Faset (lisp_vals, make_int (i), called); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3330 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3331 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3332 default: |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3333 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3334 ABORT(); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3335 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3336 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3337 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3338 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3339 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3340 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3341 UNGCPRO; |
428 | 3342 } |
3343 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3344 DEFUN ("mapconcat", Fmapconcat, 3, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3345 Call FUNCTION on each element of SEQUENCE, and concat results to a string. |
751 | 3346 Between each pair of results, insert SEPARATOR. |
3347 | |
3348 Each result, and SEPARATOR, should be strings. Thus, using " " as SEPARATOR | |
3349 results in spaces between the values returned by FUNCTION. SEQUENCE itself | |
3350 may be a list, a vector, a bit vector, or a string. | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3351 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3352 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3353 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3354 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3355 `mapconcat' will give up once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3356 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3357 arguments: (FUNCTION SEQUENCE SEPARATOR &rest SEQUENCES) |
428 | 3358 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3359 (int nargs, Lisp_Object *args)) |
428 | 3360 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3361 Lisp_Object function = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3362 Lisp_Object sequence = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3363 Lisp_Object separator = args[2]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3364 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3365 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3366 EMACS_INT i, nargs0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3367 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3368 args[2] = sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3369 args[1] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3370 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3371 for (i = 2; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3372 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3373 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3374 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3375 } |
428 | 3376 |
442 | 3377 if (len == 0) return build_string (""); |
428 | 3378 |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3379 nargs0 = len + len - 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3380 args0 = alloca_array (Lisp_Object, nargs0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3381 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3382 /* Special-case this, it's very common and doesn't require any |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3383 funcalls. Upside of doing it here, instead of cl-macs.el: no consing, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3384 apart from the final string, we allocate everything on the stack. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3385 if (EQ (function, Qidentity) && 3 == nargs && CONSP (sequence)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3386 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3387 for (i = 0; i < len; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3388 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3389 args0[i] = XCAR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3390 sequence = XCDR (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3391 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3392 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3393 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3394 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3395 mapcarX (len, args0, Qnil, function, nargs - 2, args + 2); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3396 } |
428 | 3397 |
3398 for (i = len - 1; i >= 0; i--) | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3399 args0[i + i] = args0[i]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3400 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3401 for (i = 1; i < nargs0; i += 2) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3402 args0[i] = separator; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3403 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3404 return Fconcat (nargs0, args0); |
428 | 3405 } |
3406 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3407 DEFUN ("mapcar*", FmapcarX, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3408 Call FUNCTION on each element of SEQUENCE; return a list of the results. |
434 | 3409 The result is a list of the same length as SEQUENCE. |
428 | 3410 SEQUENCE may be a list, a vector, a bit vector, or a string. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3411 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3412 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3413 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3414 from each sequence will be used each time FUNCTION is called, and `mapcar' |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3415 stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3416 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3417 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3418 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3419 (int nargs, Lisp_Object *args)) |
428 | 3420 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3421 Lisp_Object function = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3422 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3423 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3424 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3425 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3426 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3427 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3428 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3429 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3430 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3431 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3432 args0 = alloca_array (Lisp_Object, len); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3433 mapcarX (len, args0, Qnil, function, nargs - 1, args + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3434 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3435 return Flist ((int) len, args0); |
428 | 3436 } |
3437 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3438 DEFUN ("mapvector", Fmapvector, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3439 Call FUNCTION on each element of SEQUENCE; return a vector of the results. |
428 | 3440 The result is a vector of the same length as SEQUENCE. |
434 | 3441 SEQUENCE may be a list, a vector, a bit vector, or a string. |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3442 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3443 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3444 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3445 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3446 `mapvector' stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3447 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3448 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3449 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3450 (int nargs, Lisp_Object *args)) |
428 | 3451 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3452 Lisp_Object function = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3453 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3454 Lisp_Object result; |
428 | 3455 struct gcpro gcpro1; |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3456 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3457 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3458 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3459 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3460 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3461 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3462 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3463 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3464 result = make_vector (len, Qnil); |
428 | 3465 GCPRO1 (result); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3466 /* Don't pass result as the lisp_object argument, we want mapcarX to protect |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3467 a single list argument's elements from being garbage-collected. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3468 mapcarX (len, XVECTOR_DATA (result), Qnil, function, nargs - 1, args +1); |
428 | 3469 UNGCPRO; |
3470 | |
3471 return result; | |
3472 } | |
3473 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3474 DEFUN ("mapcan", Fmapcan, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3475 Call FUNCTION on each element of SEQUENCE; chain the results together. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3476 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3477 FUNCTION must normally return a list; the results will be concatenated |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3478 together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3479 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3480 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3481 there are SEQUENCES, plus one for the element from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3482 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3483 `mapcan' stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3484 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3485 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3486 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3487 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3488 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3489 Lisp_Object function = args[0], nconcing; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3490 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3491 Lisp_Object *args0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3492 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3493 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3494 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3495 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3496 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3497 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3498 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3499 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3500 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3501 args0 = alloca_array (Lisp_Object, len + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3502 mapcarX (len, args0 + 1, Qnil, function, nargs - 1, args + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3503 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3504 if (len < 2) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3505 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3506 return len ? args0[1] : Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3507 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3508 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3509 /* bytecode_nconc2 can signal and return, we need to GCPRO the args, since |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3510 mapcarX is no longer doing this for us. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3511 args0[0] = Fcons (Qnil, Qnil); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3512 GCPRO1 (args0[0]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3513 gcpro1.nvars = len + 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3514 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3515 for (i = 0; i < len; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3516 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3517 nconcing = bytecode_nconc2 (args0 + i); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3518 args0[i + 1] = nconcing; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3519 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3520 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3521 RETURN_UNGCPRO (XCDR (nconcing)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3522 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3523 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3524 DEFUN ("mapc", Fmapc, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3525 Call FUNCTION on each element of SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3526 |
428 | 3527 SEQUENCE may be a list, a vector, a bit vector, or a string. |
3528 This function is like `mapcar' but does not accumulate the results, | |
3529 which is more efficient if you do not use the results. | |
3530 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3531 With optional SEQUENCES, call FUNCTION each time with as many arguments as |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3532 there are SEQUENCES, plus one for the elements from SEQUENCE. One element |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3533 from each sequence will be used each time FUNCTION is called, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3534 `mapc' stops calling FUNCTION once the shortest sequence is exhausted. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3535 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3536 Return SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3537 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3538 arguments: (FUNCTION SEQUENCE &rest SEQUENCES) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3539 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3540 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3541 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3542 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3543 Lisp_Object sequence = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3544 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3545 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3546 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3547 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3548 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3549 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3550 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3551 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3552 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3553 /* We need to GCPRO sequence, because mapcarX will modify the |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3554 elements of the args array handed to it, and this may involve |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3555 elements of sequence getting garbage collected. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3556 GCPRO1 (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3557 mapcarX (len, NULL, Qnil, args[0], nargs - 1, args + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3558 RETURN_UNGCPRO (sequence); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3559 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3560 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3561 DEFUN ("map", Fmap, 3, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3562 Map FUNCTION across one or more sequences, returning a sequence. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3563 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3564 TYPE is the sequence type to return, FUNCTION is the function, SEQUENCE is |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3565 the first argument sequence, SEQUENCES are the other argument sequences. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3566 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3567 FUNCTION will be called with (1+ (length SEQUENCES)) arguments, and must be |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3568 capable of accepting this number of arguments. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3569 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3570 Certain TYPEs are recognised internally by `map', but others are not, and |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3571 `coerce' may throw an error on an attempt to convert to a TYPE it does not |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3572 understand. A null TYPE means do not accumulate any values. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3573 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3574 arguments: (TYPE FUNCTION SEQUENCE &rest SEQUENCES) |
428 | 3575 */ |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3576 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3577 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3578 Lisp_Object type = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3579 Lisp_Object function = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3580 Lisp_Object result = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3581 Lisp_Object *args0 = NULL; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3582 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3583 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3584 struct gcpro gcpro1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3585 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3586 for (i = 2; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3587 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3588 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3589 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3590 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3591 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3592 if (!NILP (type)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3593 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3594 args0 = alloca_array (Lisp_Object, len); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3595 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3596 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3597 mapcarX (len, args0, Qnil, function, nargs - 2, args + 2); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3598 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3599 if (EQ (type, Qnil)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3600 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3601 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3602 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3603 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3604 if (EQ (type, Qvector) || EQ (type, Qarray)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3605 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3606 result = Fvector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3607 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3608 else if (EQ (type, Qstring)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3609 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3610 result = Fstring (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3611 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3612 else if (EQ (type, Qlist)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3613 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3614 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3615 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3616 else if (EQ (type, Qbit_vector)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3617 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3618 result = Fbit_vector (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3619 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3620 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3621 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3622 result = Flist (len, args0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3623 GCPRO1 (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3624 result = call2 (Qcoerce, result, type); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3625 UNGCPRO; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3626 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3627 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3628 return result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3629 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3630 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3631 DEFUN ("map-into", Fmap_into, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3632 Modify RESULT-SEQUENCE using the return values of FUNCTION on SEQUENCES. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3633 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3634 RESULT-SEQUENCE and SEQUENCES can be lists or arrays. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3635 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3636 FUNCTION must accept at least as many arguments as there are SEQUENCES |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3637 \(possibly zero). If RESULT-SEQUENCE and the elements of SEQUENCES are not |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3638 the same length, stop when the shortest is exhausted; any elements of |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3639 RESULT-SEQUENCE beyond that are unmodified. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3640 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3641 Return RESULT-SEQUENCE. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3642 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3643 arguments: (RESULT-SEQUENCE FUNCTION &rest SEQUENCES) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3644 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3645 (int nargs, Lisp_Object *args)) |
428 | 3646 { |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3647 Elemcount len = EMACS_INT_MAX; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3648 Lisp_Object result_sequence = args[0]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3649 Lisp_Object function = args[1]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3650 int i; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3651 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3652 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3653 args[1] = result_sequence; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3654 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3655 for (i = 1; i < nargs; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3656 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3657 CHECK_SEQUENCE (args[i]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3658 len = min (len, XINT (Flength (args[i]))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3659 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3660 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3661 mapcarX (len, NULL, result_sequence, function, nargs - 2, args + 2); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3662 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3663 return result_sequence; |
428 | 3664 } |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3665 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3666 /* Call FUNCTION with NLISTS arguments repeatedly, each Nth argument |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3667 corresponding to the result of calling (nthcdr ITERATION-COUNT LISTS[N]), |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3668 until that #'nthcdr expression gives nil for some element of LISTS. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3669 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3670 If MAPLP is zero, return LISTS[0]. Otherwise, return a list of the return |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3671 values from FUNCTION; if NCONCP is non-zero, nconc them together. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3672 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3673 In contrast to mapcarX, we don't require our callers to check LISTS for |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3674 well-formedness, we signal wrong-type-argument if it's not a list, or |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3675 circular-list if it's circular. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3676 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3677 static Lisp_Object |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3678 maplist (Lisp_Object function, int nlists, Lisp_Object *lists, int maplp, |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3679 int nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3680 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3681 Lisp_Object result = maplp ? lists[0] : Fcons (Qnil, Qnil), funcalled; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3682 Lisp_Object nconcing[2], accum = result, *args; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3683 struct gcpro gcpro1, gcpro2, gcpro3; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3684 int i, j, continuing = (nlists > 0), called_count = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3685 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3686 args = alloca_array (Lisp_Object, nlists + 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3687 args[0] = function; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3688 for (i = 1; i <= nlists; ++i) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3689 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3690 args[i] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3691 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3692 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3693 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3694 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3695 nconcing[0] = result; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3696 nconcing[1] = Qnil; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3697 GCPRO3 (args[0], nconcing[0], result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3698 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3699 gcpro2.nvars = 2; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3700 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3701 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3702 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3703 GCPRO2 (args[0], result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3704 gcpro1.nvars = 1; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3705 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3706 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3707 while (continuing) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3708 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3709 for (j = 0; j < nlists; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3710 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3711 if (CONSP (lists[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3712 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3713 args[j + 1] = lists[j]; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3714 lists[j] = XCDR (lists[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3715 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3716 else if (NILP (lists[j])) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3717 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3718 continuing = 0; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3719 break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3720 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3721 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3722 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3723 dead_wrong_type_argument (Qlistp, lists[j]); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3724 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3725 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3726 if (!continuing) break; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3727 funcalled = Ffuncall (nlists + 1, args); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3728 if (!maplp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3729 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3730 if (nconcp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3731 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3732 /* This order of calls means we check that each list is |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3733 well-formed once and once only. The last result does |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3734 not have to be a list. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3735 nconcing[1] = funcalled; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3736 nconcing[0] = bytecode_nconc2 (nconcing); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3737 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3738 else |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3739 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3740 /* Add to the end, avoiding the need to call nreverse |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3741 once we're done: */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3742 XSETCDR (accum, Fcons (funcalled, Qnil)); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3743 accum = XCDR (accum); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3744 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3745 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3746 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3747 if (++called_count % CIRCULAR_LIST_SUSPICION_LENGTH) continue; |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3748 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3749 for (j = 0; j < nlists; ++j) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3750 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3751 EXTERNAL_LIST_LOOP_1 (lists[j]) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3752 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3753 /* Just check the lists aren't circular, using the |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3754 EXTERNAL_LIST_LOOP_1 macro. */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3755 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3756 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3757 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3758 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3759 if (!maplp) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3760 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3761 result = XCDR (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3762 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3763 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3764 RETURN_UNGCPRO (result); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3765 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3766 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3767 DEFUN ("maplist", Fmaplist, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3768 Call FUNCTION on each sublist of LIST and LISTS. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3769 Like `mapcar', except applies to lists and their cdr's rather than to |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3770 the elements themselves." |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3771 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3772 arguments: (FUNCTION LIST &rest LISTS) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3773 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3774 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3775 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3776 return maplist (args[0], nargs - 1, args + 1, 0, 0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3777 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3778 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3779 DEFUN ("mapl", Fmapl, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3780 Like `maplist', but do not accumulate values returned by the function. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3781 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3782 arguments: (FUNCTION LIST &rest LISTS) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3783 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3784 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3785 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3786 return maplist (args[0], nargs - 1, args + 1, 1, 0); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3787 } |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3788 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3789 DEFUN ("mapcon", Fmapcon, 2, MANY, 0, /* |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3790 Like `maplist', but chains together the values returned by FUNCTION. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3791 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3792 FUNCTION must return a list (unless it happens to be the last |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3793 iteration); the results will be concatenated together using `nconc'. |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3794 |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3795 arguments: (FUNCTION LIST &rest LISTS) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3796 */ |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3797 (int nargs, Lisp_Object *args)) |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3798 { |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3799 return maplist (args[0], nargs - 1, args + 1, 0, 1); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3800 } |
428 | 3801 |
771 | 3802 /* Extra random functions */ |
442 | 3803 |
3804 DEFUN ("replace-list", Freplace_list, 2, 2, 0, /* | |
3805 Destructively replace the list OLD with NEW. | |
3806 This is like (copy-sequence NEW) except that it reuses the | |
3807 conses in OLD as much as possible. If OLD and NEW are the same | |
3808 length, no consing will take place. | |
3809 */ | |
3025 | 3810 (old, new_)) |
442 | 3811 { |
2367 | 3812 Lisp_Object oldtail = old, prevoldtail = Qnil; |
3813 | |
3025 | 3814 EXTERNAL_LIST_LOOP_2 (elt, new_) |
442 | 3815 { |
3816 if (!NILP (oldtail)) | |
3817 { | |
3818 CHECK_CONS (oldtail); | |
2367 | 3819 XCAR (oldtail) = elt; |
442 | 3820 } |
3821 else if (!NILP (prevoldtail)) | |
3822 { | |
2367 | 3823 XCDR (prevoldtail) = Fcons (elt, Qnil); |
442 | 3824 prevoldtail = XCDR (prevoldtail); |
3825 } | |
3826 else | |
2367 | 3827 old = oldtail = Fcons (elt, Qnil); |
442 | 3828 |
3829 if (!NILP (oldtail)) | |
3830 { | |
3831 prevoldtail = oldtail; | |
3832 oldtail = XCDR (oldtail); | |
3833 } | |
3834 } | |
3835 | |
3836 if (!NILP (prevoldtail)) | |
3837 XCDR (prevoldtail) = Qnil; | |
3838 else | |
3839 old = Qnil; | |
3840 | |
3841 return old; | |
3842 } | |
3843 | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
3844 |
771 | 3845 Lisp_Object |
2367 | 3846 add_suffix_to_symbol (Lisp_Object symbol, const Ascbyte *ascii_string) |
771 | 3847 { |
3848 return Fintern (concat2 (Fsymbol_name (symbol), | |
3849 build_string (ascii_string)), | |
3850 Qnil); | |
3851 } | |
3852 | |
3853 Lisp_Object | |
2367 | 3854 add_prefix_to_symbol (const Ascbyte *ascii_string, Lisp_Object symbol) |
771 | 3855 { |
3856 return Fintern (concat2 (build_string (ascii_string), | |
3857 Fsymbol_name (symbol)), | |
3858 Qnil); | |
3859 } | |
3860 | |
442 | 3861 |
428 | 3862 /* #### this function doesn't belong in this file! */ |
3863 | |
442 | 3864 #ifdef HAVE_GETLOADAVG |
3865 #ifdef HAVE_SYS_LOADAVG_H | |
3866 #include <sys/loadavg.h> | |
3867 #endif | |
3868 #else | |
3869 int getloadavg (double loadavg[], int nelem); /* Defined in getloadavg.c */ | |
3870 #endif | |
3871 | |
428 | 3872 DEFUN ("load-average", Fload_average, 0, 1, 0, /* |
3873 Return list of 1 minute, 5 minute and 15 minute load averages. | |
3874 Each of the three load averages is multiplied by 100, | |
3875 then converted to integer. | |
3876 | |
3877 When USE-FLOATS is non-nil, floats will be used instead of integers. | |
3878 These floats are not multiplied by 100. | |
3879 | |
3880 If the 5-minute or 15-minute load averages are not available, return a | |
3881 shortened list, containing only those averages which are available. | |
3882 | |
3883 On some systems, this won't work due to permissions on /dev/kmem, | |
3884 in which case you can't use this. | |
3885 */ | |
3886 (use_floats)) | |
3887 { | |
3888 double load_ave[3]; | |
3889 int loads = getloadavg (load_ave, countof (load_ave)); | |
3890 Lisp_Object ret = Qnil; | |
3891 | |
3892 if (loads == -2) | |
563 | 3893 signal_error (Qunimplemented, |
3894 "load-average not implemented for this operating system", | |
3895 Qunbound); | |
428 | 3896 else if (loads < 0) |
563 | 3897 invalid_operation ("Could not get load-average", lisp_strerror (errno)); |
428 | 3898 |
3899 while (loads-- > 0) | |
3900 { | |
3901 Lisp_Object load = (NILP (use_floats) ? | |
3902 make_int ((int) (100.0 * load_ave[loads])) | |
3903 : make_float (load_ave[loads])); | |
3904 ret = Fcons (load, ret); | |
3905 } | |
3906 return ret; | |
3907 } | |
3908 | |
3909 | |
3910 Lisp_Object Vfeatures; | |
3911 | |
3912 DEFUN ("featurep", Ffeaturep, 1, 1, 0, /* | |
3913 Return non-nil if feature FEXP is present in this Emacs. | |
3914 Use this to conditionalize execution of lisp code based on the | |
3915 presence or absence of emacs or environment extensions. | |
3916 FEXP can be a symbol, a number, or a list. | |
3917 If it is a symbol, that symbol is looked up in the `features' variable, | |
3918 and non-nil will be returned if found. | |
3919 If it is a number, the function will return non-nil if this Emacs | |
3920 has an equal or greater version number than FEXP. | |
3921 If it is a list whose car is the symbol `and', it will return | |
3922 non-nil if all the features in its cdr are non-nil. | |
3923 If it is a list whose car is the symbol `or', it will return non-nil | |
3924 if any of the features in its cdr are non-nil. | |
3925 If it is a list whose car is the symbol `not', it will return | |
3926 non-nil if the feature is not present. | |
3927 | |
3928 Examples: | |
3929 | |
3930 (featurep 'xemacs) | |
3931 => ; Non-nil on XEmacs. | |
3932 | |
3933 (featurep '(and xemacs gnus)) | |
3934 => ; Non-nil on XEmacs with Gnus loaded. | |
3935 | |
3936 (featurep '(or tty-frames (and emacs 19.30))) | |
3937 => ; Non-nil if this Emacs supports TTY frames. | |
3938 | |
3939 (featurep '(or (and xemacs 19.15) (and emacs 19.34))) | |
3940 => ; Non-nil on XEmacs 19.15 and later, or FSF Emacs 19.34 and later. | |
3941 | |
442 | 3942 (featurep '(and xemacs 21.02)) |
3943 => ; Non-nil on XEmacs 21.2 and later. | |
3944 | |
428 | 3945 NOTE: The advanced arguments of this function (anything other than a |
3946 symbol) are not yet supported by FSF Emacs. If you feel they are useful | |
3947 for supporting multiple Emacs variants, lobby Richard Stallman at | |
442 | 3948 <bug-gnu-emacs@gnu.org>. |
428 | 3949 */ |
3950 (fexp)) | |
3951 { | |
3952 #ifndef FEATUREP_SYNTAX | |
3953 CHECK_SYMBOL (fexp); | |
3954 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
3955 #else /* FEATUREP_SYNTAX */ | |
3956 static double featurep_emacs_version; | |
3957 | |
3958 /* Brute force translation from Erik Naggum's lisp function. */ | |
3959 if (SYMBOLP (fexp)) | |
3960 { | |
3961 /* Original definition */ | |
3962 return NILP (Fmemq (fexp, Vfeatures)) ? Qnil : Qt; | |
3963 } | |
3964 else if (INTP (fexp) || FLOATP (fexp)) | |
3965 { | |
3966 double d = extract_float (fexp); | |
3967 | |
3968 if (featurep_emacs_version == 0.0) | |
3969 { | |
3970 featurep_emacs_version = XINT (Vemacs_major_version) + | |
3971 (XINT (Vemacs_minor_version) / 100.0); | |
3972 } | |
3973 return featurep_emacs_version >= d ? Qt : Qnil; | |
3974 } | |
3975 else if (CONSP (fexp)) | |
3976 { | |
3977 Lisp_Object tem = XCAR (fexp); | |
3978 if (EQ (tem, Qnot)) | |
3979 { | |
3980 Lisp_Object negate; | |
3981 | |
3982 tem = XCDR (fexp); | |
3983 negate = Fcar (tem); | |
3984 if (!NILP (tem)) | |
3985 return NILP (call1 (Qfeaturep, negate)) ? Qt : Qnil; | |
3986 else | |
3987 return Fsignal (Qinvalid_read_syntax, list1 (tem)); | |
3988 } | |
3989 else if (EQ (tem, Qand)) | |
3990 { | |
3991 tem = XCDR (fexp); | |
3992 /* Use Fcar/Fcdr for error-checking. */ | |
3993 while (!NILP (tem) && !NILP (call1 (Qfeaturep, Fcar (tem)))) | |
3994 { | |
3995 tem = Fcdr (tem); | |
3996 } | |
3997 return NILP (tem) ? Qt : Qnil; | |
3998 } | |
3999 else if (EQ (tem, Qor)) | |
4000 { | |
4001 tem = XCDR (fexp); | |
4002 /* Use Fcar/Fcdr for error-checking. */ | |
4003 while (!NILP (tem) && NILP (call1 (Qfeaturep, Fcar (tem)))) | |
4004 { | |
4005 tem = Fcdr (tem); | |
4006 } | |
4007 return NILP (tem) ? Qnil : Qt; | |
4008 } | |
4009 else | |
4010 { | |
4011 return Fsignal (Qinvalid_read_syntax, list1 (XCDR (fexp))); | |
4012 } | |
4013 } | |
4014 else | |
4015 { | |
4016 return Fsignal (Qinvalid_read_syntax, list1 (fexp)); | |
4017 } | |
4018 } | |
4019 #endif /* FEATUREP_SYNTAX */ | |
4020 | |
4021 DEFUN ("provide", Fprovide, 1, 1, 0, /* | |
4022 Announce that FEATURE is a feature of the current Emacs. | |
4023 This function updates the value of the variable `features'. | |
4024 */ | |
4025 (feature)) | |
4026 { | |
4027 Lisp_Object tem; | |
4028 CHECK_SYMBOL (feature); | |
4029 if (!NILP (Vautoload_queue)) | |
4030 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); | |
4031 tem = Fmemq (feature, Vfeatures); | |
4032 if (NILP (tem)) | |
4033 Vfeatures = Fcons (feature, Vfeatures); | |
4034 LOADHIST_ATTACH (Fcons (Qprovide, feature)); | |
4035 return feature; | |
4036 } | |
4037 | |
1067 | 4038 DEFUN ("require", Frequire, 1, 3, 0, /* |
3842 | 4039 Ensure that FEATURE is present in the Lisp environment. |
4040 FEATURE is a symbol naming a collection of resources (functions, etc). | |
4041 Optional FILENAME is a library from which to load resources; it defaults to | |
4042 the print name of FEATURE. | |
4043 Optional NOERROR, if non-nil, causes require to return nil rather than signal | |
4044 `file-error' if loading the library fails. | |
4045 | |
4046 If feature FEATURE is present in `features', update `load-history' to reflect | |
4047 the require and return FEATURE. Otherwise, try to load it from a library. | |
4048 The normal messages at start and end of loading are suppressed. | |
4049 If the library is successfully loaded and it calls `(provide FEATURE)', add | |
4050 FEATURE to `features', update `load-history' and return FEATURE. | |
4051 If the load succeeds but FEATURE is not provided by the library, signal | |
4052 `invalid-state'. | |
4053 | |
4054 The byte-compiler treats top-level calls to `require' specially, by evaluating | |
4055 them at compile time (and then compiling them normally). Thus a library may | |
4056 request that definitions that should be inlined such as macros and defsubsts | |
4057 be loaded into its compilation environment. Achieving this in other contexts | |
4058 requires an explicit \(eval-and-compile ...\) block. | |
428 | 4059 */ |
1067 | 4060 (feature, filename, noerror)) |
428 | 4061 { |
4062 Lisp_Object tem; | |
4063 CHECK_SYMBOL (feature); | |
4064 tem = Fmemq (feature, Vfeatures); | |
4065 LOADHIST_ATTACH (Fcons (Qrequire, feature)); | |
4066 if (!NILP (tem)) | |
4067 return feature; | |
4068 else | |
4069 { | |
4070 int speccount = specpdl_depth (); | |
4071 | |
4072 /* Value saved here is to be restored into Vautoload_queue */ | |
4073 record_unwind_protect (un_autoload, Vautoload_queue); | |
4074 Vautoload_queue = Qt; | |
4075 | |
1067 | 4076 tem = call4 (Qload, NILP (filename) ? Fsymbol_name (feature) : filename, |
1261 | 4077 noerror, Qrequire, Qnil); |
1067 | 4078 /* If load failed entirely, return nil. */ |
4079 if (NILP (tem)) | |
4080 return unbind_to_1 (speccount, Qnil); | |
428 | 4081 |
4082 tem = Fmemq (feature, Vfeatures); | |
4083 if (NILP (tem)) | |
563 | 4084 invalid_state ("Required feature was not provided", feature); |
428 | 4085 |
4086 /* Once loading finishes, don't undo it. */ | |
4087 Vautoload_queue = Qt; | |
771 | 4088 return unbind_to_1 (speccount, feature); |
428 | 4089 } |
4090 } | |
4091 | |
4092 /* base64 encode/decode functions. | |
4093 | |
4094 Originally based on code from GNU recode. Ported to FSF Emacs by | |
4095 Lars Magne Ingebrigtsen and Karl Heuer. Ported to XEmacs and | |
4096 subsequently heavily hacked by Hrvoje Niksic. */ | |
4097 | |
4098 #define MIME_LINE_LENGTH 72 | |
4099 | |
4100 #define IS_ASCII(Character) \ | |
4101 ((Character) < 128) | |
4102 #define IS_BASE64(Character) \ | |
4103 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) | |
4104 | |
4105 /* Table of characters coding the 64 values. */ | |
4106 static char base64_value_to_char[64] = | |
4107 { | |
4108 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */ | |
4109 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */ | |
4110 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */ | |
4111 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */ | |
4112 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */ | |
4113 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */ | |
4114 '8', '9', '+', '/' /* 60-63 */ | |
4115 }; | |
4116 | |
4117 /* Table of base64 values for first 128 characters. */ | |
4118 static short base64_char_to_value[128] = | |
4119 { | |
4120 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */ | |
4121 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */ | |
4122 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */ | |
4123 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */ | |
4124 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */ | |
4125 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */ | |
4126 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */ | |
4127 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */ | |
4128 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */ | |
4129 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */ | |
4130 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */ | |
4131 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */ | |
4132 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */ | |
4133 }; | |
4134 | |
4135 /* The following diagram shows the logical steps by which three octets | |
4136 get transformed into four base64 characters. | |
4137 | |
4138 .--------. .--------. .--------. | |
4139 |aaaaaabb| |bbbbcccc| |ccdddddd| | |
4140 `--------' `--------' `--------' | |
4141 6 2 4 4 2 6 | |
4142 .--------+--------+--------+--------. | |
4143 |00aaaaaa|00bbbbbb|00cccccc|00dddddd| | |
4144 `--------+--------+--------+--------' | |
4145 | |
4146 .--------+--------+--------+--------. | |
4147 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD| | |
4148 `--------+--------+--------+--------' | |
4149 | |
4150 The octets are divided into 6 bit chunks, which are then encoded into | |
4151 base64 characters. */ | |
4152 | |
2268 | 4153 static DECLARE_DOESNT_RETURN (base64_conversion_error (const char *, |
4154 Lisp_Object)); | |
4155 | |
575 | 4156 static DOESNT_RETURN |
563 | 4157 base64_conversion_error (const char *reason, Lisp_Object frob) |
4158 { | |
4159 signal_error (Qbase64_conversion_error, reason, frob); | |
4160 } | |
4161 | |
4162 #define ADVANCE_INPUT(c, stream) \ | |
867 | 4163 ((ec = Lstream_get_ichar (stream)) == -1 ? 0 : \ |
563 | 4164 ((ec > 255) ? \ |
4165 (base64_conversion_error ("Non-ascii character in base64 input", \ | |
4166 make_char (ec)), 0) \ | |
867 | 4167 : (c = (Ibyte)ec), 1)) |
665 | 4168 |
4169 static Bytebpos | |
867 | 4170 base64_encode_1 (Lstream *istream, Ibyte *to, int line_break) |
428 | 4171 { |
4172 EMACS_INT counter = 0; | |
867 | 4173 Ibyte *e = to; |
4174 Ichar ec; | |
428 | 4175 unsigned int value; |
4176 | |
4177 while (1) | |
4178 { | |
1204 | 4179 Ibyte c = 0; |
428 | 4180 if (!ADVANCE_INPUT (c, istream)) |
4181 break; | |
4182 | |
4183 /* Wrap line every 76 characters. */ | |
4184 if (line_break) | |
4185 { | |
4186 if (counter < MIME_LINE_LENGTH / 4) | |
4187 counter++; | |
4188 else | |
4189 { | |
4190 *e++ = '\n'; | |
4191 counter = 1; | |
4192 } | |
4193 } | |
4194 | |
4195 /* Process first byte of a triplet. */ | |
4196 *e++ = base64_value_to_char[0x3f & c >> 2]; | |
4197 value = (0x03 & c) << 4; | |
4198 | |
4199 /* Process second byte of a triplet. */ | |
4200 if (!ADVANCE_INPUT (c, istream)) | |
4201 { | |
4202 *e++ = base64_value_to_char[value]; | |
4203 *e++ = '='; | |
4204 *e++ = '='; | |
4205 break; | |
4206 } | |
4207 | |
4208 *e++ = base64_value_to_char[value | (0x0f & c >> 4)]; | |
4209 value = (0x0f & c) << 2; | |
4210 | |
4211 /* Process third byte of a triplet. */ | |
4212 if (!ADVANCE_INPUT (c, istream)) | |
4213 { | |
4214 *e++ = base64_value_to_char[value]; | |
4215 *e++ = '='; | |
4216 break; | |
4217 } | |
4218 | |
4219 *e++ = base64_value_to_char[value | (0x03 & c >> 6)]; | |
4220 *e++ = base64_value_to_char[0x3f & c]; | |
4221 } | |
4222 | |
4223 return e - to; | |
4224 } | |
4225 #undef ADVANCE_INPUT | |
4226 | |
4227 /* Get next character from the stream, except that non-base64 | |
4228 characters are ignored. This is in accordance with rfc2045. EC | |
867 | 4229 should be an Ichar, so that it can hold -1 as the value for EOF. */ |
428 | 4230 #define ADVANCE_INPUT_IGNORE_NONBASE64(ec, stream, streampos) do { \ |
867 | 4231 ec = Lstream_get_ichar (stream); \ |
428 | 4232 ++streampos; \ |
4233 /* IS_BASE64 may not be called with negative arguments so check for \ | |
4234 EOF first. */ \ | |
4235 if (ec < 0 || IS_BASE64 (ec) || ec == '=') \ | |
4236 break; \ | |
4237 } while (1) | |
4238 | |
4239 #define STORE_BYTE(pos, val, ccnt) do { \ | |
867 | 4240 pos += set_itext_ichar (pos, (Ichar)((unsigned char)(val))); \ |
428 | 4241 ++ccnt; \ |
4242 } while (0) | |
4243 | |
665 | 4244 static Bytebpos |
867 | 4245 base64_decode_1 (Lstream *istream, Ibyte *to, Charcount *ccptr) |
428 | 4246 { |
4247 Charcount ccnt = 0; | |
867 | 4248 Ibyte *e = to; |
428 | 4249 EMACS_INT streampos = 0; |
4250 | |
4251 while (1) | |
4252 { | |
867 | 4253 Ichar ec; |
428 | 4254 unsigned long value; |
4255 | |
4256 /* Process first byte of a quadruplet. */ | |
4257 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4258 if (ec < 0) | |
4259 break; | |
4260 if (ec == '=') | |
563 | 4261 base64_conversion_error ("Illegal `=' character while decoding base64", |
4262 make_int (streampos)); | |
428 | 4263 value = base64_char_to_value[ec] << 18; |
4264 | |
4265 /* Process second byte of a quadruplet. */ | |
4266 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4267 if (ec < 0) | |
563 | 4268 base64_conversion_error ("Premature EOF while decoding base64", |
4269 Qunbound); | |
428 | 4270 if (ec == '=') |
563 | 4271 base64_conversion_error ("Illegal `=' character while decoding base64", |
4272 make_int (streampos)); | |
428 | 4273 value |= base64_char_to_value[ec] << 12; |
4274 STORE_BYTE (e, value >> 16, ccnt); | |
4275 | |
4276 /* Process third byte of a quadruplet. */ | |
4277 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4278 if (ec < 0) | |
563 | 4279 base64_conversion_error ("Premature EOF while decoding base64", |
4280 Qunbound); | |
428 | 4281 |
4282 if (ec == '=') | |
4283 { | |
4284 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4285 if (ec < 0) | |
563 | 4286 base64_conversion_error ("Premature EOF while decoding base64", |
4287 Qunbound); | |
428 | 4288 if (ec != '=') |
563 | 4289 base64_conversion_error |
4290 ("Padding `=' expected but not found while decoding base64", | |
4291 make_int (streampos)); | |
428 | 4292 continue; |
4293 } | |
4294 | |
4295 value |= base64_char_to_value[ec] << 6; | |
4296 STORE_BYTE (e, 0xff & value >> 8, ccnt); | |
4297 | |
4298 /* Process fourth byte of a quadruplet. */ | |
4299 ADVANCE_INPUT_IGNORE_NONBASE64 (ec, istream, streampos); | |
4300 if (ec < 0) | |
563 | 4301 base64_conversion_error ("Premature EOF while decoding base64", |
4302 Qunbound); | |
428 | 4303 if (ec == '=') |
4304 continue; | |
4305 | |
4306 value |= base64_char_to_value[ec]; | |
4307 STORE_BYTE (e, 0xff & value, ccnt); | |
4308 } | |
4309 | |
4310 *ccptr = ccnt; | |
4311 return e - to; | |
4312 } | |
4313 #undef ADVANCE_INPUT | |
4314 #undef ADVANCE_INPUT_IGNORE_NONBASE64 | |
4315 #undef STORE_BYTE | |
4316 | |
4317 DEFUN ("base64-encode-region", Fbase64_encode_region, 2, 3, "r", /* | |
444 | 4318 Base64-encode the region between START and END. |
428 | 4319 Return the length of the encoded text. |
4320 Optional third argument NO-LINE-BREAK means do not break long lines | |
4321 into shorter lines. | |
4322 */ | |
444 | 4323 (start, end, no_line_break)) |
428 | 4324 { |
867 | 4325 Ibyte *encoded; |
665 | 4326 Bytebpos encoded_length; |
428 | 4327 Charcount allength, length; |
4328 struct buffer *buf = current_buffer; | |
665 | 4329 Charbpos begv, zv, old_pt = BUF_PT (buf); |
428 | 4330 Lisp_Object input; |
851 | 4331 int speccount = specpdl_depth (); |
428 | 4332 |
444 | 4333 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 4334 barf_if_buffer_read_only (buf, begv, zv); |
4335 | |
4336 /* We need to allocate enough room for encoding the text. | |
4337 We need 33 1/3% more space, plus a newline every 76 | |
4338 characters, and then we round up. */ | |
4339 length = zv - begv; | |
4340 allength = length + length/3 + 1; | |
4341 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
4342 | |
4343 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
867 | 4344 /* We needn't multiply allength with MAX_ICHAR_LEN because all the |
428 | 4345 base64 characters will be single-byte. */ |
867 | 4346 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 4347 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
4348 NILP (no_line_break)); | |
4349 if (encoded_length > allength) | |
2500 | 4350 ABORT (); |
428 | 4351 Lstream_delete (XLSTREAM (input)); |
4352 | |
4353 /* Now we have encoded the region, so we insert the new contents | |
4354 and delete the old. (Insert first in order to preserve markers.) */ | |
4355 buffer_insert_raw_string_1 (buf, begv, encoded, encoded_length, 0); | |
851 | 4356 unbind_to (speccount); |
428 | 4357 buffer_delete_range (buf, begv + encoded_length, zv + encoded_length, 0); |
4358 | |
4359 /* Simulate FSF Emacs implementation of this function: if point was | |
4360 in the region, place it at the beginning. */ | |
4361 if (old_pt >= begv && old_pt < zv) | |
4362 BUF_SET_PT (buf, begv); | |
4363 | |
4364 /* We return the length of the encoded text. */ | |
4365 return make_int (encoded_length); | |
4366 } | |
4367 | |
4368 DEFUN ("base64-encode-string", Fbase64_encode_string, 1, 2, 0, /* | |
4369 Base64 encode STRING and return the result. | |
444 | 4370 Optional argument NO-LINE-BREAK means do not break long lines |
4371 into shorter lines. | |
428 | 4372 */ |
4373 (string, no_line_break)) | |
4374 { | |
4375 Charcount allength, length; | |
665 | 4376 Bytebpos encoded_length; |
867 | 4377 Ibyte *encoded; |
428 | 4378 Lisp_Object input, result; |
4379 int speccount = specpdl_depth(); | |
4380 | |
4381 CHECK_STRING (string); | |
4382 | |
826 | 4383 length = string_char_length (string); |
428 | 4384 allength = length + length/3 + 1; |
4385 allength += allength / MIME_LINE_LENGTH + 1 + 6; | |
4386 | |
4387 input = make_lisp_string_input_stream (string, 0, -1); | |
867 | 4388 encoded = (Ibyte *) MALLOC_OR_ALLOCA (allength); |
428 | 4389 encoded_length = base64_encode_1 (XLSTREAM (input), encoded, |
4390 NILP (no_line_break)); | |
4391 if (encoded_length > allength) | |
2500 | 4392 ABORT (); |
428 | 4393 Lstream_delete (XLSTREAM (input)); |
4394 result = make_string (encoded, encoded_length); | |
851 | 4395 unbind_to (speccount); |
428 | 4396 return result; |
4397 } | |
4398 | |
4399 DEFUN ("base64-decode-region", Fbase64_decode_region, 2, 2, "r", /* | |
444 | 4400 Base64-decode the region between START and END. |
428 | 4401 Return the length of the decoded text. |
4402 If the region can't be decoded, return nil and don't modify the buffer. | |
4403 Characters out of the base64 alphabet are ignored. | |
4404 */ | |
444 | 4405 (start, end)) |
428 | 4406 { |
4407 struct buffer *buf = current_buffer; | |
665 | 4408 Charbpos begv, zv, old_pt = BUF_PT (buf); |
867 | 4409 Ibyte *decoded; |
665 | 4410 Bytebpos decoded_length; |
428 | 4411 Charcount length, cc_decoded_length; |
4412 Lisp_Object input; | |
4413 int speccount = specpdl_depth(); | |
4414 | |
444 | 4415 get_buffer_range_char (buf, start, end, &begv, &zv, 0); |
428 | 4416 barf_if_buffer_read_only (buf, begv, zv); |
4417 | |
4418 length = zv - begv; | |
4419 | |
4420 input = make_lisp_buffer_input_stream (buf, begv, zv, 0); | |
4421 /* We need to allocate enough room for decoding the text. */ | |
867 | 4422 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 4423 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, &cc_decoded_length); |
867 | 4424 if (decoded_length > length * MAX_ICHAR_LEN) |
2500 | 4425 ABORT (); |
428 | 4426 Lstream_delete (XLSTREAM (input)); |
4427 | |
4428 /* Now we have decoded the region, so we insert the new contents | |
4429 and delete the old. (Insert first in order to preserve markers.) */ | |
4430 BUF_SET_PT (buf, begv); | |
4431 buffer_insert_raw_string_1 (buf, begv, decoded, decoded_length, 0); | |
851 | 4432 unbind_to (speccount); |
428 | 4433 buffer_delete_range (buf, begv + cc_decoded_length, |
4434 zv + cc_decoded_length, 0); | |
4435 | |
4436 /* Simulate FSF Emacs implementation of this function: if point was | |
4437 in the region, place it at the beginning. */ | |
4438 if (old_pt >= begv && old_pt < zv) | |
4439 BUF_SET_PT (buf, begv); | |
4440 | |
4441 return make_int (cc_decoded_length); | |
4442 } | |
4443 | |
4444 DEFUN ("base64-decode-string", Fbase64_decode_string, 1, 1, 0, /* | |
4445 Base64-decode STRING and return the result. | |
4446 Characters out of the base64 alphabet are ignored. | |
4447 */ | |
4448 (string)) | |
4449 { | |
867 | 4450 Ibyte *decoded; |
665 | 4451 Bytebpos decoded_length; |
428 | 4452 Charcount length, cc_decoded_length; |
4453 Lisp_Object input, result; | |
4454 int speccount = specpdl_depth(); | |
4455 | |
4456 CHECK_STRING (string); | |
4457 | |
826 | 4458 length = string_char_length (string); |
428 | 4459 /* We need to allocate enough room for decoding the text. */ |
867 | 4460 decoded = (Ibyte *) MALLOC_OR_ALLOCA (length * MAX_ICHAR_LEN); |
428 | 4461 |
4462 input = make_lisp_string_input_stream (string, 0, -1); | |
4463 decoded_length = base64_decode_1 (XLSTREAM (input), decoded, | |
4464 &cc_decoded_length); | |
867 | 4465 if (decoded_length > length * MAX_ICHAR_LEN) |
2500 | 4466 ABORT (); |
428 | 4467 Lstream_delete (XLSTREAM (input)); |
4468 | |
4469 result = make_string (decoded, decoded_length); | |
851 | 4470 unbind_to (speccount); |
428 | 4471 return result; |
4472 } | |
4473 | |
4474 Lisp_Object Qyes_or_no_p; | |
4475 | |
4476 void | |
4477 syms_of_fns (void) | |
4478 { | |
442 | 4479 INIT_LRECORD_IMPLEMENTATION (bit_vector); |
4480 | |
563 | 4481 DEFSYMBOL (Qstring_lessp); |
4482 DEFSYMBOL (Qidentity); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4483 DEFSYMBOL (Qvector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4484 DEFSYMBOL (Qarray); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4485 DEFSYMBOL (Qstring); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4486 DEFSYMBOL (Qlist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4487 DEFSYMBOL (Qbit_vector); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4488 |
563 | 4489 DEFSYMBOL (Qyes_or_no_p); |
4490 | |
4491 DEFERROR_STANDARD (Qbase64_conversion_error, Qconversion_error); | |
428 | 4492 |
4493 DEFSUBR (Fidentity); | |
4494 DEFSUBR (Frandom); | |
4495 DEFSUBR (Flength); | |
4496 DEFSUBR (Fsafe_length); | |
4497 DEFSUBR (Fstring_equal); | |
801 | 4498 DEFSUBR (Fcompare_strings); |
428 | 4499 DEFSUBR (Fstring_lessp); |
4500 DEFSUBR (Fstring_modified_tick); | |
4501 DEFSUBR (Fappend); | |
4502 DEFSUBR (Fconcat); | |
4503 DEFSUBR (Fvconcat); | |
4504 DEFSUBR (Fbvconcat); | |
4505 DEFSUBR (Fcopy_list); | |
4506 DEFSUBR (Fcopy_sequence); | |
4507 DEFSUBR (Fcopy_alist); | |
4508 DEFSUBR (Fcopy_tree); | |
4509 DEFSUBR (Fsubstring); | |
4510 DEFSUBR (Fsubseq); | |
4511 DEFSUBR (Fnthcdr); | |
4512 DEFSUBR (Fnth); | |
4513 DEFSUBR (Felt); | |
4514 DEFSUBR (Flast); | |
4515 DEFSUBR (Fbutlast); | |
4516 DEFSUBR (Fnbutlast); | |
4517 DEFSUBR (Fmember); | |
4518 DEFSUBR (Fold_member); | |
4519 DEFSUBR (Fmemq); | |
4520 DEFSUBR (Fold_memq); | |
4521 DEFSUBR (Fassoc); | |
4522 DEFSUBR (Fold_assoc); | |
4523 DEFSUBR (Fassq); | |
4524 DEFSUBR (Fold_assq); | |
4525 DEFSUBR (Frassoc); | |
4526 DEFSUBR (Fold_rassoc); | |
4527 DEFSUBR (Frassq); | |
4528 DEFSUBR (Fold_rassq); | |
4529 DEFSUBR (Fdelete); | |
4530 DEFSUBR (Fold_delete); | |
4531 DEFSUBR (Fdelq); | |
4532 DEFSUBR (Fold_delq); | |
4533 DEFSUBR (Fremassoc); | |
4534 DEFSUBR (Fremassq); | |
4535 DEFSUBR (Fremrassoc); | |
4536 DEFSUBR (Fremrassq); | |
4537 DEFSUBR (Fnreverse); | |
4538 DEFSUBR (Freverse); | |
4539 DEFSUBR (Fsort); | |
4540 DEFSUBR (Fplists_eq); | |
4541 DEFSUBR (Fplists_equal); | |
4542 DEFSUBR (Flax_plists_eq); | |
4543 DEFSUBR (Flax_plists_equal); | |
4544 DEFSUBR (Fplist_get); | |
4545 DEFSUBR (Fplist_put); | |
4546 DEFSUBR (Fplist_remprop); | |
4547 DEFSUBR (Fplist_member); | |
4548 DEFSUBR (Fcheck_valid_plist); | |
4549 DEFSUBR (Fvalid_plist_p); | |
4550 DEFSUBR (Fcanonicalize_plist); | |
4551 DEFSUBR (Flax_plist_get); | |
4552 DEFSUBR (Flax_plist_put); | |
4553 DEFSUBR (Flax_plist_remprop); | |
4554 DEFSUBR (Flax_plist_member); | |
4555 DEFSUBR (Fcanonicalize_lax_plist); | |
4556 DEFSUBR (Fdestructive_alist_to_plist); | |
4557 DEFSUBR (Fget); | |
4558 DEFSUBR (Fput); | |
4559 DEFSUBR (Fremprop); | |
4560 DEFSUBR (Fobject_plist); | |
4561 DEFSUBR (Fequal); | |
4562 DEFSUBR (Fold_equal); | |
4563 DEFSUBR (Ffillarray); | |
4564 DEFSUBR (Fnconc); | |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4565 DEFSUBR (FmapcarX); |
428 | 4566 DEFSUBR (Fmapvector); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4567 DEFSUBR (Fmapcan); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4568 DEFSUBR (Fmapc); |
428 | 4569 DEFSUBR (Fmapconcat); |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4570 DEFSUBR (Fmap); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4571 DEFSUBR (Fmap_into); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4572 Ffset (intern ("mapc-internal"), Fsymbol_function (intern ("mapc"))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4573 Ffset (intern ("mapcar"), Fsymbol_function (intern ("mapcar*"))); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4574 DEFSUBR (Fmaplist); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4575 DEFSUBR (Fmapl); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4576 DEFSUBR (Fmapcon); |
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4797
diff
changeset
|
4577 |
442 | 4578 DEFSUBR (Freplace_list); |
428 | 4579 DEFSUBR (Fload_average); |
4580 DEFSUBR (Ffeaturep); | |
4581 DEFSUBR (Frequire); | |
4582 DEFSUBR (Fprovide); | |
4583 DEFSUBR (Fbase64_encode_region); | |
4584 DEFSUBR (Fbase64_encode_string); | |
4585 DEFSUBR (Fbase64_decode_region); | |
4586 DEFSUBR (Fbase64_decode_string); | |
771 | 4587 |
4588 DEFSUBR (Fsplit_string_by_char); | |
4589 DEFSUBR (Fsplit_path); /* #### */ | |
4590 } | |
4591 | |
4592 void | |
4593 vars_of_fns (void) | |
4594 { | |
4595 DEFVAR_LISP ("path-separator", &Vpath_separator /* | |
4596 The directory separator in search paths, as a string. | |
4597 */ ); | |
4598 { | |
4599 char c = SEPCHAR; | |
867 | 4600 Vpath_separator = make_string ((Ibyte *) &c, 1); |
771 | 4601 } |
428 | 4602 } |
4603 | |
4604 void | |
4605 init_provide_once (void) | |
4606 { | |
4607 DEFVAR_LISP ("features", &Vfeatures /* | |
4608 A list of symbols which are the features of the executing emacs. | |
4609 Used by `featurep' and `require', and altered by `provide'. | |
4610 */ ); | |
4611 Vfeatures = Qnil; | |
4612 | |
4613 Fprovide (intern ("base64")); | |
4614 } |