comparison src/fns.c @ 5395:ccf7e84fe265

Correct some interactions of :from-end and :count, #'delete*, #'remove* src/ChangeLog addition: 2011-04-04 Aidan Kehoe <kehoea@parhasard.net> * fns.c (count_with_tail): This can be legitimately called from #'delete* with a specified COUNT keyword value, accept this in the assertion. * fns.c (FdeleteX): * fns.c (FremoveX): If COUNT is specified and FROM-END is non-nil, set COUNT to nil in the argument vector, so count_with_tail doesn't see it when calculating the total number of times an item occurs. Fixes problems with the interaction of :count and :from-end.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 04 Apr 2011 20:34:17 +0100
parents 484b437fc7b4
children 248176c74e6b
comparison
equal deleted inserted replaced
5394:484b437fc7b4 5395:ccf7e84fe265
997 997
998 /* Our callers should have filtered out non-positive COUNT. */ 998 /* Our callers should have filtered out non-positive COUNT. */
999 assert (counting >= 0); 999 assert (counting >= 0);
1000 /* And we're not prepared to handle COUNT from any other caller at the 1000 /* And we're not prepared to handle COUNT from any other caller at the
1001 moment. */ 1001 moment. */
1002 assert (EQ (caller, QremoveX)); 1002 assert (EQ (caller, QremoveX)|| EQ (caller, QdeleteX));
1003 } 1003 }
1004 1004
1005 check_test = get_check_test_function (item, &test, test_not, if_, if_not, 1005 check_test = get_check_test_function (item, &test, test_not, if_, if_not,
1006 key, &test_not_unboundp); 1006 key, &test_not_unboundp);
1007 1007
3277 3277
3278 if (counting < 1) 3278 if (counting < 1)
3279 { 3279 {
3280 return sequence; 3280 return sequence;
3281 } 3281 }
3282 } 3282
3283 if (!NILP (from_end))
3284 {
3285 /* Sigh, this is inelegant. Force count_with_tail () to ignore
3286 the count keyword, so we get the actual number of matching
3287 elements, and can start removing from the beginning for the
3288 from-end case. */
3289 for (ii = XSUBR (GET_DEFUN_LISP_OBJECT (FdeleteX))->min_args;
3290 ii < nargs; ii += 2)
3291 {
3292 if (EQ (args[ii], Q_count))
3293 {
3294 args[ii + 1] = Qnil;
3295 break;
3296 }
3297 }
3298 ii = 0;
3299 }
3300 }
3283 } 3301 }
3284 3302
3285 check_test = get_check_test_function (item, &test, test_not, if_, if_not, 3303 check_test = get_check_test_function (item, &test, test_not, if_, if_not,
3286 key, &test_not_unboundp); 3304 key, &test_not_unboundp);
3287 3305
3625 3643
3626 if (counting <= 0) 3644 if (counting <= 0)
3627 { 3645 {
3628 return sequence; 3646 return sequence;
3629 } 3647 }
3648
3649 if (!NILP (from_end))
3650 {
3651 /* Sigh, this is inelegant. Force count_with_tail () to ignore the
3652 count keyword, so we get the actual number of matching
3653 elements, and can start removing from the beginning for the
3654 from-end case. */
3655 for (ii = XSUBR (GET_DEFUN_LISP_OBJECT (FremoveX))->min_args;
3656 ii < nargs; ii += 2)
3657 {
3658 if (EQ (args[ii], Q_count))
3659 {
3660 args[ii + 1] = Qnil;
3661 break;
3662 }
3663 }
3664 ii = 0;
3665 }
3630 } 3666 }
3631 3667
3632 check_test = get_check_test_function (item, &test, test_not, if_, if_not, 3668 check_test = get_check_test_function (item, &test, test_not, if_, if_not,
3633 key, &test_not_unboundp); 3669 key, &test_not_unboundp);
3634 3670