From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#70155: 29.3; Several Emacs Lisp list functions accept non-list arguments Date: Sat, 27 Apr 2024 11:22:06 +0300 Message-ID: <86ttjnw6z5.fsf@gnu.org> References: <87y19v8igf.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3530"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70155@debbugs.gnu.org To: tpeplt@gmail.com, Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 27 10:23:04 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s0dKo-0000bN-TW for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Apr 2024 10:23:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0dKX-0005sX-Cp; Sat, 27 Apr 2024 04:22:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s0dKV-0005s6-Du for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2024 04:22:43 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0dKV-0000OE-6F for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2024 04:22:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s0dKn-0005tX-Pk for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2024 04:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Apr 2024 08:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70155 X-GNU-PR-Package: emacs Original-Received: via spool by 70155-submit@debbugs.gnu.org id=B70155.171420615822385 (code B ref 70155); Sat, 27 Apr 2024 08:23:01 +0000 Original-Received: (at 70155) by debbugs.gnu.org; 27 Apr 2024 08:22:38 +0000 Original-Received: from localhost ([127.0.0.1]:38866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s0dKN-0005oY-RT for submit@debbugs.gnu.org; Sat, 27 Apr 2024 04:22:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s0dKK-0005mm-Dd for 70155@debbugs.gnu.org; Sat, 27 Apr 2024 04:22:33 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s0dJw-0000K9-0m; Sat, 27 Apr 2024 04:22:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=WB6tkTjbxdsGL5LtTHlf1tscSbtNGvHg2QQocJyU5zc=; b=quLvbpPGLzAj2gf2XR91 q/emZCx33D7Y8+8hZf4hlS+OBhUvSD/XspGymsXAlk40O1IzJVQ3om+I3/G+W5rZHAaFaPDrJXujt 4xRHJx35yUIo+0VsrdBkN3YyAxG0sQWYFdDxzj3RZIeVAS4f0+dHzFtJg3LwfbM1XYS+fNYwUN9aj JZAXA5/pfpWOv4QGu/DXlTXlTKitFH4vBN/zCTCDqd9MvldNMCqLq9Jn47iGtUIAwtNMCoS3PG8vZ BTXkmaG+JNInxkP/o/luFGu1mf6QywgxUDQzz5TfJyqJ7GQrCtYLoajGEF4zfW5wNFmrEQ/Au2RC7 hWKjtw7wBvGhnA==; In-Reply-To: <87y19v8igf.fsf@gmail.com> (tpeplt@gmail.com) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:284017 Archived-At: > From: > Date: Tue, 02 Apr 2024 19:15:28 -0400 > > > 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) > > -- Mattias, Stefan: any comments on this? Should we document this, or should we change the code?