From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: space leak from `values' Date: 29 Jul 2004 10:41:42 +0200 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1091090504 15483 80.91.224.253 (29 Jul 2004 08:41:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 29 Jul 2004 08:41:44 +0000 (UTC) Cc: emacs-devel@gnu.org, Stefan Monnier , Dave Love Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 29 10:41:33 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Bq6Tk-0000yW-00 for ; Thu, 29 Jul 2004 10:41:33 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bq6Ww-0000TD-1Q for ged-emacs-devel@m.gmane.org; Thu, 29 Jul 2004 04:44:50 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Bq6Wn-0000Sx-RW for emacs-devel@gnu.org; Thu, 29 Jul 2004 04:44:41 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Bq6Wk-0000Sj-K2 for emacs-devel@gnu.org; Thu, 29 Jul 2004 04:44:41 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bq6Wk-0000Sg-5l for emacs-devel@gnu.org; Thu, 29 Jul 2004 04:44:38 -0400 Original-Received: from [212.88.64.25] (helo=mail-relay.sonofon.dk) by monty-python.gnu.org with smtp (Exim 4.34) id 1Bq6TF-0000tE-CD for emacs-devel@gnu.org; Thu, 29 Jul 2004 04:41:01 -0400 Original-Received: (qmail 95273 invoked from network); 29 Jul 2004 08:41:00 -0000 Original-Received: from unknown (HELO kfs-l.imdomain.dk.cua.dk) (213.83.150.2) by 0 with SMTP; 29 Jul 2004 08:41:00 -0000 Original-To: Miles Bader In-Reply-To: Original-Lines: 36 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:26083 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:26083 Miles Bader 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 http://www.cua.dk