From: <tpeplt@gmail.com>
To: 70155@debbugs.gnu.org
Subject: bug#70155: 29.3; Several Emacs Lisp list functions accept non-list arguments
Date: Tue, 02 Apr 2024 19:15:28 -0400 [thread overview]
Message-ID: <87y19v8igf.fsf@gmail.com> (raw)
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)
--
next reply other threads:[~2024-04-02 23:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 23:15 tpeplt [this message]
2024-04-03 2:55 ` bug#70155: 29.3; Several Emacs Lisp list functions accept non-list arguments Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-27 8:22 ` Eli Zaretskii
2024-04-27 9:48 ` Mattias Engdegård
2024-04-27 15:01 ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-27 14:38 ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y19v8igf.fsf@gmail.com \
--to=tpeplt@gmail.com \
--cc=70155@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).