GNU bug report logs - #12314
24.2.50; `add-to-history': use `setq' with `delete'

Previous Next

Package: emacs;

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

Date: Thu, 30 Aug 2012 23:10:01 UTC

Severity: normal

Found in version 24.2.50

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Wolfgang Jenkner <wjenkner <at> inode.at>
To: "Drew Adams" <drew.adams <at> oracle.com>
Cc: 12314 <at> debbugs.gnu.org, 'Eli Zaretskii' <eliz <at> gnu.org>, cyd <at> gnu.org
Subject: bug#12314: 24.2.50; `add-to-history': use `setq' with `delete'
Date: Mon, 10 Sep 2012 13:54:40 +0200
On Sun, Sep 09 2012, Drew Adams wrote:

>> 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.
>
> Consider the example I gave before:
>
> (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)

Though using `delete' and friends this way would have unpredictable
results in ANSI Common Lisp[1] or Scheme (delete! in srfi1[2]), hence
may be regarded as questionable programming style in Emacs Lisp as well,
which I understand is Eli's point.

The following should work in both CL (except for the missing DEFVARs)
and Emacs Lisp, but sort of defeats the point about easy sharing ;-)

(setq a (list 1 2 3 4))
(setq b (cddr a))
(setf (cddr a) (setq b (delete 4 b)))

[1] http://www.lispworks.com/documentation/HyperSpec/Body/f_rm_rm.htm#delete
    http://www.lispworks.com/documentation/HyperSpec/Issues/iss293_w.htm

[2] http://srfi.schemers.org/srfi-1/srfi-1.html#LinearUpdateProcedures

Wolfgang




This bug report was last modified 12 years and 251 days ago.

Previous Next


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