GNU bug report logs -
#70155
29.3; Several Emacs Lisp list functions accept non-list arguments
Previous Next
Reported by: <tpeplt <at> gmail.com>
Date: Tue, 2 Apr 2024 23:16:02 UTC
Severity: wishlist
Tags: wontfix
Found in version 29.3
Done: Stefan Kangas <stefankangas <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#70155: 29.3; Several Emacs Lisp list functions accept non-list arguments
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 70155 <at> debbugs.gnu.org.
--
70155: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=70155
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Mattias Engdegård <mattias.engdegard <at> gmail.com> writes:
> 27 apr. 2024 kl. 10.22 skrev Eli Zaretskii <eliz <at> gnu.org>:
>
>> Mattias, Stefan: any comments on this? Should we document this, or
>> should we change the code?
>
> Eli, thank you for bringing this to our attention. I personally don't see much that we need to change.
Mattias provided an explanation for why we shouldn't (or don't need to)
make any changes here. I think it makes sense, so I'm closing this as
wontfix.
[Message part 3 (message/rfc822, inline)]
The built-in Emacs Lisp functions ‘last’, ‘nthcdr’, ‘take’,
and ‘ntake’ are functions that accept lists as an argument.
However, they also accept non-list arguments without
signaling an error. This is not documented in their
docstrings or in the Emacs Lisp reference manual. The
behavior of the related list functions ‘butlast’ and
‘nbutlast’ is that an error is signaled when the function’s
list argument is not a list.
If it is intended that the functions ‘last’, ‘nthcdr’,
‘take’, and ‘ntake’ should accept non-list arguments without
signaling an error, then this should be documented.
Otherwise, these functions should be changed to behave
consistent with other list functions by signaling an error
when an expected list argument is not a list.
This behavior can be seen by following these steps:
1. Start Emacs at a shell prompt with option ‘-Q’: $ emacs -Q
2. Evaluate the following expressions in the *scratch*
buffer. Note that ‘last’ does not signal an error when a non-list
argument is provided:
(last '(a b c))
;;=> (c)
(last 'a)
;;=> a
(last 3.14)
;;=> 3.14
(last "a string")
;;=> "a string"
3. Evaluate following expressions with the related function ‘butlast’.
Note that the function signals an error when provided a non-list
argument.
(butlast '(a b c))
;;=> (a b)
(butlast 'a)
;;=> *** Eval error *** Wrong type argument: sequencep, a
(butlast 3.14)
;;=> *** Eval error *** Wrong type argument: sequencep, 3.14
(butlast "a string")
;;=> *** Eval error *** Wrong type argument: listp, "a string"
4. Evaluate the following expressions for ‘nthcdr’, ‘take’, and ‘ntake’.
As expected, an error is signaled when the (first) number argument is
non-zero and the list argument is a non-list.
But no error is signaled when the (first) number argument is zero and
the list argument is a non-list.
(nthcdr 0 '(a b c))
;;=> (a b c) (correct, as documented)
(nthcdr 1 'a)
;;=> *** Eval error *** Wrong type argument: listp, a
(nthcdr 0 'a)
;;=> a (expect an error, but got the argument returned instead)
(take 0 '(a b c))
;;=> nil (correct, as documented)
(take 1 'a) => nil
;;=> *** Eval error *** Wrong type argument: listp, a
(take 0 'a)
;;=> nil (expect an error, but got the argument returned instead)
(ntake 0 '(a b c))
;;=> nil (correct, as documented)
(ntake 1 'a) => nil
;;=> *** Eval error *** Wrong type argument: listp, a
(ntake 0 'a)
;;=> nil (expect an error, but got the argument returned instead)
--
This bug report was last modified 84 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.