GNU bug report logs - #15059
24.3; nth with negative index values

Previous Next

Package: emacs;

Reported by: Wilfred Hughes <wilfred <at> editd.com>

Date: Fri, 9 Aug 2013 11:57:01 UTC

Severity: minor

Tags: notabug, wontfix

Found in version 24.3

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15059 in the body.
You can then email your comments to 15059 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Fri, 09 Aug 2013 11:57:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Wilfred Hughes <wilfred <at> editd.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 09 Aug 2013 11:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Wilfred Hughes <wilfred <at> editd.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; nth with negative index values
Date: Fri, 9 Aug 2013 12:55:53 +0100
I've noticed that nth returns the first item in a list, when it's given
a negative index.

(nth -1 '(5 6 7)) ;; 5
(nth -2 '(5 6 7)) ;; 5

Judging by my reading of the docstring, I was expecting nil (though
raising an error might be a sensible behaviour instead).

In GNU Emacs 24.3.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.8.2)
 of 2013-07-30 on -var-lib-archbuild-staging-x86_64-jgc
Windowing system distributor `The X.Org Foundation', version 11.0.11402000
Configured using:
 `configure '--prefix=/usr' '--sysconfdir=/etc' '--libexecdir=/usr/lib'
 '--localstatedir=/var' '--with-x-toolkit=gtk3' '--with-xft'
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector
 --param=ssp-buffer-size=4'
 'LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro'
 'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
  value of $LANG: en_GB.utf8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Fri, 09 Aug 2013 15:52:01 GMT) Full text and rfc822 format available.

Message #8 received at 15059 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Wilfred Hughes <wilfred <at> editd.com>
Cc: 15059 <at> debbugs.gnu.org
Subject: Re: bug#15059: 24.3; nth with negative index values
Date: Fri, 09 Aug 2013 17:51:50 +0200
Wilfred Hughes <wilfred <at> editd.com> writes:

> I've noticed that nth returns the first item in a list, when it's given
> a negative index.
>
> (nth -1 '(5 6 7)) ;; 5
> (nth -2 '(5 6 7)) ;; 5
>
> Judging by my reading of the docstring, I was expecting nil

The list is longer than -1, so this case doesn't apply.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Fri, 09 Aug 2013 18:53:02 GMT) Full text and rfc822 format available.

Message #11 received at 15059 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Wilfred Hughes <wilfred <at> editd.com>
Cc: 15059 <at> debbugs.gnu.org
Subject: Re: bug#15059: 24.3; nth with negative index values
Date: Fri, 09 Aug 2013 14:52:29 -0400
Wilfred Hughes wrote:

> (nth -1 '(5 6 7)) ;; 5
> (nth -2 '(5 6 7)) ;; 5
>
> Judging by my reading of the docstring, I was expecting nil (though
> raising an error might be a sensible behaviour instead).

Easy to raise an error (unless something was relying on the behaviour
for -ve arguments?):

*** src/fns.c	2013-08-01 22:24:02 +0000
--- src/fns.c	2013-08-09 18:43:02 +0000
***************
*** 1277,1283 ****
    (Lisp_Object n, Lisp_Object list)
  {
    EMACS_INT i, num;
!   CHECK_NUMBER (n);
    num = XINT (n);
    for (i = 0; i < num && !NILP (list); i++)
      {
--- 1277,1283 ----
    (Lisp_Object n, Lisp_Object list)
  {
    EMACS_INT i, num;
!   CHECK_NATNUM (n);
    num = XINT (n);
    for (i = 0; i < num && !NILP (list); i++)
      {





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Fri, 09 Aug 2013 21:59:01 GMT) Full text and rfc822 format available.

Message #14 received at 15059 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Wilfred Hughes <wilfred <at> editd.com>, 15059 <at> debbugs.gnu.org
Subject: Re: bug#15059: 24.3; nth with negative index values
Date: Fri, 09 Aug 2013 17:58:38 -0400
> Easy to raise an error (unless something was relying on the behaviour
> for -ve arguments?):

We could try.  But note that Emacs-19.34 already behaved like that (I
don't have any older version at hand to test).  Not sure it's important
to "fix".


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Sat, 10 Aug 2013 01:32:01 GMT) Full text and rfc822 format available.

Message #17 received at 15059 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Wilfred Hughes <wilfred <at> editd.com>, 15059 <at> debbugs.gnu.org
Subject: Re: bug#15059: 24.3; nth with negative index values
Date: Fri, 09 Aug 2013 21:31:26 -0400
Stefan Monnier wrote:

>> Easy to raise an error (unless something was relying on the behaviour
>> for -ve arguments?):
>
> We could try.  But note that Emacs-19.34 already behaved like that (I
> don't have any older version at hand to test).  Not sure it's important
> to "fix".

Oh, the elisp manual actually documents the -ve argument case:

   -- Function: nth n list
  [...]
  If N is negative, `nth' returns the first element of LIST.
  [...]
  (nth -3 '(1 2 3 4))
               => 1

All hope is lost!




Added tag(s) notabug and wontfix. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 11 Aug 2013 18:50:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 15059 <at> debbugs.gnu.org and Wilfred Hughes <wilfred <at> editd.com> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 11 Aug 2013 18:50:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Mon, 12 Aug 2013 10:12:01 GMT) Full text and rfc822 format available.

Message #24 received at 15059 <at> debbugs.gnu.org (full text, mbox):

From: Wilfred Hughes <wilfred <at> editd.com>
To: 15059 <at> debbugs.gnu.org
Subject: Re: bug#15059: 24.3; nth with negative index values
Date: Mon, 12 Aug 2013 11:10:51 +0100
[Message part 1 (text/plain, inline)]
Ah, great to see this behaviour is documented. Could the docstring of nth
and nthcdr be changed to also point to this part of the elisp manual,
similar to cdr?
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Mon, 12 Aug 2013 14:10:01 GMT) Full text and rfc822 format available.

Message #27 received at 15059 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Wilfred Hughes <wilfred <at> editd.com>
Cc: 15059 <at> debbugs.gnu.org
Subject: Re: bug#15059: 24.3; nth with negative index values
Date: Mon, 12 Aug 2013 10:09:39 -0400
> Ah, great to see this behaviour is documented. Could the docstring of nth
> and nthcdr be changed to also point to this part of the elisp manual,
> similar to cdr?

I prefer to leave it undocumented where possible (I'd be even tempted
to remove the part of the Elisp manual that documents it).
Just don't rely on this behavior, it's a bad idea.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15059; Package emacs. (Tue, 13 Aug 2013 07:16:01 GMT) Full text and rfc822 format available.

Message #30 received at 15059 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Wilfred Hughes <wilfred <at> editd.com>, 15059 <at> debbugs.gnu.org
Subject: Re: bug#15059: 24.3; nth with negative index values
Date: Tue, 13 Aug 2013 03:15:51 -0400
Stefan Monnier wrote:

> (I'd be even tempted to remove the part of the Elisp manual that
> documents it).

I was thinking the same thing, so I did that.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 10 Sep 2013 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 286 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.