all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Drew Adams <drew.adams@oracle.com>
Cc: 12314@debbugs.gnu.org, cyd@gnu.org
Subject: bug#12314: 24.2.50; `add-to-history': use `setq' with `delete'
Date: Sun, 09 Sep 2012 06:00:11 +0300	[thread overview]
Message-ID: <834nn7nbno.fsf@gnu.org> (raw)
In-Reply-To: <852E534DA6A342708069D17B8C3C3DFF@us.oracle.com>

> From: "Drew Adams" <drew.adams@oracle.com>
> Cc: <cyd@gnu.org>, <12314@debbugs.gnu.org>
> Date: Sat, 8 Sep 2012 15:26:04 -0700
> 
> > > > Why is it even necessary to talk about destructive 
> > > > modifications, if we are to advise to assign the result anyway?
> > > 
> > > Not sure I understand the question.  It is because these 
> > > operations can be destructive of list structure that we advise that.
> > 
> > If you need to forget about the old value and assign the new one
> > returned by 'delete', why does it matter that the modification was
> > destructive?  That pertains to the old value that you need to toss
> > anyway.
> 
> Perhaps we are miscommunicating.
> 
> That general advice about assigning the variable is only a general guideline; it
> is not absolute.  You will NOT always want to assign the variable to the return
> value.  It all depends on what you want/need.

Please describe the situations with using 'delete' when the old value
will be wanted.  (Please try to do that succinctly, because I get lost
in your longish deliberations.)

> The doc about these operations needs to describe what they do, and what they do
> is typically destructive; that is, they typically modify list structure.
> 
> The bit about variables here is only a heads-up about a classic gotcha, nothing
> more.  It is because we often have variables that are assigned/bound to the list
> structure that we might be modifying that we should BE AWARE that these
> operations do NOT do ANYTHING wrt variables.  

Being aware doesn't solve problems.  To write reliable code, one needs
to always do certain things.  My understanding is that one must always
assign the new value, because the old one is unpredictable in general.

> > > If you have variables that point to some list structure 
> > > that you modify somehow, then it is up to you to ensure that
> > > the variables point to what you want them to point to after
> > > such modification.
> > 
> > Variables that point to that list structure will point to something
> > whose value is unpredictable, a.k.a. "garbage".  It is enough to say
> > that the old value is garbage and shouldn't be used, IMO.
> 
> No.  It all depends.  Lisp programs that use list modification do so sometimes
> for performance in calculating the new list, but more often they do so in order
> to take advantage of SHARING list structure.
> 
> (This too is something not so obvious to newbies - they can get the impression
> that these operations are mainly about saving cycles in calculating the return
> value.)

But the manual should cater first and foremost to newbies.  The rest
will get the point when they read the detailed description of how the
list is modified.

> (setq a  '(1 2 3 4))
> (setq b  (cddr a))
> 
> a => (1 2 3 4)
> b => (3 4)
> 
> (delq 4 b)
> 
> a => (1 2 3)
> b => (3)
> 
> The fact that modifying the list pointed to by `b' also modifies the list
> pointed to by `a' is an advantage for certain kinds of programs.  Without a
> separate `setq' operation, the variables point to the same cons cells they
> pointed to at the outset.  And in some cases that is exactly what you want: you
> want to remove the last link in the list that is shared by `a' and `b'.

I fail to see the utility of this.  Building code that relies on
internal implementation details is never a good idea.  But that's me;
please don't bother to argue.





  reply	other threads:[~2012-09-09  3:00 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-30 23:08 bug#12314: 24.2.50; `add-to-history': use `setq' with `delete' Drew Adams
2012-09-08 14:32 ` Chong Yidong
2012-09-08 14:43   ` Eli Zaretskii
2012-09-08 14:57     ` Drew Adams
2012-09-08 15:20       ` Eli Zaretskii
2012-09-08 15:48         ` Drew Adams
2012-09-08 16:05           ` Eli Zaretskii
2012-09-08 16:19             ` Andreas Schwab
2012-09-08 16:33               ` Eli Zaretskii
2012-09-08 16:50                 ` Lars Ingebrigtsen
2012-09-08 16:54                 ` Drew Adams
2012-09-08 17:06                 ` Andreas Schwab
2012-09-08 16:35               ` Drew Adams
2012-09-08 16:25             ` Drew Adams
2012-09-08 16:32               ` Eli Zaretskii
2012-09-08 16:42                 ` Drew Adams
2012-09-08 21:21                   ` Eli Zaretskii
2012-09-08 22:26                     ` Drew Adams
2012-09-09  3:00                       ` Eli Zaretskii [this message]
2012-09-09  6:29                         ` Drew Adams
2012-09-09  7:53                         ` Chong Yidong
2012-09-09 17:25                           ` Eli Zaretskii
2012-09-10 11:54                       ` Wolfgang Jenkner
2012-09-08 23:11                     ` Stefan Monnier
2012-09-09  2:51                       ` Eli Zaretskii
2012-09-09 14:44                         ` Stefan Monnier
2012-09-09 17:14                           ` Eli Zaretskii
2012-09-09 17:35                             ` Drew Adams
2012-09-09 18:20                               ` Eli Zaretskii
2012-09-09 19:46                                 ` Drew Adams
2012-09-09 21:37                             ` Stefan Monnier
2012-09-10  4:37                               ` Eli Zaretskii
2012-09-10 12:59                                 ` Stefan Monnier
2012-09-10 15:01                                   ` Stefan Monnier
2012-09-10 15:21                                   ` Drew Adams
2012-09-10 16:24                                   ` Eli Zaretskii
2012-09-09  8:25 ` Dmitry Gutov

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=834nn7nbno.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=12314@debbugs.gnu.org \
    --cc=cyd@gnu.org \
    --cc=drew.adams@oracle.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.