all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "'Help-Gnu-Emacs \(help-gnu-emacs@gnu.org\)'" <help-gnu-emacs@gnu.org>
Subject: Re: Chopping the last element of a list
Date: Fri, 29 Apr 2022 01:02:50 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488B6B027B6980946CBA65EF3FC9@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 812 bytes --]

> Right, so you see the problem with functions like `last` and `butlast`
> which work on the end of a list: they are only useful if that's the
> only thing you do with that list.  As soon as you try to do more, then
> you end up traversing the list multiple times.
> 
> > Shouldn't emacs provide a function which does it in one step, so the
> > list isn't walked twice? E.g. (choplast mylist)
> 
> That would just suffer from the same problem you just experienced
> (i.e. everytime you need to do `choplast` plus something else, you'll
> end up traversing the list twice).
> 
> Instead, every time you need to work on the end of a list, you should
> start by getting a reference to that end (presumably with `last` with
> an appropriate N) and then you work locally on that end.

+1.  Well put.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 13432 bytes --]

             reply	other threads:[~2022-04-29  1:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29  1:02 Drew Adams [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-04-28 21:27 Chopping the last element of a list Drew Adams
2022-04-29  4:26 ` emacsq
2022-04-29  5:12   ` tomas
     [not found] <fn8q5CKH0JRjvhUBk-weL0eqI0HA5QMHJ7ag-wmP2c_YXYavm1MNiga-Vz77nJCHECfOfW-UdvaTOH2nEAIopin5Nn7mXg2jgOxpVffs4So=@protonmail.com>
2022-04-28  9:21 ` emacsq via Users list for the GNU Emacs text editor
2022-04-28 21:33   ` Michael Heerdegen
2022-04-28 23:52   ` Stefan Monnier via Users list for the GNU Emacs text editor

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SJ0PR10MB5488B6B027B6980946CBA65EF3FC9@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.