From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] seq.el: add seq-last for symmetry with seq-first Date: Tue, 14 Mar 2023 15:26:56 +0000 Message-ID: <87fsa7cq0v.fsf@posteo.net> References: <871qlrmr14.fsf@gmail.com> 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="25404"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?utf-8?B?TWF0w7rFoQ==?= Goljer Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 14 16:27:12 2023 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 1pc6YS-0006KD-Km for ged-emacs-devel@m.gmane-mx.org; Tue, 14 Mar 2023 16:27:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pc6Xz-000883-8C; Tue, 14 Mar 2023 11:26:43 -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 1pc6Xx-00083d-Sg for emacs-devel@gnu.org; Tue, 14 Mar 2023 11:26:41 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pc6Xw-0005br-93 for emacs-devel@gnu.org; Tue, 14 Mar 2023 11:26:41 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id A94DA2407F9 for ; Tue, 14 Mar 2023 16:26:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1678807596; bh=yylZmcJiL1mhh8ejY8ewG6h8Ez9oFZZ3fR+pqQzutXo=; h=From:To:Cc:Subject:Date:From; b=JqMCp2KqPqjQcXZrsij0yI4GS/KNjOza0HNE24BaeYfBxKUvE5u5Ok3wLTJnU5pl1 9QwcBRz4fv/o2am41Li8T4B2VHoYVQzD8TNtwrTHuMcIPQq3niBAzOKwPtmOzbva8p iXbo35uyQq1bWoE4nT3+hoseBFePAanB1HWTZbIPY3u+L01IChJPMrFZQAloup6Aec qkxv/6YENyREmPpjedPU3qsp9YZeUb775ABMdOp0zOkbXsJPaYcRO9LmhOzaE1V7Y5 W+Zo79hbfQuMGG1nUhr41+Ro67KujRL79yA/xbT/JXJ9MKedeORbP6HjJTT3IAB6UF +odJnaNgOExag== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4PbcnS03BSz9rxT; Tue, 14 Mar 2023 16:26:33 +0100 (CET) In-Reply-To: <871qlrmr14.fsf@gmail.com> (=?utf-8?B?Ik1hdMO6xaE=?= Goljer"'s message of "Tue, 14 Mar 2023 13:55:03 +0100") Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:304446 Archived-At: Mat=C3=BA=C5=A1 Goljer writes: > Sometimes I want to get the last element of sequence and > (seq-elt seq (1- (seq-length seq)) adds too much noise. Wouldn't it make sense to add a specialised implementation for lists, to avoid recusing the list twice. A thing I notice is that seq-first is not consistent on the way it behaves if the sequence is empty. (seq-first '()) ;=3D> nil while (seq-first []) raises an error. seq-last would have the same issue for vectors, except that it would attempt to index the position -1, which might be confusing? > This patch adds a simple wrapper around that. > --=20 > Best regards, > Mat=C3=BA=C5=A1 Goljer > > From f3ef1a282d0aa1f4c2a21c946845516d0caf8c31 Mon Sep 17 00:00:00 2001 > From: Matus Goljer > Date: Tue, 14 Mar 2023 13:46:10 +0100 > Subject: [PATCH] seq.el: add seq-last for symmetry with seq-first > > --- > lisp/emacs-lisp/seq.el | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el > index 6917c541f2e..2571b558c95 100644 > --- a/lisp/emacs-lisp/seq.el > +++ b/lisp/emacs-lisp/seq.el > @@ -124,6 +124,10 @@ name to be bound to the rest of SEQUENCE." > "Return the first element of SEQUENCE." > (seq-elt sequence 0)) >=20=20 > +(defun seq-last (sequence) > + "Return the last element of SEQUENCE." > + (seq-elt sequence (1- (seq-length sequence)))) > + > (defun seq-rest (sequence) > "Return SEQUENCE with its first element removed." > (seq-drop sequence 1))