From: Philip Kaludercic <philipk@posteo.net>
To: Augusto Stoffel <arstoffel@gmail.com>
Cc: "Matúš Goljer" <matus.goljer@gmail.com>, emacs-devel@gnu.org
Subject: Re: [PATCH] seq.el: add seq-last for symmetry with seq-first
Date: Tue, 14 Mar 2023 22:04:43 +0000 [thread overview]
Message-ID: <87edprm1l0.fsf@posteo.net> (raw)
In-Reply-To: <87r0trb2pz.fsf@gmail.com> (Augusto Stoffel's message of "Tue, 14 Mar 2023 19:35:36 +0100")
Augusto Stoffel <arstoffel@gmail.com> writes:
> Maybe it's more useful to allow negative arguments in seq-elt? Saying
> (seq-elt seq -1) isn't much more effort than (seq-last seq).
>
> On Tue, 14 Mar 2023 at 16:14, Philip Kaludercic wrote:
>
>>> I think for lists it should behave as `nth` or `elt`, so it gives nil.
>>
>> But why? Wouldn't that be a leaky abstraction, since the behaviour
>> doesn't consistently abstract over the concrete sequence types? If code
>> doesn't want to worry about what sequence is being used, then it has to
>> manually check the return value or if a signal was raised, depending on
>> the type of the argument to seq-last (which is to ignore the issue that
>> we cannot distinguish between (seq-first '()) and (seq-first '(nil)),
>> the same also being the case for seq-last).
>
> It would be good to look systematically at what errors seq.el can
> signal. But it also seems that in practice the main value of seq.el is
> to provide a bunch of handy functions rather than allowing you to work
> with a sequence whose type you don't know.
I don't think the two are necessarily different issues. Using seq might
incur a dispatch overhead, but you get the advantage that your code is
less bound to a specific data structure and is therefore easier to
adjust later on because you rely on the abstract behaviour instead of a
concrete structure.
Matúš Goljer <matus.goljer@gmail.com> writes:
>> Maybe it's more useful to allow negative arguments in seq-elt? Saying
>> (seq-elt seq -1) isn't much more effort than (seq-last seq).
>
> I'm personally a bit ambiguous about negative indices. It's nice for
> those one liners when you need them, but they are quite confusing
> especially if you switch between languages and they all implement them a
> bit differently.
The only language I am really familiar with is python, and what that
effectively does is (mod i (length n)), what do other languages do?
> Sometimes having simple semantics of "last item" is better for
> understanding the code 6 months down the line or when just skimming
> through.
>
> But of course we can have both. Emacs itself has `car` but `nth 0` also
> works.
True.
>>>> I think for lists it should behave as `nth` or `elt`, so it gives nil.
>>>
>>> But why? Wouldn't that be a leaky abstraction, since the behaviour
>>> doesn't consistently abstract over the concrete sequence types? If code
>>> doesn't want to worry about what sequence is being used, then it has to
>>> manually check the return value or if a signal was raised, depending on
>>> the type of the argument to seq-last (which is to ignore the issue that
>>> we cannot distinguish between (seq-first '()) and (seq-first '(nil)),
>>> the same also being the case for seq-last).
>>
>> It would be good to look systematically at what errors seq.el can
>> signal. But it also seems that in practice the main value of seq.el is
>> to provide a bunch of handy functions rather than allowing you to work
>> with a sequence whose type you don't know.
>
> Yea, this has been my experience as well. Usually I know what the
> sequence is, but seq provides a nice interface to not have to *remember*
> how to do what I need. Just seq-do it and it will work somehow.
Another thing that should be kept in mind that sequences can be streams
(as provided by stream.el), and there doesn't have to be a final
element.
--
Philip Kaludercic
next prev parent reply other threads:[~2023-03-14 22:04 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
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 [this message]
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=87edprm1l0.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=arstoffel@gmail.com \
--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).