From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "tomas@tuxteam.de" Newsgroups: gmane.emacs.help Subject: Re: [External] : Re: Chopping the last element of a list Date: Sat, 30 Apr 2022 07:25:57 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="XVUBHlOwRORgIn60" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29561"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "help-gnu-emacs@gnu.org" To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 30 07:27:08 2022 Return-path: Envelope-to: geh-help-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 1nkfdM-0007WM-5u for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 30 Apr 2022 07:27:08 +0200 Original-Received: from localhost ([::1]:44318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkfdL-0002mX-1E for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 30 Apr 2022 01:27:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkfcN-0002mL-G2 for help-gnu-emacs@gnu.org; Sat, 30 Apr 2022 01:26:09 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:44614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkfcH-0006Ae-FA for help-gnu-emacs@gnu.org; Sat, 30 Apr 2022 01:26:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject :Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ixf5YDOuV6sZq8Kzvbk+RlHwRhYhMaHWomLP1deHWds=; b=bNtSIp2tA0eOnuSVjQaT57GhXC UnTRb1aAkfTD35Appx08lHun+rBST6OAXbrb+gI6wlv5Gyido6AeMa+LjJurTmp533zazhjfq8KML Y5ZIsqeRCzR8CZ6xF3LbLArKIPHOhoLFONuPy0wcD+JXihx7YKd0kmIR/CltApnA3AKa0d89mbsJl 1ecrvNClfJ0gOFy6kE9s/6re8EJH6OCxO6hv3Ko3t48mg6bp9vI1b6RXSSgyL2L7h/d3jY+kzqTcS 80ScYrIJ5wjP6VsCjrKLoX/4x2Xmew6Gws5FC3wcKqNFvhAj6syy4S1RjvzN8j4wh8af3Cec7zCY0 DNG3cvwQ==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1nkfcD-0005bF-IC; Sat, 30 Apr 2022 07:25:57 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:137092 Archived-At: --XVUBHlOwRORgIn60 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 29, 2022 at 03:55:39PM +0000, Drew Adams wrote: > > > > Here. It returns the last element, and it > > > > chops that last element off the list. > > > > > > Thanks. It's quite simple and useful to have along with > > > last/butlast/etc. > > > > > > Will you put it into subr.el, so emacs has it built-in ? > >=20 > > Read Drew's code again. Read the examples he provided. > >=20 > > Now, answer this one question: for a list with exactly > > one element, say > >=20 > > (setq foo '(1)) > >=20 > > what is its last element? What would you expect choplast > > to do? What does Drew's implementation do? Surprise? >=20 > Yes. If you want to return 1 in that case then > be aware that there's no way to modify a cons > to turn it into nil. (nil is a scalar - what > Lisp calls an "atom"; a cons is not.) I know... > I intentionally kept the same behavior as `butlast': > return nil and don't change anything for a list > with less than 2 elements. =2E..and I know you know :) I wanted to help OP to understand why changing things "in place" has this special feel about it in Lisp land :-) Cheers --=20 t --XVUBHlOwRORgIn60 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCYmzIVwAKCRAFyCz1etHa RlgmAJ97yM8qSkmQk8A9ohIYUzV/Y8JAvACfbPykIKY9j8KFmvDMTKP7tF6BeMM= =M7BX -----END PGP SIGNATURE----- --XVUBHlOwRORgIn60--