all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: emacs-devel@gnu.org, d.love@dl.ac.uk, monnier@iro.umontreal.ca,
	miles@gnu.org
Subject: Re: space leak from `values'
Date: 20 Aug 2004 14:51:32 +0200	[thread overview]
Message-ID: <m3isbeas6j.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <E1Bqa3P-00081l-6z@fencepost.gnu.org>


Referring to my proposal for adding setnthcdr, and the number of
places where a list is currently truncated in the lisp files,

Richard Stallman <rms@gnu.org> writes:

> I did not realize there were so many places where this was done.
> However, (setcdr (or (nthcdr N LIST) (list nil)) nil) is pretty
> simple.  I am not sure we need a new function to replace that
> even if that is done 20 times in Emacs.

Since the only practical use of the "setnthcdr" function is to simply
truncate a list to a specific length, I suggest a new function
truncate-list (to be defined in subr.el):

(defun truncate-list (list n)
  "Truncate list LIST to have a maximum of N elements.
If LIST has less than N element, do nothing."
   (if (setq list (nthcdr (1- n) list))
       (setcdr list nil)))

Using that function is both clearer and more efficient than
how it's done currently.

e.g. instead of

    (setq kill-ring (cons string kill-ring))
    (if (> (length kill-ring) kill-ring-max)
	(setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))

just write

    (truncate-list (setq kill-ring (cons string kill-ring))
                   kill-ring-max)


Also, it is much simpler to document truncate-list than the more
generic setnthcdr.

--
Kim F. Storm <storm@cua.dk> http://www.cua.dk

  reply	other threads:[~2004-08-20 12:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <rzqzn5qehby.fsf@albion.dl.ac.uk>
     [not found] ` <E1BoSQg-0001Br-II@fencepost.gnu.org>
     [not found]   ` <rzq3c3eex5r.fsf@albion.dl.ac.uk>
     [not found]     ` <E1Bp9wv-0004v0-Ts@fencepost.gnu.org>
     [not found]       ` <rzqllh4m4yi.fsf@albion.dl.ac.uk>
     [not found]         ` <jwvu0vs9gjz.fsf-monnier+emacs@gnu.org>
2004-07-28 23:13           ` space leak from `values' Kim F. Storm
2004-07-29  7:50             ` Miles Bader
2004-07-29  8:41               ` Kim F. Storm
2004-07-29  8:50                 ` David Kastrup
2004-07-29  9:06                 ` Miles Bader
2004-07-29 12:00                   ` Kim F. Storm
2004-07-30 16:16                     ` Richard Stallman
2004-08-20 12:51                       ` Kim F. Storm [this message]
2004-08-21 16:49                         ` Richard Stallman
2004-07-30  4:54                 ` Richard Stallman

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=m3isbeas6j.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=d.love@dl.ac.uk \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.