# HG changeset patch # User Aidan Kehoe # Date 1301945657 -3600 # Node ID ccf7e84fe265cc4bc9db2ea13972c5c3e49d8792 # Parent 484b437fc7b427b77cea75392465b10d533a6d98 Correct some interactions of :from-end and :count, #'delete*, #'remove* src/ChangeLog addition: 2011-04-04 Aidan Kehoe * 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. diff -r 484b437fc7b4 -r ccf7e84fe265 src/ChangeLog --- a/src/ChangeLog Mon Apr 04 09:12:39 2011 +0100 +++ b/src/ChangeLog Mon Apr 04 20:34:17 2011 +0100 @@ -1,3 +1,15 @@ +2011-04-04 Aidan Kehoe + + * 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. + 2011-04-04 Aidan Kehoe * fns.c (FremoveX): diff -r 484b437fc7b4 -r ccf7e84fe265 src/fns.c --- a/src/fns.c Mon Apr 04 09:12:39 2011 +0100 +++ b/src/fns.c Mon Apr 04 20:34:17 2011 +0100 @@ -999,7 +999,7 @@ assert (counting >= 0); /* And we're not prepared to handle COUNT from any other caller at the moment. */ - assert (EQ (caller, QremoveX)); + assert (EQ (caller, QremoveX)|| EQ (caller, QdeleteX)); } check_test = get_check_test_function (item, &test, test_not, if_, if_not, @@ -3279,7 +3279,25 @@ { return sequence; } - } + + if (!NILP (from_end)) + { + /* Sigh, this is inelegant. Force count_with_tail () to ignore + the count keyword, so we get the actual number of matching + elements, and can start removing from the beginning for the + from-end case. */ + for (ii = XSUBR (GET_DEFUN_LISP_OBJECT (FdeleteX))->min_args; + ii < nargs; ii += 2) + { + if (EQ (args[ii], Q_count)) + { + args[ii + 1] = Qnil; + break; + } + } + ii = 0; + } + } } check_test = get_check_test_function (item, &test, test_not, if_, if_not, @@ -3627,6 +3645,24 @@ { return sequence; } + + if (!NILP (from_end)) + { + /* Sigh, this is inelegant. Force count_with_tail () to ignore the + count keyword, so we get the actual number of matching + elements, and can start removing from the beginning for the + from-end case. */ + for (ii = XSUBR (GET_DEFUN_LISP_OBJECT (FremoveX))->min_args; + ii < nargs; ii += 2) + { + if (EQ (args[ii], Q_count)) + { + args[ii + 1] = Qnil; + break; + } + } + ii = 0; + } } check_test = get_check_test_function (item, &test, test_not, if_, if_not,