From: Philip Kaludercic <philipk@posteo.net>
To: "Matúš Goljer" <matus.goljer@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] seq.el: add seq-last for symmetry with seq-first
Date: Tue, 14 Mar 2023 15:26:56 +0000 [thread overview]
Message-ID: <87fsa7cq0v.fsf@posteo.net> (raw)
In-Reply-To: <871qlrmr14.fsf@gmail.com> ("Matúš Goljer"'s message of "Tue, 14 Mar 2023 13:55:03 +0100")
Matúš Goljer <matus.goljer@gmail.com> 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 '()) ;=> 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.
> --
> Best regards,
> Matúš Goljer
>
> From f3ef1a282d0aa1f4c2a21c946845516d0caf8c31 Mon Sep 17 00:00:00 2001
> From: Matus Goljer <matus.goljer@gmail.com>
> 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))
>
> +(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))
next prev parent reply other threads:[~2023-03-14 15:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-14 12:55 [PATCH] seq.el: add seq-last for symmetry with seq-first Matúš Goljer
2023-03-14 15:26 ` Philip Kaludercic [this message]
2023-03-14 15:48 ` Matúš Goljer
2023-03-14 16:14 ` Philip Kaludercic
2023-03-14 18:35 ` Augusto Stoffel
2023-03-14 19:14 ` Matúš Goljer
2023-03-14 22:04 ` Philip Kaludercic
2023-03-15 7:06 ` Augusto Stoffel
2023-03-15 8:09 ` Philip Kaludercic
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=87fsa7cq0v.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=emacs-devel@gnu.org \
--cc=matus.goljer@gmail.com \
/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).