From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: Negative nth index Date: Tue, 24 Dec 2024 21:33:17 +0000 Message-ID: <87r05wahsi.fsf@protonmail.com> References: <865xnc6u9n.fsf@gnu.org> <87jzbs9jlk.fsf@gnu.org> Reply-To: Pip Cet Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31963"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Kangas , Tassilo Horn , Eli Zaretskii , Anand Tamariya , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 25 04:21:44 2024 Return-path: Envelope-to: ged-emacs-devel@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 1tQHxu-00085h-Jt for ged-emacs-devel@m.gmane-mx.org; Wed, 25 Dec 2024 04:21:42 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQHx2-0008Te-6P; Tue, 24 Dec 2024 22:20:48 -0500 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 1tQCWw-00021j-Ru for emacs-devel@gnu.org; Tue, 24 Dec 2024 16:33:30 -0500 Original-Received: from mail-10630.protonmail.ch ([79.135.106.30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tQCWu-0004Jw-JC for emacs-devel@gnu.org; Tue, 24 Dec 2024 16:33:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1735076003; x=1735335203; bh=PR/lMJ+hsWOQAR+uPB/BANFmGwq7/f71dyF8W8wuEww=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=glbqISxq9f6wcKhhPRHyial7MB8k/HaprdveC8c07BrObfMtvx7NzDtKtbqDTbuPr Q8WE4eY8gYZcWz0al1Zw4sAVMe3HbmHSfTw+49gpCU5SldNwWd9w//BvlCGd7ONALH 0I48i8h8jqG2+11uwADkdFqgPrjiOaKmsiEGhXIysNKveQbQPSgvOFyvtds+HOzPkE 11lhaA9U+stw16mMeQEIx03x6Z35GQlhftlrAfZ2AdasjzFRqHSrBvREL0Lxwa6rf0 U2TFFS4yUfg72L4h7LAq1fkvo2p0/pHoYaFcUk9jHa8u7l5pIKNwwj2cXygx46cU3U G2t6c5JBOxplQ== In-Reply-To: Feedback-ID: 112775352:user:proton X-Pm-Message-ID: f89dc9f05f74ebdceed8591ef6e9b3e71fb91e43 Received-SPF: pass client-ip=79.135.106.30; envelope-from=pipcet@protonmail.com; helo=mail-10630.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 24 Dec 2024 22:20:46 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327048 Archived-At: "Stefan Monnier" writes: >>>>> Should negative index for nth be valid? e.g. >>>>> (nth -1 '(1 2)) returns 1 > > [ I'd make it return 2 otherwise you can't use it to return the > last element. ] I think the OP meant that (nth -1 '(1 2)) is 1 on current Emacs, which is definitely unexpected. > I don't see a strong argument in favor of making it index from the end > rather than signal an error. What would the implementation look like? I agree, but the current implementation does not signal an error. It should, and I think that's what the suggestion was. To me, (nth -1 list) means "I set list to be the cdr of x, now tell me what x was", so the right answer is "I can't do that, so here's an error and go fix your code". It's perfectly analogous to (/ 0 0), which means "I multiplied a number x by 0 and got 0. Tell me what x was." For circular lists, we could give a possible answer for x (just as we could give a possible answer for x in the 0/0 example), by moving back in the cycle, but it's not the only possible answer, so we shouldn't. (For lists both proper and circular, we could also create a new cons cell and return it, I guess). Indexing from the end is even worse than defining 0/0 to be 17. Pip