all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: tpeplt <tpeplt@gmail.com>,
	"help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: RE: [External] : Undefined behavior for the function ‘last’ or an error?
Date: Mon, 1 Apr 2024 17:28:02 +0000	[thread overview]
Message-ID: <SJ0PR10MB54888A11CF049379124BE449F33F2@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <87il119g8u.fsf@gmail.com>

> The built-in Emacs Lisp function ‘last’ accepts
> a list as its argument:
> 
> (last '(a b c)) => (c)
> 
> It also (surprisingly) accepts a non-list as its argument:
> 
> (last 'a) => a
> (last 3.14) => 3.14
> (last "string of chars") => "string of chars"

Congratulations!

This regression was introduced in Emacs 24.5.
Prior to that it would raise an error.

In 24.5 `safe-length' was substituted for
`length', and that results in what you see.

(`C-h f safe-length'.)

IMO this should be fixed.  Someone(TM) will
maybe say it's intentional (but then it
should be doc'd).

`safe-length' is good, in avoiding pbs with
circular lists etc.  But either some test
for a list (or a sequence) should be used
or this nontraditional behavior for `last'
should be doc'd.  (`last' should of course
work with dotted lists.)

`last' is one of the oldest Lisp functions.
We really shouldn't be fiddling with its
behavior in unexpected ways.


  parent reply	other threads:[~2024-04-01 17:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 16:53 Undefined behavior for the function ‘last’ or an error? tpeplt
2024-04-01 17:12 ` tpeplt
2024-04-01 17:28 ` Drew Adams [this message]
2024-04-01 18:35   ` [External] : " tpeplt
2024-04-01 19:25     ` Drew Adams
2024-04-01 20:11       ` tpeplt
2024-04-03  1:05         ` tpeplt

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=SJ0PR10MB54888A11CF049379124BE449F33F2@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=tpeplt@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 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.