* bug#15059: 24.3; nth with negative index values
@ 2013-08-09 11:55 Wilfred Hughes
2013-08-09 15:51 ` Andreas Schwab
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Wilfred Hughes @ 2013-08-09 11:55 UTC (permalink / raw)
To: 15059
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#15059: 24.3; nth with negative index values
2013-08-09 11:55 bug#15059: 24.3; nth with negative index values Wilfred Hughes
@ 2013-08-09 15:51 ` Andreas Schwab
2013-08-09 18:52 ` Glenn Morris
2013-08-12 10:10 ` Wilfred Hughes
2 siblings, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2013-08-09 15:51 UTC (permalink / raw)
To: Wilfred Hughes; +Cc: 15059
Wilfred Hughes <wilfred@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@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#15059: 24.3; nth with negative index values
2013-08-09 11:55 bug#15059: 24.3; nth with negative index values Wilfred Hughes
2013-08-09 15:51 ` Andreas Schwab
@ 2013-08-09 18:52 ` Glenn Morris
2013-08-09 21:58 ` Stefan Monnier
2013-08-12 10:10 ` Wilfred Hughes
2 siblings, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2013-08-09 18:52 UTC (permalink / raw)
To: Wilfred Hughes; +Cc: 15059
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++)
{
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#15059: 24.3; nth with negative index values
2013-08-09 18:52 ` Glenn Morris
@ 2013-08-09 21:58 ` Stefan Monnier
2013-08-10 1:31 ` Glenn Morris
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2013-08-09 21:58 UTC (permalink / raw)
To: Glenn Morris; +Cc: Wilfred Hughes, 15059
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#15059: 24.3; nth with negative index values
2013-08-09 21:58 ` Stefan Monnier
@ 2013-08-10 1:31 ` Glenn Morris
0 siblings, 0 replies; 8+ messages in thread
From: Glenn Morris @ 2013-08-10 1:31 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Wilfred Hughes, 15059
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!
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#15059: 24.3; nth with negative index values
2013-08-09 11:55 bug#15059: 24.3; nth with negative index values Wilfred Hughes
2013-08-09 15:51 ` Andreas Schwab
2013-08-09 18:52 ` Glenn Morris
@ 2013-08-12 10:10 ` Wilfred Hughes
2013-08-12 14:09 ` Stefan Monnier
2 siblings, 1 reply; 8+ messages in thread
From: Wilfred Hughes @ 2013-08-12 10:10 UTC (permalink / raw)
To: 15059
[-- Attachment #1: Type: text/plain, Size: 160 bytes --]
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?
[-- Attachment #2: Type: text/html, Size: 164 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#15059: 24.3; nth with negative index values
2013-08-12 10:10 ` Wilfred Hughes
@ 2013-08-12 14:09 ` Stefan Monnier
2013-08-13 7:15 ` Glenn Morris
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2013-08-12 14:09 UTC (permalink / raw)
To: Wilfred Hughes; +Cc: 15059
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-08-13 7:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-09 11:55 bug#15059: 24.3; nth with negative index values Wilfred Hughes
2013-08-09 15:51 ` Andreas Schwab
2013-08-09 18:52 ` Glenn Morris
2013-08-09 21:58 ` Stefan Monnier
2013-08-10 1:31 ` Glenn Morris
2013-08-12 10:10 ` Wilfred Hughes
2013-08-12 14:09 ` Stefan Monnier
2013-08-13 7:15 ` Glenn Morris
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).