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 22:04:43 +0000 Message-ID: <87edprm1l0.fsf@posteo.net> References: <871qlrmr14.fsf@gmail.com> <87fsa7cq0v.fsf@posteo.net> <87wn3jl4f8.fsf@gmail.com> <875yb3cntx.fsf@posteo.net> <87r0trb2pz.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="35525"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?B?TWF0w7rFoQ==?= Goljer , emacs-devel@gnu.org To: Augusto Stoffel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 14 23:05:41 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 1pcCm4-00090I-MY for ged-emacs-devel@m.gmane-mx.org; Tue, 14 Mar 2023 23:05:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcClO-0005Dc-VM; Tue, 14 Mar 2023 18:04:59 -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 1pcClN-0005DU-EB for emacs-devel@gnu.org; Tue, 14 Mar 2023 18:04:57 -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 1pcClH-0004rJ-EQ for emacs-devel@gnu.org; Tue, 14 Mar 2023 18:04:53 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 7796B2409B7 for ; Tue, 14 Mar 2023 23:04:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1678831489; bh=LCe9pQhcVQv8b0CoN3rl5Uoex4FUGWBKHKUdbYJ2/50=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=nzY8wGKDeRxrKSilCp+1vcUjcxuJNpPN+PjHeL2wr8671ki9J2nqdpGdsumZrsEWK gGoq8ZeoA5HVdcZHVevB4t2nIZ398Ndhp7pw1ucU5z/A8Z1Y2FLO6GTQby8qCPuEZz EFQ7d8RTkJJiVNByQCVXQ06sv+dDxkTG8lmgno+ChPhbFUQOG1aKmPwpyvtcgFw0kX xpEQT4m+kJyAVOxE6o+q1Kg7EvhIXQDi+YvY5B/etcXbE4ABBfBaW/rc6EEgw5SZ/3 ADHyaQJwsoomNfyLnfy3rJPRtDhx3T9OocplhOQCkhmBrRvGJLiFLriG0c5sRxKUH1 l/i5c4LCXZxvw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Pbnct3Zwsz6tq0; Tue, 14 Mar 2023 23:04:43 +0100 (CET) In-Reply-To: <87r0trb2pz.fsf@gmail.com> (Augusto Stoffel's message of "Tue, 14 Mar 2023 19:35:36 +0100") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM 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:304462 Archived-At: Augusto Stoffel 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=C3=BA=C5=A1 Goljer 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. --=20 Philip Kaludercic