From: Drew Adams <drew.adams@oracle.com>
To: "tomas@tuxteam.de" <tomas@tuxteam.de>,
"help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: RE: [External] : Re: Chopping the last element of a list
Date: Fri, 29 Apr 2022 15:55:39 +0000 [thread overview]
Message-ID: <SJ0PR10MB548887DF1FEA726B9B979D1AF3FC9@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <YmtzxtmB6n1qKY3i@tuxteam.de>
> > > Here. It returns the last element, and it
> > > chops that last element off the list.
> >
> > Thanks. It's quite simple and useful to have along with
> > last/butlast/etc.
> >
> > Will you put it into subr.el, so emacs has it built-in ?
>
> Read Drew's code again. Read the examples he provided.
>
> Now, answer this one question: for a list with exactly
> one element, say
>
> (setq foo '(1))
>
> what is its last element? What would you expect choplast
> to do? What does Drew's implementation do? Surprise?
Yes. If you want to return 1 in that case then
be aware that there's no way to modify a cons
to turn it into nil. (nil is a scalar - what
Lisp calls an "atom"; a cons is not.)
If you want behavior that returns 1 and sets some
variable whose value is (1) to nil, then you need
to pass a variable (that is, a symbol), not a list,
as the argument.
E.g., in that case you want behavior similar to
what `add-to-list' does: you pass it a _variable_
and it updates the variable's value.
I intentionally kept the same behavior as `butlast':
return nil and don't change anything for a list
with less than 2 elements.
next prev parent reply other threads:[~2022-04-29 15:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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
2022-04-29 15:55 ` Drew Adams [this message]
2022-04-30 5:25 ` [External] : " tomas
2022-04-30 14:47 ` Drew Adams
2022-04-30 14:51 ` tomas
2022-04-29 15:55 ` [External] : " Drew Adams
[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-29 3:33 ` [External] : " Drew Adams
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=SJ0PR10MB548887DF1FEA726B9B979D1AF3FC9@SJ0PR10MB5488.namprd10.prod.outlook.com \
--to=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=tomas@tuxteam.de \
/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.