[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: space leak from `values'
From: |
Kim F. Storm |
Subject: |
Re: space leak from `values' |
Date: |
29 Jul 2004 10:41:42 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
Miles Bader <address@hidden> writes:
> address@hidden (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 <address@hidden> http://www.cua.dk