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, Stefan Monnier <monnier@iro.umontreal.ca>,
	Dave Love <d.love@dl.ac.uk>
Subject: Re: space leak from `values'
Date: 29 Jul 2004 10:41:42 +0200	[thread overview]
Message-ID: <m33c3bdx2x.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <buoekmvgskt.fsf@mctpc71.ucom.lsi.nec.co.jp>

Miles Bader <miles@lsi.nec.co.jp> writes:

> storm@cua.dk (Kim F. Storm) writes:
> > + DEFUN ("setnthcdr", Fsetnthcdr, Ssetnthcdr, 2, 3, 0,
> > +        doc: /* Set cdr of Nth element of LIST to VALUE (nil if omitted), returns the result.
> 
> What's wrong with (setcdr (nthcdr (1- N) LIST) VALUE) ?

Read the third line of the doc string:

> If list has less than N elements, do not modify list.

Your suggestion fails if N is less than the length of the list:

(let ((list '(1 2 3 4))
      (n 10)     
      (value nil))
  (setcdr (nthcdr (1- n) list) value))

With (my version of) setnthcdr you replace
    (if (> (length kill-ring) kill-ring-max)
	(setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
by
    (setnthcdr kill-ring-max kill-ring)

And besides, I need this at the C level (but I can of course
write the necessary code in-line).


BTW, my first idea was to call this function `chop' so that (chop N
LIST) would simply truncate LIST to a maximum of N elements -- but
then I realized that setnthcdr with the optional VALUE arg would be
more generic (and potentially more useful).

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

  reply	other threads:[~2004-07-29  8:41 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 [this message]
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
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=m33c3bdx2x.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=d.love@dl.ac.uk \
    --cc=emacs-devel@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.