diff options
| author | Mattias EngdegÄrd | 2022-08-30 16:44:51 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2022-08-30 16:48:25 +0200 |
| commit | e1e60e51bf324aaa2137075827c4d08a331a7bef (patch) | |
| tree | 7eb07197b4db9009b310ca85736076f0a97ac57d | |
| parent | 5cf7b1ada96c2e209580d086d15b1bbe5b345657 (diff) | |
| download | emacs-e1e60e51bf324aaa2137075827c4d08a331a7bef.tar.gz emacs-e1e60e51bf324aaa2137075827c4d08a331a7bef.zip | |
Accept bignum arguments in `take` and `ntake`
* src/fns.c (Ftake, Fntake): Accept any integer as first argument, for
completeness.
* test/src/fns-tests.el (fns--take-ntake): Add test cases.
| -rw-r--r-- | src/fns.c | 20 | ||||
| -rw-r--r-- | test/src/fns-tests.el | 10 |
2 files changed, 27 insertions, 3 deletions
| @@ -1563,7 +1563,15 @@ If N is zero or negative, return nil. | |||
| 1563 | If N is greater or equal to the length of LIST, return LIST (or a copy). */) | 1563 | If N is greater or equal to the length of LIST, return LIST (or a copy). */) |
| 1564 | (Lisp_Object n, Lisp_Object list) | 1564 | (Lisp_Object n, Lisp_Object list) |
| 1565 | { | 1565 | { |
| 1566 | CHECK_FIXNUM (n); | 1566 | if (BIGNUMP (n)) |
| 1567 | { | ||
| 1568 | if (mpz_sgn (*xbignum_val (n)) < 0) | ||
| 1569 | return Qnil; | ||
| 1570 | CHECK_LIST (list); | ||
| 1571 | return list; | ||
| 1572 | } | ||
| 1573 | if (!FIXNUMP (n)) | ||
| 1574 | wrong_type_argument (Qintegerp, n); | ||
| 1567 | EMACS_INT m = XFIXNUM (n); | 1575 | EMACS_INT m = XFIXNUM (n); |
| 1568 | if (m <= 0) | 1576 | if (m <= 0) |
| 1569 | return Qnil; | 1577 | return Qnil; |
| @@ -1594,7 +1602,15 @@ If N is greater or equal to the length of LIST, return LIST unmodified. | |||
| 1594 | Otherwise, return LIST after truncating it. */) | 1602 | Otherwise, return LIST after truncating it. */) |
| 1595 | (Lisp_Object n, Lisp_Object list) | 1603 | (Lisp_Object n, Lisp_Object list) |
| 1596 | { | 1604 | { |
| 1597 | CHECK_FIXNUM (n); | 1605 | if (BIGNUMP (n)) |
| 1606 | { | ||
| 1607 | if (mpz_sgn (*xbignum_val (n)) < 0) | ||
| 1608 | return Qnil; | ||
| 1609 | CHECK_LIST (list); | ||
| 1610 | return list; | ||
| 1611 | } | ||
| 1612 | if (!FIXNUMP (n)) | ||
| 1613 | wrong_type_argument (Qintegerp, n); | ||
| 1598 | EMACS_INT m = XFIXNUM (n); | 1614 | EMACS_INT m = XFIXNUM (n); |
| 1599 | if (m <= 0) | 1615 | if (m <= 0) |
| 1600 | return Qnil; | 1616 | return Qnil; |
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index a84cce3ad4e..4ef428af03e 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -1412,6 +1412,14 @@ | |||
| 1412 | (should (equal (take 5 list) '(a b c b c))) | 1412 | (should (equal (take 5 list) '(a b c b c))) |
| 1413 | (should (equal (take 10 list) '(a b c b c b c b c b))) | 1413 | (should (equal (take 10 list) '(a b c b c b c b c b))) |
| 1414 | 1414 | ||
| 1415 | (should (equal (ntake 10 list) '(a b))))) | 1415 | (should (equal (ntake 10 list) '(a b)))) |
| 1416 | |||
| 1417 | ;; Bignum N argument. | ||
| 1418 | (let ((list (list 'a 'b 'c))) | ||
| 1419 | (should (equal (take (+ most-positive-fixnum 1) list) '(a b c))) | ||
| 1420 | (should (equal (take (- most-negative-fixnum 1) list) nil)) | ||
| 1421 | (should (equal (ntake (+ most-positive-fixnum 1) list) '(a b c))) | ||
| 1422 | (should (equal (ntake (- most-negative-fixnum 1) list) nil)) | ||
| 1423 | (should (equal list '(a b c))))) | ||
| 1416 | 1424 | ||
| 1417 | ;;; fns-tests.el ends here | 1425 | ;;; fns-tests.el ends here |