GNU bug report logs - #18253
24.4.50; doc string of `remq': correct it per the doc of `remove'

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Tue, 12 Aug 2014 15:00:02 UTC

Severity: minor

Found in version 24.4.50

Done: Christoph <cschol2112 <at> gmail.com>

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 18253 in the body.
You can then email your comments to 18253 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#18253; Package emacs. (Tue, 12 Aug 2014 15:00:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Drew Adams <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 12 Aug 2014 15:00:04 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4.50; doc string of `remq': correct it per the doc of `remove'
Date: Tue, 12 Aug 2014 07:59:01 -0700 (PDT)
Please explicitly say that `remq' returns a *copy* of LIST, just as we
do in the doc string of `remove'.  It does *not* "Return LIST with all
occurrences of ELT removed."  

The final sentence of the doc string tries to clarify things, but
combined with the first sentence the result is still confusing.



In GNU Emacs 24.4.50.1 (i686-pc-mingw32)
 of 2014-06-28 on ODIEONE
Bzr revision: 117431 rgm <at> gnu.org-20140628015517-eku6hj8mpgcvfnso
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/Devel/emacs/snapshot/trunk
 --enable-checking=yes,glyphs 'CFLAGS=-O0 -g3'
 LDFLAGS=-Lc:/Devel/emacs/lib 'CPPFLAGS=-DGC_MCHECK=1
 -Ic:/Devel/emacs/include''




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Mon, 25 Aug 2014 03:20:02 GMT) Full text and rfc822 format available.

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

From: Christoph <cschol2112 <at> gmail.com>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 18253 <at> debbugs.gnu.org, 18253-done <at> debbugs.gnu.org
Subject: Re: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Sun, 24 Aug 2014 21:19:32 -0600
[Message part 1 (text/plain, inline)]
Thanks for the report. Fixed in trunk r117732.


On Tue, Aug 12, 2014 at 8:59 AM, Drew Adams <drew.adams <at> oracle.com> wrote:

>
> Please explicitly say that `remq' returns a *copy* of LIST, just as we
> do in the doc string of `remove'.  It does *not* "Return LIST with all
> occurrences of ELT removed."
>
> The final sentence of the doc string tries to clarify things, but
> combined with the first sentence the result is still confusing.
>
>
>
> In GNU Emacs 24.4.50.1 (i686-pc-mingw32)
>  of 2014-06-28 on ODIEONE
> Bzr revision: 117431 rgm <at> gnu.org-20140628015517-eku6hj8mpgcvfnso
> Windowing system distributor `Microsoft Corp.', version 6.1.7601
> Configured using:
>  `configure --prefix=/c/Devel/emacs/snapshot/trunk
>  --enable-checking=yes,glyphs 'CFLAGS=-O0 -g3'
>  LDFLAGS=-Lc:/Devel/emacs/lib 'CPPFLAGS=-DGC_MCHECK=1
>  -Ic:/Devel/emacs/include''
>
>
>
>
[Message part 2 (text/html, inline)]

Reply sent to Christoph <cschol2112 <at> gmail.com>:
You have taken responsibility. (Mon, 25 Aug 2014 03:20:03 GMT) Full text and rfc822 format available.

Notification sent to Drew Adams <drew.adams <at> oracle.com>:
bug acknowledged by developer. (Mon, 25 Aug 2014 03:20:04 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Mon, 25 Aug 2014 22:17:01 GMT) Full text and rfc822 format available.

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

From: tsugutomo.enami <at> jp.sony.com
To: Christoph <cschol2112 <at> gmail.com>, Drew Adams <drew.adams <at> oracle.com>
Cc: 18253 <at> debbugs.gnu.org
Subject: Re: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Tue, 26 Aug 2014 07:12:58 +0900
Hi,

> Thanks for the report. Fixed in trunk r117732.
> 
> On Tue, Aug 12, 2014 at 8:59 AM, Drew Adams <drew.adams <at> oracle.com> wrote:
> 
> >
> > Please explicitly say that `remq' returns a *copy* of LIST, just as we
> > do in the doc string of `remove'.  It does *not* "Return LIST with all
> > occurrences of ELT removed."

IMHO, describing remq to return a copy of list is also confusing.  Since
it does not return a copy on some cases.

enami.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Mon, 25 Aug 2014 22:38:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: tsugutomo.enami <at> jp.sony.com, Christoph <cschol2112 <at> gmail.com>
Cc: 18253 <at> debbugs.gnu.org
Subject: RE: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Mon, 25 Aug 2014 15:37:27 -0700 (PDT)
> > > Please explicitly say that `remq' returns a *copy* of LIST, just as we
> > > do in the doc string of `remove'.  It does *not* "Return LIST with all
> > > occurrences of ELT removed."
> 
> IMHO, describing remq to return a copy of list is also confusing.  Since
> it does not return a copy on some cases.

Good point. Perhaps it should say that it returns either a copy or a
tail of the list.  It could say something like this, for example:

 If the only elements in LIST that are `eq' to ELT occur before any
 other elements then a copy is not made: the tail after the last such
 occurrence is returned.

Whatever language we choose, it should be precise wrt what the behavior
is.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Tue, 26 Aug 2014 18:35:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 18253 <at> debbugs.gnu.org, tsugutomo.enami <at> jp.sony.com,
 Christoph <cschol2112 <at> gmail.com>
Subject: Re: bug#18253: 24.4.50;
 doc string of `remq': correct it per the doc of `remove'
Date: Tue, 26 Aug 2014 14:34:00 -0400
>  If the only elements in LIST that are `eq' to ELT occur before any
>  other elements then a copy is not made: the tail after the last such
>  occurrence is returned.
> Whatever language we choose, it should be precise wrt what the behavior
> is.

I don't see a need for precision.  It should just say that the returned list
may share some elements with the original argument, but that no element
was modified by side-effect.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Tue, 26 Aug 2014 18:58:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18253 <at> debbugs.gnu.org, tsugutomo.enami <at> jp.sony.com,
 Christoph <cschol2112 <at> gmail.com>
Subject: RE: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Tue, 26 Aug 2014 11:57:12 -0700 (PDT)
> It should just say that the returned list may share some elements
> with the original argument, but that no element was modified by
> side-effect.

Why would the question of whether an *element* was modified even come
up?  That seems like a red herring, bound only to confuse people.
The question that arises for users is about sharing/modification of
the list structure, not elements.  (Yes, of course an element can
itself be a list.)

There is nothing wrong with letting users know the actual behavior.
It would be helpful to provide the kind of information that Emacs
provides (and all Lisps provide) for `member': "The value is actually
the tail of LIST whose car is ELT."

But the main point - the point of the bug report, is that it is not
correct to say, as we say now, that `remq' "Returns LIST with all
occurrences of ELT removed."  It does that only when all of the ELT
occurrences occur before any non-ELT occurrences.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Wed, 27 Aug 2014 03:19:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 18253 <at> debbugs.gnu.org, tsugutomo.enami <at> jp.sony.com,
 Christoph <cschol2112 <at> gmail.com>
Subject: Re: bug#18253: 24.4.50;
 doc string of `remq': correct it per the doc of `remove'
Date: Tue, 26 Aug 2014 23:18:02 -0400
> There is nothing wrong with letting users know the actual behavior.

Of course there is: there is another possible behavior, which would
generally be superior but which we didn't bother to implement (yet).


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Wed, 27 Aug 2014 04:56:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18253 <at> debbugs.gnu.org, tsugutomo.enami <at> jp.sony.com,
 Christoph <cschol2112 <at> gmail.com>
Subject: RE: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Tue, 26 Aug 2014 21:55:36 -0700 (PDT)
> > There is nothing wrong with letting users know the actual behavior.
> 
> Of course there is: there is another possible behavior, which would
> generally be superior but which we didn't bother to implement (yet).

That's a pretty facile "of course".  Of course you can document now
the behavior it has now, and if and when you ever change the behavior
you can update the doc accordingly.  It's not like you just invented
`remq' - it's nearly as old as Lisp (at least as old as ZetaLisp).

And most (all other?) Lisps have given it the same behavior as `remove',
the only difference being to use `eq' instead of `equal'.  IOW, they
systematically copy the sequence.  All the more reason to let users
know that Emacs Lisp is exceptional in this regard.

It is this part of the Emacs definition that differs from the usual
definition, and makes Emacs `remq' unparallel with Emacs `remove':

  (while (and (eq elt (car list)) (setq list (cdr list))))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Wed, 27 Aug 2014 05:36:02 GMT) Full text and rfc822 format available.

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

From: tsugutomo.enami <at> jp.sony.com
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 18253 <at> debbugs.gnu.org, tsugutomo.enami <at> jp.sony.com,
 Christoph <cschol2112 <at> gmail.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: RE: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Wed, 27 Aug 2014 14:31:01 +0900
Hi,

> And most (all other?) Lisps have given it the same behavior as `remove',
> the only difference being to use `eq' instead of `equal'.  IOW, they
> systematically copy the sequence.

How about to avoid the use of word `copy' to describe both `remq' and
`remove'?

The point of remq/remove is non-destructive operation.  Whether it
returns a copy or not is not important.  This matches CL's `remove'
definition.  Actually, even the current `remove' implementation does not
return a copy when SEQ is not a list and there is nothing to remove.

If document explicitly says it returns a copy, reader might think
destructive operation can be performed on the result of both functions
while expecting original sequence unmodified.

enami.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Wed, 27 Aug 2014 14:08:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: tsugutomo.enami <at> jp.sony.com
Cc: 18253 <at> debbugs.gnu.org, Christoph <cschol2112 <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: RE: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Wed, 27 Aug 2014 07:06:51 -0700 (PDT)
> > And most (all other?) Lisps have given it the same behavior as
> > `remove', the only difference being to use `eq' instead of `equal'.
> > IOW, they systematically copy the sequence.
> 
> How about to avoid the use of word `copy' to describe both `remq'
> and `remove'?

Because that is precisely what is important.  Why "avoid" what it
is most important to communicate to users?

> The point of remq/remove is non-destructive operation.  Whether it
> returns a copy or not is not important.  This matches CL's `remove'
> definition.

No, it does not.  From CLTL, section 14.3, "Modifying Sequences":

  The result is a sequence of the same kind as the argument SEQUENCE
  that has the same elements except that those in the subsequence
  delimited by :start and :end and satisfying the test (see above)
  have been removed.  This is a non-destructive operation; the result
  is a copy of the input SEQUENCE, save that some elements are not
  ^^^^^^^^^
  copied.  Elements not removed occur in the same order in the result
  ^^^^^^
  that they did in the argument.

That text was in the original edition of CTLT (1984), and it has not
changed one bit in subsequent revisions.

> Actually, even the current `remove' implementation does
> not return a copy when SEQ is not a list and there is nothing to
> remove.

I did not check the C code, but all descriptions of Elisp `delete'
for a non-list say that it *always* returns a new object.  Perhaps
all of those descriptions are incorrect (?), in which case we have
a bigger doc problem.

> If document explicitly says it returns a copy, reader might think
> destructive operation can be performed on the result of both
> functions while expecting original sequence unmodified.

Which is the case for Common Lisp.  And which should be the case
for Emacs Lisp for the cases that need to be documented as such
(i.e. as copying).






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18253; Package emacs. (Wed, 27 Aug 2014 23:54:01 GMT) Full text and rfc822 format available.

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

From: tsugutomo.enami <at> jp.sony.com
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 18253 <at> debbugs.gnu.org, Christoph <cschol2112 <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: RE: bug#18253: 24.4.50; doc string of `remq': correct it per the doc
 of `remove'
Date: Thu, 28 Aug 2014 08:49:13 +0900
Hi,

I guess the specification of Emacs's remove/remq should be clarified
first.

If current implementaion is correctly reflecting the specification, then
I hope it is documented that those function might not return a copy on
some case (in other words, document which can be read as if they always
return a copy is confusing).

If current implementaion is not correct, then they should be fixed (and
documentation is updated to reflect the specification, if necessary).

> > The point of remq/remove is non-destructive operation.  Whether it
> > returns a copy or not is not important.  This matches CL's `remove'
> > definition.
> 
> No, it does not.  From CLTL, section 14.3, "Modifying Sequences":
> 
>   The result is a sequence of the same kind as the argument SEQUENCE
>   that has the same elements except that those in the subsequence
>   delimited by :start and :end and satisfying the test (see above)
>   have been removed.  This is a non-destructive operation; the result
>   is a copy of the input SEQUENCE, save that some elements are not
>   ^^^^^^^^^
>   copied.  Elements not removed occur in the same order in the result
>   ^^^^^^
>   that they did in the argument.
> 
> That text was in the original edition of CTLT (1984), and it has not
> changed one bit in subsequent revisions.

Probably, I failed to pick up my word.  What I meant was that those
function might not return a copy and they doesn't modify its argument is
more important aspect.  Of course it is importatnt to copy cells when
necessary.

The `remove' might not return a copy is described in the last sentense
of the section (quoted from
https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node144.html):

  The result of remove may share with the argument sequence; a list
  result may share a tail with an input list, and the result may be eq
  to the input sequence if no elements need to be removed.

enami.




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

This bug report was last modified 9 years and 220 days ago.

Previous Next


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