comparison src/fns.c @ 5473:ac37a5f7e5be

Merge with trunk.
author Mats Lidell <matsl@xemacs.org>
date Thu, 17 Mar 2011 23:42:59 +0100
parents e79980ee5efe d967d96ca043
children 248176c74e6b
comparison
equal deleted inserted replaced
5472:e79980ee5efe 5473:ac37a5f7e5be
68 Lisp_Object Vpath_separator; 68 Lisp_Object Vpath_separator;
69 69
70 extern Fixnum max_lisp_eval_depth; 70 extern Fixnum max_lisp_eval_depth;
71 extern int lisp_eval_depth; 71 extern int lisp_eval_depth;
72 72
73 static int internal_old_equal (Lisp_Object, Lisp_Object, int);
74 Lisp_Object safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth); 73 Lisp_Object safe_copy_tree (Lisp_Object arg, Lisp_Object vecp, int depth);
75 74
76 static DOESNT_RETURN 75 static DOESNT_RETURN
77 mapping_interaction_error (Lisp_Object func, Lisp_Object object) 76 mapping_interaction_error (Lisp_Object func, Lisp_Object object)
78 { 77 {
2091 { 2090 {
2092 Charcount ccstart, ccend; 2091 Charcount ccstart, ccend;
2093 Bytecount bstart, blen; 2092 Bytecount bstart, blen;
2094 Lisp_Object val; 2093 Lisp_Object val;
2095 2094
2095 CHECK_STRING (string);
2096 get_string_range_char (string, start, end, &ccstart, &ccend, 2096 get_string_range_char (string, start, end, &ccstart, &ccend,
2097 GB_HISTORICAL_STRING_BEHAVIOR); 2097 GB_HISTORICAL_STRING_BEHAVIOR);
2098 bstart = string_index_char_to_byte (string, ccstart); 2098 bstart = string_index_char_to_byte (string, ccstart);
2099 blen = string_offset_char_to_byte_len (string, bstart, ccend - ccstart); 2099 blen = string_offset_char_to_byte_len (string, bstart, ccend - ccstart);
2100 val = make_string (XSTRING_DATA (string) + bstart, blen); 2100 val = make_string (XSTRING_DATA (string) + bstart, blen);
2576 return tail; 2576 return tail;
2577 } 2577 }
2578 return Qnil; 2578 return Qnil;
2579 } 2579 }
2580 2580
2581 DEFUN ("old-member", Fold_member, 2, 2, 0, /*
2582 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'.
2583 The value is actually the tail of LIST whose car is ELT.
2584 This function is provided only for byte-code compatibility with v19.
2585 Do not use it.
2586 */
2587 (elt, list))
2588 {
2589 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
2590 {
2591 if (internal_old_equal (elt, list_elt, 0))
2592 return tail;
2593 }
2594 return Qnil;
2595 }
2596
2597 DEFUN ("memq", Fmemq, 2, 2, 0, /* 2581 DEFUN ("memq", Fmemq, 2, 2, 0, /*
2598 Return non-nil if ELT is an element of LIST. Comparison done with `eq'. 2582 Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
2599 The value is actually the tail of LIST whose car is ELT. 2583 The value is actually the tail of LIST whose car is ELT.
2600 */ 2584 */
2601 (elt, list)) 2585 (elt, list))
2602 { 2586 {
2603 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail) 2587 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
2604 { 2588 {
2605 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt)) 2589 if (EQ_WITH_EBOLA_NOTICE (elt, list_elt))
2606 return tail;
2607 }
2608 return Qnil;
2609 }
2610
2611 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /*
2612 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'.
2613 The value is actually the tail of LIST whose car is ELT.
2614 This function is provided only for byte-code compatibility with v19.
2615 Do not use it.
2616 */
2617 (elt, list))
2618 {
2619 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
2620 {
2621 if (HACKEQ_UNSAFE (elt, list_elt))
2622 return tail; 2590 return tail;
2623 } 2591 }
2624 return Qnil; 2592 return Qnil;
2625 } 2593 }
2626 2594
2817 return elt; 2785 return elt;
2818 } 2786 }
2819 return Qnil; 2787 return Qnil;
2820 } 2788 }
2821 2789
2822 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /*
2823 Return non-nil if KEY is `old-equal' to the car of an element of ALIST.
2824 The value is actually the element of ALIST whose car equals KEY.
2825 */
2826 (key, alist))
2827 {
2828 /* This function can GC. */
2829 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
2830 {
2831 if (internal_old_equal (key, elt_car, 0))
2832 return elt;
2833 }
2834 return Qnil;
2835 }
2836
2837 Lisp_Object 2790 Lisp_Object
2838 assoc_no_quit (Lisp_Object key, Lisp_Object alist) 2791 assoc_no_quit (Lisp_Object key, Lisp_Object alist)
2839 { 2792 {
2840 int speccount = specpdl_depth (); 2793 int speccount = specpdl_depth ();
2841 specbind (Qinhibit_quit, Qt); 2794 specbind (Qinhibit_quit, Qt);
2850 (key, alist)) 2803 (key, alist))
2851 { 2804 {
2852 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) 2805 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
2853 { 2806 {
2854 if (EQ_WITH_EBOLA_NOTICE (key, elt_car)) 2807 if (EQ_WITH_EBOLA_NOTICE (key, elt_car))
2855 return elt;
2856 }
2857 return Qnil;
2858 }
2859
2860 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /*
2861 Return non-nil if KEY is `old-eq' to the car of an element of ALIST.
2862 The value is actually the element of ALIST whose car is KEY.
2863 Elements of ALIST that are not conses are ignored.
2864 This function is provided only for byte-code compatibility with v19.
2865 Do not use it.
2866 */
2867 (key, alist))
2868 {
2869 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
2870 {
2871 if (HACKEQ_UNSAFE (key, elt_car))
2872 return elt; 2808 return elt;
2873 } 2809 }
2874 return Qnil; 2810 return Qnil;
2875 } 2811 }
2876 2812
2950 (value, alist)) 2886 (value, alist))
2951 { 2887 {
2952 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist) 2888 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
2953 { 2889 {
2954 if (internal_equal (value, elt_cdr, 0)) 2890 if (internal_equal (value, elt_cdr, 0))
2955 return elt;
2956 }
2957 return Qnil;
2958 }
2959
2960 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /*
2961 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST.
2962 The value is actually the element of ALIST whose cdr equals VALUE.
2963 */
2964 (value, alist))
2965 {
2966 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
2967 {
2968 if (internal_old_equal (value, elt_cdr, 0))
2969 return elt; 2891 return elt;
2970 } 2892 }
2971 return Qnil; 2893 return Qnil;
2972 } 2894 }
2973 2895
3273 test, key, start, end, from_end, default_, Qposition); 3195 test, key, start, end, from_end, default_, Qposition);
3274 3196
3275 return object; 3197 return object;
3276 } 3198 }
3277 3199
3278 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /*
3279 Delete by side effect any occurrences of ELT as a member of LIST.
3280 The modified LIST is returned. Comparison is done with `old-equal'.
3281 If the first member of LIST is ELT, there is no way to remove it by side
3282 effect; therefore, write `(setq foo (old-delete element foo))' to be sure
3283 of changing the value of `foo'.
3284 */
3285 (elt, list))
3286 {
3287 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
3288 (internal_old_equal (elt, list_elt, 0)));
3289 return list;
3290 }
3291
3292 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /*
3293 Delete by side effect any occurrences of ELT as a member of LIST.
3294 The modified LIST is returned. Comparison is done with `old-eq'.
3295 If the first member of LIST is ELT, there is no way to remove it by side
3296 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of
3297 changing the value of `foo'.
3298 */
3299 (elt, list))
3300 {
3301 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
3302 (HACKEQ_UNSAFE (elt, list_elt)));
3303 return list;
3304 }
3305
3306 /* Like Fdelq, but caller must ensure that LIST is properly 3200 /* Like Fdelq, but caller must ensure that LIST is properly
3307 nil-terminated and ebola-free. */ 3201 nil-terminated and ebola-free. */
3308 3202
3309 Lisp_Object 3203 Lisp_Object
3310 delq_no_quit (Lisp_Object elt, Lisp_Object list) 3204 delq_no_quit (Lisp_Object elt, Lisp_Object list)
6532 return internal_equalp (obj1, obj2, depth); 6426 return internal_equalp (obj1, obj2, depth);
6533 else 6427 else
6534 return internal_equal (obj1, obj2, depth); 6428 return internal_equal (obj1, obj2, depth);
6535 } 6429 }
6536 6430
6431 DEFUN ("equal", Fequal, 2, 2, 0, /*
6432 Return t if two Lisp objects have similar structure and contents.
6433 They must have the same data type.
6434 Conses are compared by comparing the cars and the cdrs.
6435 Vectors and strings are compared element by element.
6436 Numbers are compared by value. Symbols must match exactly.
6437 */
6438 (object1, object2))
6439 {
6440 return internal_equal (object1, object2, 0) ? Qt : Qnil;
6441 }
6442
6443 DEFUN ("equalp", Fequalp, 2, 2, 0, /*
6444 Return t if two Lisp objects have similar structure and contents.
6445
6446 This is like `equal', except that it accepts numerically equal
6447 numbers of different types (float, integer, bignum, bigfloat), and also
6448 compares strings and characters case-insensitively.
6449
6450 Type objects that are arrays (that is, strings, bit-vectors, and vectors)
6451 of the same length and with contents that are `equalp' are themselves
6452 `equalp', regardless of whether the two objects have the same type.
6453
6454 Other objects whose primary purpose is as containers of other objects are
6455 `equalp' if they would otherwise be equal (same length, type, etc.) and
6456 their contents are `equalp'. This goes for conses, weak lists,
6457 weak boxes, ephemerons, specifiers, hash tables, char tables and range
6458 tables. However, objects that happen to contain other objects but are not
6459 primarily designed for this purpose (e.g. compiled functions, events or
6460 display-related objects such as glyphs, faces or extents) are currently
6461 compared using `equalp' the same way as using `equal'.
6462
6463 More specifically, two hash tables are `equalp' if they have the same test
6464 (see `hash-table-test'), the same number of entries, and the same value for
6465 `hash-table-weakness', and if, for each entry in one hash table, its key is
6466 equivalent to a key in the other hash table using the hash table test, and
6467 its value is `equalp' to the other hash table's value for that key.
6468 */
6469 (object1, object2))
6470 {
6471 return internal_equalp (object1, object2, 0) ? Qt : Qnil;
6472 }
6473
6474 #ifdef SUPPORT_CONFOUNDING_FUNCTIONS
6475
6537 /* Note that we may be calling sub-objects that will use 6476 /* Note that we may be calling sub-objects that will use
6538 internal_equal() (instead of internal_old_equal()). Oh well. 6477 internal_equal() (instead of internal_old_equal()). Oh well.
6539 We will get an Ebola note if there's any possibility of confusion, 6478 We will get an Ebola note if there's any possibility of confusion,
6540 but that seems unlikely. */ 6479 but that seems unlikely. */
6541 6480
6552 return 0; 6491 return 0;
6553 6492
6554 return internal_equal (obj1, obj2, depth); 6493 return internal_equal (obj1, obj2, depth);
6555 } 6494 }
6556 6495
6557 DEFUN ("equal", Fequal, 2, 2, 0, /* 6496 DEFUN ("old-member", Fold_member, 2, 2, 0, /*
6558 Return t if two Lisp objects have similar structure and contents. 6497 Return non-nil if ELT is an element of LIST. Comparison done with `old-equal'.
6559 They must have the same data type. 6498 The value is actually the tail of LIST whose car is ELT.
6560 Conses are compared by comparing the cars and the cdrs. 6499 This function is provided only for byte-code compatibility with v19.
6561 Vectors and strings are compared element by element. 6500 Do not use it.
6562 Numbers are compared by value. Symbols must match exactly. 6501 */
6563 */ 6502 (elt, list))
6564 (object1, object2)) 6503 {
6565 { 6504 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
6566 return internal_equal (object1, object2, 0) ? Qt : Qnil; 6505 {
6567 } 6506 if (internal_old_equal (elt, list_elt, 0))
6568 6507 return tail;
6569 DEFUN ("equalp", Fequalp, 2, 2, 0, /* 6508 }
6570 Return t if two Lisp objects have similar structure and contents. 6509 return Qnil;
6571 6510 }
6572 This is like `equal', except that it accepts numerically equal 6511
6573 numbers of different types (float, integer, bignum, bigfloat), and also 6512 DEFUN ("old-memq", Fold_memq, 2, 2, 0, /*
6574 compares strings and characters case-insensitively. 6513 Return non-nil if ELT is an element of LIST. Comparison done with `old-eq'.
6575 6514 The value is actually the tail of LIST whose car is ELT.
6576 Type objects that are arrays (that is, strings, bit-vectors, and vectors) 6515 This function is provided only for byte-code compatibility with v19.
6577 of the same length and with contents that are `equalp' are themselves 6516 Do not use it.
6578 `equalp', regardless of whether the two objects have the same type. 6517 */
6579 6518 (elt, list))
6580 Other objects whose primary purpose is as containers of other objects are 6519 {
6581 `equalp' if they would otherwise be equal (same length, type, etc.) and 6520 EXTERNAL_LIST_LOOP_3 (list_elt, list, tail)
6582 their contents are `equalp'. This goes for conses, weak lists, 6521 {
6583 weak boxes, ephemerons, specifiers, hash tables, char tables and range 6522 if (HACKEQ_UNSAFE (elt, list_elt))
6584 tables. However, objects that happen to contain other objects but are not 6523 return tail;
6585 primarily designed for this purpose (e.g. compiled functions, events or 6524 }
6586 display-related objects such as glyphs, faces or extents) are currently 6525 return Qnil;
6587 compared using `equalp' the same way as using `equal'. 6526 }
6588 6527
6589 More specifically, two hash tables are `equalp' if they have the same test 6528 DEFUN ("old-assoc", Fold_assoc, 2, 2, 0, /*
6590 (see `hash-table-test'), the same number of entries, and the same value for 6529 Return non-nil if KEY is `old-equal' to the car of an element of ALIST.
6591 `hash-table-weakness', and if, for each entry in one hash table, its key is 6530 The value is actually the element of ALIST whose car equals KEY.
6592 equivalent to a key in the other hash table using the hash table test, and 6531 */
6593 its value is `equalp' to the other hash table's value for that key. 6532 (key, alist))
6594 */ 6533 {
6595 (object1, object2)) 6534 /* This function can GC. */
6596 { 6535 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
6597 return internal_equalp (object1, object2, 0) ? Qt : Qnil; 6536 {
6537 if (internal_old_equal (key, elt_car, 0))
6538 return elt;
6539 }
6540 return Qnil;
6541 }
6542
6543 DEFUN ("old-assq", Fold_assq, 2, 2, 0, /*
6544 Return non-nil if KEY is `old-eq' to the car of an element of ALIST.
6545 The value is actually the element of ALIST whose car is KEY.
6546 Elements of ALIST that are not conses are ignored.
6547 This function is provided only for byte-code compatibility with v19.
6548 Do not use it.
6549 */
6550 (key, alist))
6551 {
6552 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
6553 {
6554 if (HACKEQ_UNSAFE (key, elt_car))
6555 return elt;
6556 }
6557 return Qnil;
6558 }
6559
6560 DEFUN ("old-rassoc", Fold_rassoc, 2, 2, 0, /*
6561 Return non-nil if VALUE is `old-equal' to the cdr of an element of ALIST.
6562 The value is actually the element of ALIST whose cdr equals VALUE.
6563 */
6564 (value, alist))
6565 {
6566 EXTERNAL_ALIST_LOOP_4 (elt, elt_car, elt_cdr, alist)
6567 {
6568 if (internal_old_equal (value, elt_cdr, 0))
6569 return elt;
6570 }
6571 return Qnil;
6572 }
6573
6574 DEFUN ("old-delete", Fold_delete, 2, 2, 0, /*
6575 Delete by side effect any occurrences of ELT as a member of LIST.
6576 The modified LIST is returned. Comparison is done with `old-equal'.
6577 If the first member of LIST is ELT, there is no way to remove it by side
6578 effect; therefore, write `(setq foo (old-delete element foo))' to be sure
6579 of changing the value of `foo'.
6580 */
6581 (elt, list))
6582 {
6583 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
6584 (internal_old_equal (elt, list_elt, 0)));
6585 return list;
6586 }
6587
6588 DEFUN ("old-delq", Fold_delq, 2, 2, 0, /*
6589 Delete by side effect any occurrences of ELT as a member of LIST.
6590 The modified LIST is returned. Comparison is done with `old-eq'.
6591 If the first member of LIST is ELT, there is no way to remove it by side
6592 effect; therefore, write `(setq foo (old-delq element foo))' to be sure of
6593 changing the value of `foo'.
6594 */
6595 (elt, list))
6596 {
6597 EXTERNAL_LIST_LOOP_DELETE_IF (list_elt, list,
6598 (HACKEQ_UNSAFE (elt, list_elt)));
6599 return list;
6598 } 6600 }
6599 6601
6600 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /* 6602 DEFUN ("old-equal", Fold_equal, 2, 2, 0, /*
6601 Return t if two Lisp objects have similar structure and contents. 6603 Return t if two Lisp objects have similar structure and contents.
6602 They must have the same data type. 6604 They must have the same data type.
6608 */ 6610 */
6609 (object1, object2)) 6611 (object1, object2))
6610 { 6612 {
6611 return internal_old_equal (object1, object2, 0) ? Qt : Qnil; 6613 return internal_old_equal (object1, object2, 0) ? Qt : Qnil;
6612 } 6614 }
6615
6616 DEFUN ("old-eq", Fold_eq, 2, 2, 0, /*
6617 Return t if the two args are (in most cases) the same Lisp object.
6618
6619 Special kludge: A character is considered `old-eq' to its equivalent integer
6620 even though they are not the same object and are in fact of different
6621 types. This is ABSOLUTELY AND UTTERLY HORRENDOUS but is necessary to
6622 preserve byte-code compatibility with v19. This kludge is known as the
6623 \"char-int confoundance disease\" and appears in a number of other
6624 functions with `old-foo' equivalents.
6625
6626 Do not use this function!
6627 */
6628 (object1, object2))
6629 {
6630 /* #### blasphemy */
6631 return HACKEQ_UNSAFE (object1, object2) ? Qt : Qnil;
6632 }
6633
6634 #endif
6613 6635
6614 6636
6615 static Lisp_Object replace_string_range_1 (Lisp_Object dest, 6637 static Lisp_Object replace_string_range_1 (Lisp_Object dest,
6616 Lisp_Object start, 6638 Lisp_Object start,
6617 Lisp_Object end, 6639 Lisp_Object end,
11793 DEFSUBR (Felt); 11815 DEFSUBR (Felt);
11794 DEFSUBR (Flast); 11816 DEFSUBR (Flast);
11795 DEFSUBR (Fbutlast); 11817 DEFSUBR (Fbutlast);
11796 DEFSUBR (Fnbutlast); 11818 DEFSUBR (Fnbutlast);
11797 DEFSUBR (Fmember); 11819 DEFSUBR (Fmember);
11798 DEFSUBR (Fold_member);
11799 DEFSUBR (Fmemq); 11820 DEFSUBR (Fmemq);
11800 DEFSUBR (Fold_memq);
11801 DEFSUBR (FmemberX); 11821 DEFSUBR (FmemberX);
11802 DEFSUBR (Fadjoin); 11822 DEFSUBR (Fadjoin);
11803 DEFSUBR (Fassoc); 11823 DEFSUBR (Fassoc);
11804 DEFSUBR (Fold_assoc);
11805 DEFSUBR (Fassq); 11824 DEFSUBR (Fassq);
11806 DEFSUBR (Fold_assq);
11807 DEFSUBR (Frassoc); 11825 DEFSUBR (Frassoc);
11808 DEFSUBR (Fold_rassoc);
11809 DEFSUBR (Frassq); 11826 DEFSUBR (Frassq);
11810 DEFSUBR (Fold_rassq);
11811 11827
11812 DEFSUBR (Fposition); 11828 DEFSUBR (Fposition);
11813 DEFSUBR (Ffind); 11829 DEFSUBR (Ffind);
11814 11830
11815 DEFSUBR (Fold_delete);
11816 DEFSUBR (Fold_delq);
11817 DEFSUBR (FdeleteX); 11831 DEFSUBR (FdeleteX);
11818 DEFSUBR (FremoveX); 11832 DEFSUBR (FremoveX);
11819 DEFSUBR (Fremassoc); 11833 DEFSUBR (Fremassoc);
11820 DEFSUBR (Fremassq); 11834 DEFSUBR (Fremassq);
11821 DEFSUBR (Fremrassoc); 11835 DEFSUBR (Fremrassoc);
11848 DEFSUBR (Fremprop); 11862 DEFSUBR (Fremprop);
11849 DEFSUBR (Fobject_plist); 11863 DEFSUBR (Fobject_plist);
11850 DEFSUBR (Fobject_setplist); 11864 DEFSUBR (Fobject_setplist);
11851 DEFSUBR (Fequal); 11865 DEFSUBR (Fequal);
11852 DEFSUBR (Fequalp); 11866 DEFSUBR (Fequalp);
11867 DEFSUBR (Ffill);
11868
11869 #ifdef SUPPORT_CONFOUNDING_FUNCTIONS
11870 DEFSUBR (Fold_member);
11871 DEFSUBR (Fold_memq);
11872 DEFSUBR (Fold_assoc);
11873 DEFSUBR (Fold_assq);
11874 DEFSUBR (Fold_rassoc);
11875 DEFSUBR (Fold_rassq);
11876 DEFSUBR (Fold_delete);
11877 DEFSUBR (Fold_delq);
11853 DEFSUBR (Fold_equal); 11878 DEFSUBR (Fold_equal);
11854 DEFSUBR (Ffill); 11879 DEFSUBR (Fold_eq);
11880 #endif
11855 11881
11856 DEFSUBR (FassocX); 11882 DEFSUBR (FassocX);
11857 DEFSUBR (FrassocX); 11883 DEFSUBR (FrassocX);
11858 11884
11859 DEFSUBR (Fnconc); 11885 DEFSUBR (Fnconc);